1 package org.cacert.gigi.pages.wot;
3 import java.io.InputStreamReader;
4 import java.io.PrintWriter;
5 import java.sql.SQLException;
6 import java.text.ParseException;
7 import java.text.SimpleDateFormat;
9 import java.util.HashMap;
12 import javax.servlet.http.HttpServletRequest;
14 import org.cacert.gigi.Language;
15 import org.cacert.gigi.User;
16 import org.cacert.gigi.output.Form;
17 import org.cacert.gigi.output.Template;
18 import org.cacert.gigi.pages.LoginPage;
19 import org.cacert.gigi.util.Notary;
20 import org.cacert.gigi.util.Notary.AssuranceResult;
22 public class AssuranceForm extends Form {
24 static final Template templ;
26 templ = new Template(new InputStreamReader(
27 AssuranceForm.class.getResourceAsStream("AssuranceForm.templ")));
30 public AssuranceForm(int assuree) {
31 this.assuree = new User(assuree);
33 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
36 public void outputContent(PrintWriter out, Language l,
37 Map<String, Object> vars) {
38 HashMap<String, Object> res = new HashMap<String, Object>();
40 res.put("name", assuree.getName());
42 res.put("maxpoints", assuree.getMaxAssurePoints());
43 } catch (SQLException e) {
46 res.put("dob", sdf.format(assuree.getDob()));
47 templ.output(out, l, res);
51 public boolean submit(PrintWriter out, HttpServletRequest req) {
54 out.println("<div class='formError'>");
55 boolean failed = false;
57 if (!"1".equals(req.getParameter("certify"))
58 || !"1".equals(req.getParameter("rules"))
59 || !"1".equals(req.getParameter("CCAAgreed"))
60 || !"1".equals(req.getParameter("assertion"))) {
61 outputError(out, req, "You failed to check all boxes to validate"
62 + " your adherence to the rules and policies of CAcert");
66 if (req.getParameter("date") == null
67 || req.getParameter("date").equals("")) {
69 "You must enter the date when you met the assuree.");
73 Date d = sdf.parse(req.getParameter("date"));
74 if (d.getTime() > System.currentTimeMillis()) {
76 "You must not enter a date in the future.");
79 } catch (ParseException e) {
81 "You must enter the date in this format: YYYY-MM-DD.");
85 // check location, min 3 characters
86 if (req.getParameter("location") == null
87 || req.getParameter("location").equals("")) {
89 "You failed to enter a location of your meeting.");
91 } else if (req.getParameter("location").length() <= 2) {
93 "You must enter a location with at least 3 characters eg town and country.");
97 String points = req.getParameter("points");
98 if (points == null || "".equals(points)) {
103 out.println("</div>");
107 AssuranceResult success = Notary.assure(LoginPage.getUser(req),
108 assuree, Integer.parseInt(req.getParameter("points")),
109 req.getParameter("location"), req.getParameter("date"));
110 if (success != AssuranceResult.ASSURANCE_SUCCEDED) {
111 outputError(out, req, success.getMessage());
113 out.println("</div>");
114 return success == AssuranceResult.ASSURANCE_SUCCEDED;
115 } catch (SQLException e) {
119 out.println("</div>");