1 package org.cacert.gigi.pages.wot;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.net.URLEncoder;
6 import java.text.SimpleDateFormat;
8 import java.util.HashMap;
11 import javax.servlet.http.HttpServletRequest;
13 import org.cacert.gigi.GigiApiException;
14 import org.cacert.gigi.dbObjects.Name;
15 import org.cacert.gigi.dbObjects.User;
16 import org.cacert.gigi.email.Sendmail;
17 import org.cacert.gigi.localisation.Language;
18 import org.cacert.gigi.output.template.Form;
19 import org.cacert.gigi.output.template.Template;
20 import org.cacert.gigi.pages.Page;
21 import org.cacert.gigi.pages.PasswordResetPage;
22 import org.cacert.gigi.util.Notary;
23 import org.cacert.gigi.util.RandomToken;
24 import org.cacert.gigi.util.ServerConstants;
26 public class AssuranceForm extends Form {
30 private Name assureeName;
34 private String location = "";
36 private String date = "";
40 private static final Template templ;
42 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
45 public AssuranceForm(HttpServletRequest hsr, User assuree) {
47 this.assuree = assuree;
48 assureeName = this.assuree.getName();
49 dob = this.assuree.getDoB();
52 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
54 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
57 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
58 HashMap<String, Object> res = new HashMap<String, Object>();
60 res.put("nameExplicit", assuree.getName());
61 res.put("name", assuree.getName().toString());
62 res.put("maxpoints", assuree.getMaxAssurePoints());
63 res.put("dob", sdf.format(assuree.getDoB()));
64 res.put("dobFmt2", sdf2.format(assuree.getDoB()));
65 res.put("location", location);
66 res.put("date", date);
67 res.put("aword", aword);
68 templ.output(out, l, res);
72 public boolean submit(PrintWriter out, HttpServletRequest req) {
73 location = req.getParameter("location");
74 date = req.getParameter("date");
75 if (date == null || location == null) {
76 outputError(out, req, "You need to enter location and date!");
79 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
80 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
83 if ("1".equals(req.getParameter("passwordReset"))) {
84 aword = req.getParameter("passwordResetValue");
85 if ("".equals(aword)) {
93 String points = req.getParameter("points");
94 if (points == null || "".equals(points)) {
95 outputError(out, req, "For an assurance, you need to enter points.");
98 pointsI = Integer.parseInt(points);
99 } catch (NumberFormatException e) {
100 outputError(out, req, "The points entered were not a number.");
108 Notary.assure(Page.getUser(req), assuree, assureeName, dob, pointsI, location, req.getParameter("date"));
109 if (aword != null && !aword.equals("")) {
110 String systemToken = RandomToken.generateToken(32);
111 int id = assuree.generatePasswordResetTicket(Page.getUser(req), systemToken, aword);
113 Language l = Language.getInstance(assuree.getPreferredLocale());
114 StringBuffer body = new StringBuffer();
115 body.append(l.getTranslation("Hi,") + "\n\n");
116 body.append(l.getTranslation("A password reset was triggered. If you did a password reset by assurance, please enter your secret password using this form: \n"));
117 body.append(ServerConstants.getWwwHostNamePortSecure() + PasswordResetPage.PATH);
120 body.append("&token=");
121 body.append(URLEncoder.encode(systemToken, "UTF-8"));
124 body.append(l.getTranslation("Best regards"));
126 body.append(l.getTranslation("CAcert.org Support!"));
127 Sendmail.getInstance().sendmail(assuree.getEmail(), "[CAcert.org] " + l.getTranslation("Password reset by assurance"), body.toString(), "support@cacert.org", null, null, null, null, false);
128 } catch (IOException e) {
133 } catch (GigiApiException e) {
134 e.format(out, Page.getLanguage(req));
140 public User getAssuree() {