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 {
25 public static final String PATH = "/wot/assure";
27 DateSelector ds = new DateSelector("day", "month", "year");
32 super("Assure someone");
33 t = new Template(AssuranceForm.class.getResource("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 int mid = Integer.parseInt(pi.substring(1));
44 AssuranceForm form = new AssuranceForm(req, mid);
45 outputForm(req, out, mid, form);
48 HashMap<String, Object> vars = new HashMap<String, Object>();
50 t.output(out, getLanguage(req), vars);
54 private void outputForm(HttpServletRequest req, PrintWriter out, int mid, AssuranceForm form) {
55 User myself = LoginPage.getUser(req);
56 AssuranceResult check = Notary.checkAssuranceIsPossible(myself, new User(mid));
57 if (check != AssuranceResult.ASSURANCE_SUCCEDED) {
58 out.println(translate(req, check.getMessage()));
61 if (form == null || form.assuree.getId() != mid) {
62 form = new AssuranceForm(req, mid);
65 form.output(out, getLanguage(req), new HashMap<String, Object>());
69 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
70 PrintWriter out = resp.getWriter();
71 String pi = req.getPathInfo().substring(PATH.length());
72 if (pi.length() > 1) {
73 User myself = getUser(req);
74 int mid = Integer.parseInt(pi.substring(1));
75 if (mid == myself.getId()) {
76 out.println(translate(req, "Cannot assure myself."));
80 AssuranceForm form = Form.getForm(req, AssuranceForm.class);
81 if (mid != form.assuree.getId()) {
84 if (form.submit(out, req)) {
85 out.println(translate(req, "Assurance complete."));
87 outputForm(req, resp.getWriter(), mid, form);
95 PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id, verified FROM users WHERE email=? AND dob=? AND deleted=0");
96 ps.setString(1, req.getParameter("email"));
97 String day = req.getParameter("year") + "-" + req.getParameter("month") + "-" + req.getParameter("day");
99 rs = ps.executeQuery();
103 int verified = rs.getInt(2);
105 out.println("Error, ambigous user. Please contact support@cacert.org.");
108 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
110 resp.sendRedirect(PATH + "/" + id);
113 out.print("<div class='formError'>");
115 out.println(translate(req, "I'm sorry, there was no email and date of birth matching" + " what you entered in the system. Please double check" + " your information."));
120 } catch (SQLException e) {
127 } catch (SQLException e) {