1 package org.cacert.gigi.pages.wot;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.HashMap;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import org.cacert.gigi.GigiApiException;
11 import org.cacert.gigi.database.GigiPreparedStatement;
12 import org.cacert.gigi.database.GigiResultSet;
13 import org.cacert.gigi.dbObjects.User;
14 import org.cacert.gigi.output.DateSelector;
15 import org.cacert.gigi.output.template.Form;
16 import org.cacert.gigi.output.template.Template;
17 import org.cacert.gigi.pages.Page;
18 import org.cacert.gigi.util.AuthorizationContext;
20 public class AssurePage extends Page {
22 public static final String PATH = "/wot/assure";
24 DateSelector ds = new DateSelector("day", "month", "year");
26 private static final Template t = new Template(AssuranceForm.class.getResource("AssureeSearch.templ"));
29 super("Verify someone");
34 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
36 PrintWriter out = resp.getWriter();
37 HashMap<String, Object> vars = new HashMap<String, Object>();
39 t.output(out, getLanguage(req), vars);
43 public boolean isPermitted(AuthorizationContext ac) {
44 return ac != null && ac.canAssure();
48 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
49 PrintWriter out = resp.getWriter();
50 if (req.getParameter("search") == null) {
51 AssuranceForm form = Form.getForm(req, AssuranceForm.class);
52 if (form.submitProtected(out, req)) {
53 out.println(translate(req, "Verification complete."));
59 try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `users`.`id`, `verified` FROM `users` INNER JOIN `certOwners` ON `certOwners`.`id`=`users`.`id` WHERE `email`=? AND `dob`=? AND `deleted` IS NULL")) {
62 ps.setString(1, req.getParameter("email"));
63 ps.setDate(2, ds.getDate().toSQLDate());
64 GigiResultSet rs = ps.executeQuery();
68 boolean verified = rs.getBoolean(2);
70 out.println("Error, ambigous user. Please contact support@cacert.org.");
73 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
74 } else if (getUser(req).getId() == id) {
77 User assuree = User.getById(id);
79 new AssuranceForm(req, assuree).output(out, getLanguage(req), new HashMap<String, Object>());
80 } catch (GigiApiException e) {
81 e.format(out, Page.getLanguage(req));
86 throw new GigiApiException("I'm sorry, there was no email and date of birth matching" //
87 + " what you entered in the system. Please double check your information.");
90 } catch (GigiApiException e) {
91 e.format(out, getLanguage(req));