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 String location = "";
30 private String date = "";
32 private static final Template templ;
34 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
37 public AssuranceForm(HttpServletRequest hsr, User assuree) {
39 this.assuree = assuree;
40 assureeName = this.assuree.getName();
41 dob = this.assuree.getDoB();
44 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
46 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
49 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
50 HashMap<String, Object> res = new HashMap<String, Object>();
52 res.put("nameExplicit", assuree.getName());
53 res.put("name", assuree.getName().toString());
54 res.put("maxpoints", assuree.getMaxAssurePoints());
55 res.put("dob", sdf.format(assuree.getDoB()));
56 res.put("dobFmt2", sdf2.format(assuree.getDoB()));
57 res.put("location", location);
58 res.put("date", date);
59 templ.output(out, l, res);
63 public boolean submit(PrintWriter out, HttpServletRequest req) {
64 location = req.getParameter("location");
65 date = req.getParameter("date");
66 if (date == null || location == null) {
67 outputError(out, req, "You need to enter location and date!");
70 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
71 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
75 String points = req.getParameter("points");
76 if (points == null || "".equals(points)) {
77 outputError(out, req, "For an assurance, you need to enter points.");
80 pointsI = Integer.parseInt(points);
81 } catch (NumberFormatException e) {
82 outputError(out, req, "The points entered were not a number.");
90 Notary.assure(Page.getUser(req), assuree, assureeName, dob, pointsI, location, req.getParameter("date"));
92 } catch (GigiApiException e) {
93 e.format(out, Page.getLanguage(req));
99 public User getAssuree() {