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;
23 import org.cacert.gigi.util.Notary.AssuranceResult;
25 public class AssurePage extends Page {
26 public static final String PATH = "/wot/assure";
27 public static final String SESSION = "/wot/assure/FORM";
28 DateSelector ds = new DateSelector("day", "month", "year");
32 super("Assure someone");
33 t = new Template(new InputStreamReader(AssuranceForm.class.getResourceAsStream("AssureeSearch.templ")));
38 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
40 PrintWriter out = resp.getWriter();
41 String pi = req.getPathInfo().substring(PATH.length());
42 if (pi.length() > 1) {
43 User myself = LoginPage.getUser(req);
44 int mid = Integer.parseInt(pi.substring(1));
45 AssuranceResult check = Notary.checkAssuranceIsPossible(myself, new User(mid));
46 if (check != AssuranceResult.ASSURANCE_SUCCEDED) {
47 out.println(translate(req, check.getMessage()));
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>());
60 HashMap<String, Object> vars = new HashMap<String, Object>();
62 t.output(out, getLanguage(req), vars);
67 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
68 PrintWriter out = resp.getWriter();
69 String pi = req.getPathInfo().substring(PATH.length());
70 if (pi.length() > 1) {
71 User myself = LoginPage.getUser(req);
72 int mid = Integer.parseInt(pi.substring(1));
73 if (mid == myself.getId()) {
74 out.println("Cannot assure myself.");
78 AssuranceForm form = (AssuranceForm) req.getSession().getAttribute(SESSION);
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.getInstance().prepare(
97 "SELECT id, verified FROM users WHERE email=? AND dob=? AND deleted=0");
98 ps.setString(1, req.getParameter("email"));
99 String day = req.getParameter("year") + "-" + req.getParameter("month") + "-" + req.getParameter("day");
100 ps.setString(2, day);
101 rs = ps.executeQuery();
105 int verified = rs.getInt(2);
107 out.println("Error, ambigous user. Please contact support@cacert.org.");
110 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
112 resp.sendRedirect(PATH + "/" + id);
115 out.print("<div class='formError'>");
117 out.println(translate(req, "I'm sorry, there was no email and date of birth matching"
118 + " what you entered in the system. Please double check" + " your information."));
123 } catch (SQLException e) {
130 } catch (SQLException e) {