1 package org.cacert.gigi.pages.wot;
3 import java.io.InputStreamReader;
4 import java.io.PrintWriter;
5 import java.text.ParseException;
6 import java.text.SimpleDateFormat;
8 import java.util.HashMap;
11 import javax.servlet.http.HttpServletRequest;
13 import org.cacert.gigi.Language;
14 import org.cacert.gigi.User;
15 import org.cacert.gigi.output.Form;
16 import org.cacert.gigi.output.Template;
18 public class AssuranceForm extends Form {
20 static final Template templ;
22 templ = new Template(new InputStreamReader(
23 AssuranceForm.class.getResourceAsStream("AssuranceForm.templ")));
26 public AssuranceForm(int assuree) {
27 this.assuree = new User(assuree);
29 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
32 public void output(PrintWriter out, Language l, Map<String, Object> vars) {
33 HashMap<String, Object> res = new HashMap<String, Object>();
35 res.put("name", assuree.getName());
36 res.put("dob", sdf.format(assuree.getDob()));
37 templ.output(out, l, res);
41 public boolean submit(PrintWriter out, HttpServletRequest req) {
42 out.println("<div class='formError'>");
43 boolean failed = false;
45 if (!"1".equals(req.getParameter("certify"))
46 || !"1".equals(req.getParameter("rules"))
47 || !"1".equals(req.getParameter("CCAAgreed"))
48 || !"1".equals(req.getParameter("assertion"))) {
49 outputError(out, req, "You failed to check all boxes to validate"
50 + " your adherence to the rules and policies of CAcert");
54 if (req.getParameter("date") == null
55 || req.getParameter("date").equals("")) {
57 "You must enter the date when you met the assuree.");
61 Date d = sdf.parse(req.getParameter("date"));
62 if (d.getTime() > System.currentTimeMillis()) {
64 "You must not enter a date in the future.");
67 } catch (ParseException e) {
69 "You must enter the date in this format: YYYY-MM-DD.");
73 // check location, min 3 characters
74 if (req.getParameter("location") == null
75 || req.getParameter("location").equals("")) {
77 "You failed to enter a location of your meeting.");
79 } else if (req.getParameter("location").length() <= 2) {
81 "You must enter a location with at least 3 characters eg town and country.");
85 out.println("</div>");