1 package org.cacert.gigi.pages.wot;
3 import java.io.PrintWriter;
4 import java.text.SimpleDateFormat;
6 import java.util.HashMap;
9 import javax.servlet.http.HttpServletRequest;
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.Name;
13 import org.cacert.gigi.dbObjects.User;
14 import org.cacert.gigi.localisation.Language;
15 import org.cacert.gigi.output.template.Form;
16 import org.cacert.gigi.output.template.Template;
17 import org.cacert.gigi.pages.Page;
18 import org.cacert.gigi.util.Notary;
20 public class AssuranceForm extends Form {
24 private Name assureeName;
28 private static final Template templ;
30 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
33 public AssuranceForm(HttpServletRequest hsr, User assuree) {
35 this.assuree = assuree;
36 assureeName = this.assuree.getName();
37 dob = this.assuree.getDoB();
40 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
42 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
45 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
46 HashMap<String, Object> res = new HashMap<String, Object>();
48 res.put("nameExplicit", assuree.getName());
49 res.put("name", assuree.getName().toString());
50 res.put("maxpoints", assuree.getMaxAssurePoints());
51 res.put("dob", sdf.format(assuree.getDoB()));
52 res.put("dobFmt2", sdf2.format(assuree.getDoB()));
53 templ.output(out, l, res);
57 public boolean submit(PrintWriter out, HttpServletRequest req) {
58 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
59 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
63 String points = req.getParameter("points");
64 if (points == null || "".equals(points)) {
65 outputError(out, req, "For an assurance, you need to enter points.");
68 pointsI = Integer.parseInt(points);
69 } catch (NumberFormatException e) {
70 outputError(out, req, "The points entered were not a number.");
78 Notary.assure(Page.getUser(req), assuree, assureeName, dob, pointsI, req.getParameter("location"), req.getParameter("date"));
80 } catch (GigiApiException e) {
81 e.format(out, Page.getLanguage(req));
87 public User getAssuree() {