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 = "";
42 private static final Template templ;
44 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
47 public AssuranceForm(HttpServletRequest hsr, User assuree) {
49 assurer = Page.getUser(hsr);
50 this.assuree = assuree;
51 assureeName = this.assuree.getName();
52 dob = this.assuree.getDoB();
55 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
57 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
60 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
61 HashMap<String, Object> res = new HashMap<String, Object>();
63 res.put("nameExplicit", assuree.getName());
64 res.put("name", assuree.getName().toString());
65 res.put("maxpoints", assurer.getMaxAssurePoints());
66 res.put("dob", sdf.format(assuree.getDoB()));
67 res.put("dobFmt2", sdf2.format(assuree.getDoB()));
68 res.put("location", location);
69 res.put("date", date);
70 res.put("aword", aword);
71 templ.output(out, l, res);
75 public boolean submit(PrintWriter out, HttpServletRequest req) {
76 location = req.getParameter("location");
77 date = req.getParameter("date");
78 if (date == null || location == null) {
79 outputError(out, req, "You need to enter location and date!");
82 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
83 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
86 if ("1".equals(req.getParameter("passwordReset"))) {
87 aword = req.getParameter("passwordResetValue");
88 if ("".equals(aword)) {
96 String points = req.getParameter("points");
97 if (points == null || "".equals(points)) {
98 outputError(out, req, "For an assurance, you need to enter points.");
101 pointsI = Integer.parseInt(points);
102 } catch (NumberFormatException e) {
103 outputError(out, req, "The points entered were not a number.");
111 Notary.assure(assurer, assuree, assureeName, dob, pointsI, location, req.getParameter("date"));
112 if (aword != null && !aword.equals("")) {
113 String systemToken = RandomToken.generateToken(32);
114 int id = assuree.generatePasswordResetTicket(Page.getUser(req), systemToken, aword);
116 Language l = Language.getInstance(assuree.getPreferredLocale());
117 StringBuffer body = new StringBuffer();
118 body.append(l.getTranslation("Hi,") + "\n\n");
119 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: \nhttps://"));
120 body.append(ServerConstants.getWwwHostNamePortSecure() + PasswordResetPage.PATH);
123 body.append("&token=");
124 body.append(URLEncoder.encode(systemToken, "UTF-8"));
127 body.append(l.getTranslation("Best regards"));
129 body.append(l.getTranslation("CAcert.org Support!"));
130 Sendmail.getInstance().sendmail(assuree.getEmail(), "[CAcert.org] " + l.getTranslation("Password reset by assurance"), body.toString(), "support@cacert.org", null, null, null, null, false);
131 } catch (IOException e) {
136 } catch (GigiApiException e) {
137 e.format(out, Page.getLanguage(req));
143 public User getAssuree() {