1 package org.cacert.gigi.pages.wot;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.sql.PreparedStatement;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8 import java.util.HashMap;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
13 import org.cacert.gigi.User;
14 import org.cacert.gigi.database.DatabaseConnection;
15 import org.cacert.gigi.output.DateSelector;
16 import org.cacert.gigi.output.Form;
17 import org.cacert.gigi.output.template.Template;
18 import org.cacert.gigi.pages.LoginPage;
19 import org.cacert.gigi.pages.Page;
20 import org.cacert.gigi.util.Notary;
21 import org.cacert.gigi.util.Notary.AssuranceResult;
23 public class AssurePage extends Page {
24 public static final String PATH = "/wot/assure";
25 DateSelector ds = new DateSelector("day", "month", "year");
29 super("Assure someone");
30 t = new Template(AssuranceForm.class.getResource("AssureeSearch.templ"));
35 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
37 PrintWriter out = resp.getWriter();
38 String pi = req.getPathInfo().substring(PATH.length());
39 if (pi.length() > 1) {
40 int mid = Integer.parseInt(pi.substring(1));
41 AssuranceForm form = new AssuranceForm(req, mid);
42 outputForm(req, out, mid, form);
45 HashMap<String, Object> vars = new HashMap<String, Object>();
47 t.output(out, getLanguage(req), vars);
51 private void outputForm(HttpServletRequest req, PrintWriter out, int mid, AssuranceForm form) {
52 User myself = LoginPage.getUser(req);
53 AssuranceResult check = Notary.checkAssuranceIsPossible(myself, new User(mid));
54 if (check != AssuranceResult.ASSURANCE_SUCCEDED) {
55 out.println(translate(req, check.getMessage()));
58 if (form == null || form.assuree.getId() != mid) {
59 form = new AssuranceForm(req, mid);
62 form.output(out, getLanguage(req), new HashMap<String, Object>());
66 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
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(translate(req, "Cannot assure myself."));
77 AssuranceForm form = Form.getForm(req, AssuranceForm.class);
78 if (mid != form.assuree.getId()) {
81 if (form.submit(out, req)) {
82 out.println(translate(req, "Assurance complete."));
84 outputForm(req, resp.getWriter(), mid, form);
92 PreparedStatement ps = DatabaseConnection.getInstance().prepare(
93 "SELECT id, verified FROM users WHERE email=? AND dob=? AND deleted=0");
94 ps.setString(1, req.getParameter("email"));
95 String day = req.getParameter("year") + "-" + req.getParameter("month") + "-" + req.getParameter("day");
97 rs = ps.executeQuery();
101 int verified = rs.getInt(2);
103 out.println("Error, ambigous user. Please contact support@cacert.org.");
106 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
108 resp.sendRedirect(PATH + "/" + id);
111 out.print("<div class='formError'>");
113 out.println(translate(req, "I'm sorry, there was no email and date of birth matching"
114 + " what you entered in the system. Please double check" + " your information."));
119 } catch (SQLException e) {
126 } catch (SQLException e) {