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 outputContent(PrintWriter out, Language l,
36 Map<String, Object> vars) {
37 HashMap<String, Object> res = new HashMap<String, Object>();
39 res.put("name", assuree.getName());
41 res.put("maxpoints", assuree.getMaxAssurePoints());
42 } catch (SQLException e) {
45 res.put("dob", sdf.format(assuree.getDob()));
46 templ.output(out, l, res);
50 public boolean submit(PrintWriter out, HttpServletRequest req) {
51 out.println("<div class='formError'>");
52 boolean failed = false;
54 if (!"1".equals(req.getParameter("certify"))
55 || !"1".equals(req.getParameter("rules"))
56 || !"1".equals(req.getParameter("CCAAgreed"))
57 || !"1".equals(req.getParameter("assertion"))) {
58 outputError(out, req, "You failed to check all boxes to validate"
59 + " your adherence to the rules and policies of CAcert");
63 if (req.getParameter("date") == null
64 || req.getParameter("date").equals("")) {
66 "You must enter the date when you met the assuree.");
70 Date d = sdf.parse(req.getParameter("date"));
71 if (d.getTime() > System.currentTimeMillis()) {
73 "You must not enter a date in the future.");
76 } catch (ParseException e) {
78 "You must enter the date in this format: YYYY-MM-DD.");
82 // check location, min 3 characters
83 if (req.getParameter("location") == null
84 || req.getParameter("location").equals("")) {
86 "You failed to enter a location of your meeting.");
88 } else if (req.getParameter("location").length() <= 2) {
90 "You must enter a location with at least 3 characters eg town and country.");
94 String points = req.getParameter("points");
95 if (points == null || "".equals(points)) {
100 out.println("</div>");
104 boolean success = Notary.assure(LoginPage.getUser(req), assuree,
105 Integer.parseInt(req.getParameter("points")),
106 req.getParameter("location"), req.getParameter("date"));
108 outputError(out, req,
109 "Assurance failed. Maybe user data changed.");
111 out.println("</div>");
113 } catch (SQLException e) {
117 out.println("</div>");