1 package org.cacert.gigi.pages.wot;
3 import java.io.IOException;
4 import java.io.InputStreamReader;
5 import java.io.PrintWriter;
6 import java.sql.PreparedStatement;
7 import java.sql.ResultSet;
8 import java.sql.SQLException;
9 import java.util.HashMap;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import javax.servlet.http.HttpSession;
15 import org.cacert.gigi.User;
16 import org.cacert.gigi.database.DatabaseConnection;
17 import org.cacert.gigi.output.DateSelector;
18 import org.cacert.gigi.output.Template;
19 import org.cacert.gigi.output.Form.CSRFError;
20 import org.cacert.gigi.pages.LoginPage;
21 import org.cacert.gigi.pages.Page;
22 import org.cacert.gigi.util.Notary;
24 public class AssurePage extends Page {
25 public static final String PATH = "/wot/assure";
26 public static final String SESSION = "/wot/assure/FORM";
27 DateSelector ds = new DateSelector("day", "month", "year");
31 super("Assure someone");
32 t = new Template(new InputStreamReader(
33 AssuranceForm.class.getResourceAsStream("AssureeSearch.templ")));
38 public void doGet(HttpServletRequest req, HttpServletResponse resp)
41 PrintWriter out = resp.getWriter();
42 String pi = req.getPathInfo().substring(PATH.length());
43 if (pi.length() > 1) {
44 User myself = LoginPage.getUser(req);
45 int mid = Integer.parseInt(pi.substring(1));
47 if (!Notary.checkAssuranceIsPossible(myself, new User(mid), out)) {
50 HttpSession hs = req.getSession();
51 AssuranceForm form = (AssuranceForm) hs.getAttribute(SESSION);
52 if (form == null || form.assuree.getId() != mid) {
53 form = new AssuranceForm(mid);
54 hs.setAttribute(SESSION, form);
57 form.output(out, getLanguage(req), new HashMap<String, Object>());;
59 HashMap<String, Object> vars = new HashMap<String, Object>();
61 t.output(out, getLanguage(req), vars);
65 public void doPost(HttpServletRequest req, HttpServletResponse resp)
67 PrintWriter out = resp.getWriter();
68 String pi = req.getPathInfo().substring(PATH.length());
69 if (pi.length() > 1) {
70 User myself = LoginPage.getUser(req);
71 int mid = Integer.parseInt(pi.substring(1));
72 if (mid == myself.getId()) {
73 out.println("Cannot assure myself.");
77 AssuranceForm form = (AssuranceForm) req.getSession().getAttribute(
80 out.println("No form found. This is an Error. Fill in the form again.");
84 form.submit(out, req);
85 } catch (CSRFError e) {
86 resp.sendError(500, "CSRF Failed");
87 out.println(translate(req, "CSRF Token failed."));
93 System.out.println("searching for");
96 PreparedStatement ps = DatabaseConnection
99 "SELECT id, verified FROM users WHERE email=? AND dob=? AND deleted=0");
100 ps.setString(1, req.getParameter("email"));
101 String day = req.getParameter("year") + "-"
102 + req.getParameter("month") + "-" + req.getParameter("day");
103 ps.setString(2, day);
104 rs = ps.executeQuery();
108 int verified = rs.getInt(2);
110 out.println("Error, ambigous user. Please contact support@cacert.org.");
113 out.println(translate(req,
114 "User is not yet verified. Please try again in 24 hours!"));
116 resp.sendRedirect(PATH + "/" + id);
119 out.print("<div class='formError'>");
121 out.println(translate(
123 "I'm sorry, there was no email and date of birth matching"
124 + " what you entered in the system. Please double check"
125 + " your information."));
130 } catch (SQLException e) {
137 } catch (SQLException e) {