1 package org.cacert.gigi.pages.wot;
3 import java.io.PrintWriter;
4 import java.text.SimpleDateFormat;
5 import java.util.HashMap;
6 import java.util.Iterator;
7 import java.util.LinkedList;
10 import javax.servlet.http.HttpServletRequest;
12 import org.cacert.gigi.GigiApiException;
13 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
14 import org.cacert.gigi.dbObjects.Name;
15 import org.cacert.gigi.dbObjects.User;
16 import org.cacert.gigi.localisation.Language;
17 import org.cacert.gigi.output.template.Form;
18 import org.cacert.gigi.output.template.IterableDataset;
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.DayDate;
23 import org.cacert.gigi.util.Notary;
25 public class AssuranceForm extends Form {
29 private Name assureeName;
33 private String location = "";
35 private String date = "";
41 private AssuranceType type = AssuranceType.FACE_TO_FACE;
43 private static final Template templ;
45 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
48 public AssuranceForm(HttpServletRequest hsr, User assuree) {
50 assurer = Page.getUser(hsr);
51 this.assuree = assuree;
52 assureeName = this.assuree.getName();
53 dob = this.assuree.getDoB();
56 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
58 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
61 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
62 HashMap<String, Object> res = new HashMap<String, Object>();
64 res.put("nameExplicit", assuree.getName());
65 res.put("name", assuree.getName().toString());
66 res.put("maxpoints", assurer.getMaxAssurePoints());
67 res.put("dob", sdf.format(assuree.getDoB().toDate()));
68 res.put("dobFmt2", sdf2.format(assuree.getDoB().toDate()));
69 res.put("location", location);
70 res.put("date", date);
71 res.put("aword", aword);
72 final LinkedList<AssuranceType> ats = new LinkedList<>();
73 for (AssuranceType at : AssuranceType.values()) {
75 Notary.may(assurer, assuree, at);
77 } catch (GigiApiException e) {
80 res.put("ats", new IterableDataset() {
82 Iterator<AssuranceType> t = ats.iterator();
85 public boolean next(Language l, Map<String, Object> vars) {
89 AssuranceType t1 = t.next();
90 vars.put("type", t1.getDescription());
91 vars.put("id", t1.toString());
92 vars.put("sel", t1 == type ? " selected" : "");
96 templ.output(out, l, res);
100 public boolean submit(PrintWriter out, HttpServletRequest req) {
101 location = req.getParameter("location");
102 date = req.getParameter("date");
103 if (date == null || location == null) {
104 outputError(out, req, "You need to enter location and date!");
107 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("tos_agree")) || !"1".equals(req.getParameter("assertion"))) {
108 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of SomeCA");
110 if ("1".equals(req.getParameter("passwordReset"))) {
111 aword = req.getParameter("passwordResetValue");
112 if ("".equals(aword)) {
118 String val = req.getParameter("assuranceType");
121 type = AssuranceType.valueOf(val);
122 } catch (IllegalArgumentException e) {
123 outputError(out, req, "Assurance Type wrong.");
128 String points = req.getParameter("points");
129 if (points == null || "".equals(points)) {
130 outputError(out, req, "For an assurance, you need to enter points.");
133 pointsI = Integer.parseInt(points);
134 } catch (NumberFormatException e) {
135 outputError(out, req, "The points entered were not a number.");
143 Notary.assure(assurer, assuree, assureeName, dob, pointsI, location, req.getParameter("date"), type);
144 if (aword != null && !aword.equals("")) {
145 Language l = Language.getInstance(assuree.getPreferredLocale());
146 String method = l.getTranslation("A password reset was triggered. If you did a password reset by assurance, please enter your secret password using this form:");
147 String subject = l.getTranslation("Password reset by assurance");
148 PasswordResetPage.initPasswordResetProcess(out, assuree, req, aword, l, method, subject);
151 } catch (GigiApiException e) {
152 e.format(out, Page.getLanguage(req));
158 public User getAssuree() {