]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/wot/AssuranceForm.java
Assurance form: display DoB
[gigi.git] / src / org / cacert / gigi / pages / wot / AssuranceForm.java
1 package org.cacert.gigi.pages.wot;
2
3 import java.io.InputStreamReader;
4 import java.io.PrintWriter;
5 import java.text.ParseException;
6 import java.text.SimpleDateFormat;
7 import java.util.Date;
8 import java.util.HashMap;
9 import java.util.Map;
10
11 import javax.servlet.http.HttpServletRequest;
12
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;
17
18 public class AssuranceForm extends Form {
19         User assuree;
20         static final Template templ;
21         static {
22                 templ = new Template(new InputStreamReader(
23                                 AssuranceForm.class.getResourceAsStream("AssuranceForm.templ")));
24         }
25
26         public AssuranceForm(int assuree) {
27                 this.assuree = new User(assuree);
28         }
29         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
30
31         @Override
32         public void output(PrintWriter out, Language l, Map<String, Object> vars) {
33                 HashMap<String, Object> res = new HashMap<String, Object>();
34                 res.putAll(vars);
35                 res.put("name", assuree.getName());
36                 res.put("dob", sdf.format(assuree.getDob()));
37                 templ.output(out, l, res);
38         }
39
40         @Override
41         public boolean submit(PrintWriter out, HttpServletRequest req) {
42                 out.println("<div class='formError'>");
43                 boolean failed = false;
44
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");
51                         failed = true;
52
53                 }
54                 if (req.getParameter("date") == null
55                                 || req.getParameter("date").equals("")) {
56                         outputError(out, req,
57                                         "You must enter the date when you met the assuree.");
58                         failed = true;
59                 } else {
60                         try {
61                                 Date d = sdf.parse(req.getParameter("date"));
62                                 if (d.getTime() > System.currentTimeMillis()) {
63                                         outputError(out, req,
64                                                         "You must not enter a date in the future.");
65                                         failed = true;
66                                 }
67                         } catch (ParseException e) {
68                                 outputError(out, req,
69                                                 "You must enter the date in this format: YYYY-MM-DD.");
70                                 failed = true;
71                         }
72                 }
73                 // check location, min 3 characters
74                 if (req.getParameter("location") == null
75                                 || req.getParameter("location").equals("")) {
76                         outputError(out, req,
77                                         "You failed to enter a location of your meeting.");
78                         failed = true;
79                 } else if (req.getParameter("location").length() <= 2) {
80                         outputError(out, req,
81                                         "You must enter a location with at least 3 characters eg town and country.");
82                         failed = true;
83                 }
84                 // TODO checkPoints
85                 out.println("</div>");
86                 if (failed) {
87                         return false;
88                 }
89
90                 return false;
91         }
92 }