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;
21 public class AssuranceForm extends Form {
23 static final Template templ;
25 templ = new Template(new InputStreamReader(
26 AssuranceForm.class.getResourceAsStream("AssuranceForm.templ")));
29 public AssuranceForm(int assuree) {
30 this.assuree = new User(assuree);
32 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
35 public void output(PrintWriter out, Language l, Map<String, Object> vars) {
36 HashMap<String, Object> res = new HashMap<String, Object>();
38 res.put("name", assuree.getName());
40 res.put("maxpoints", assuree.getMaxAssurePoints());
41 } catch (SQLException e) {
44 res.put("dob", sdf.format(assuree.getDob()));
45 templ.output(out, l, res);
49 public boolean submit(PrintWriter out, HttpServletRequest req) {
50 out.println("<div class='formError'>");
51 boolean failed = false;
53 if (!"1".equals(req.getParameter("certify"))
54 || !"1".equals(req.getParameter("rules"))
55 || !"1".equals(req.getParameter("CCAAgreed"))
56 || !"1".equals(req.getParameter("assertion"))) {
57 outputError(out, req, "You failed to check all boxes to validate"
58 + " your adherence to the rules and policies of CAcert");
62 if (req.getParameter("date") == null
63 || req.getParameter("date").equals("")) {
65 "You must enter the date when you met the assuree.");
69 Date d = sdf.parse(req.getParameter("date"));
70 if (d.getTime() > System.currentTimeMillis()) {
72 "You must not enter a date in the future.");
75 } catch (ParseException e) {
77 "You must enter the date in this format: YYYY-MM-DD.");
81 // check location, min 3 characters
82 if (req.getParameter("location") == null
83 || req.getParameter("location").equals("")) {
85 "You failed to enter a location of your meeting.");
87 } else if (req.getParameter("location").length() <= 2) {
89 "You must enter a location with at least 3 characters eg town and country.");
93 String points = req.getParameter("points");
94 if (points == null || "".equals(points)) {
99 out.println("</div>");
103 boolean success = Notary.assure(LoginPage.getUser(req), assuree,
104 Integer.parseInt(req.getParameter("points")),
105 req.getParameter("location"), req.getParameter("date"));
107 outputError(out, req,
108 "Assurance failed. Maybe user data changed.");
110 out.println("</div>");
112 } catch (SQLException e) {
116 out.println("</div>");