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.pages.LoginPage;
20 import org.cacert.gigi.pages.Page;
21 import org.cacert.gigi.util.Notary;
23 public class AssurePage extends Page {
24 public static final String PATH = "/wot/assure";
25 public static final String SESSION = "/wot/assure/FORM";
26 DateSelector ds = new DateSelector("day", "month", "year");
30 super("Assure someone");
31 t = new Template(new InputStreamReader(
32 AssuranceForm.class.getResourceAsStream("AssureeSearch.templ")));
37 public void doGet(HttpServletRequest req, HttpServletResponse resp)
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));
46 if (!Notary.checkAssuranceIsPossible(myself, new User(mid), out)) {
49 HttpSession hs = req.getSession();
50 AssuranceForm form = (AssuranceForm) hs.getAttribute(SESSION);
51 if (form == null || form.assuree.getId() != mid) {
52 form = new AssuranceForm(mid);
53 hs.setAttribute(SESSION, form);
56 form.output(out, getLanguage(req), new HashMap<String, Object>());;
58 HashMap<String, Object> vars = new HashMap<String, Object>();
60 t.output(out, getLanguage(req), vars);
64 public void doPost(HttpServletRequest req, HttpServletResponse resp)
66 PrintWriter out = resp.getWriter();
67 String pi = req.getPathInfo().substring(PATH.length());
68 if (pi.length() > 1) {
69 User myself = LoginPage.getUser(req);
70 int mid = Integer.parseInt(pi.substring(1));
71 if (mid == myself.getId()) {
72 out.println("Cannot assure myself.");
76 AssuranceForm form = (AssuranceForm) req.getSession().getAttribute(
79 out.println("No form found. This is an Error. Fill in the form again.");
82 form.submit(out, req);
87 System.out.println("searching for");
90 PreparedStatement ps = DatabaseConnection
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") + "-"
96 + req.getParameter("month") + "-" + req.getParameter("day");
98 rs = ps.executeQuery();
102 int verified = rs.getInt(2);
104 out.println("Error, ambigous user. Please contact support@cacert.org.");
107 out.println(translate(req,
108 "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(
117 "I'm sorry, there was no email and date of birth matching"
118 + " what you entered in the system. Please double check"
119 + " your information."));
124 } catch (SQLException e) {
131 } catch (SQLException e) {