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.LoginPage;
18 import org.cacert.gigi.pages.Page;
19 import org.cacert.gigi.util.AuthorizationContext;
20 import org.cacert.gigi.util.Notary;
22 public class AssurePage extends Page {
24 public static final String PATH = "/wot/assure";
26 DateSelector ds = new DateSelector("day", "month", "year");
31 super("Assure someone");
32 t = new Template(AssuranceForm.class.getResource("AssureeSearch.templ"));
37 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
39 PrintWriter out = resp.getWriter();
40 HashMap<String, Object> vars = new HashMap<String, Object>();
42 t.output(out, getLanguage(req), vars);
46 public boolean isPermitted(AuthorizationContext ac) {
47 return ac != null && ac.canAssure();
51 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
52 PrintWriter out = resp.getWriter();
53 if (req.getParameter("search") == null) {
54 AssuranceForm form = Form.getForm(req, AssuranceForm.class);
56 if (form.submit(out, req)) {
57 out.println(translate(req, "Assurance complete."));
60 } catch (GigiApiException e) {
61 e.format(out, Page.getLanguage(req));
63 Notary.checkAssuranceIsPossible(LoginPage.getUser(req), form.getAssuree());
64 form.output(out, getLanguage(req), new HashMap<String, Object>());
65 } catch (GigiApiException e1) {
66 e1.format(out, Page.getLanguage(req));
73 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")) {
76 ps.setString(1, req.getParameter("email"));
77 ps.setDate(2, ds.getDate().toSQLDate());
78 GigiResultSet rs = ps.executeQuery();
82 boolean verified = rs.getBoolean(2);
84 out.println("Error, ambigous user. Please contact support@cacert.org.");
87 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
88 } else if (getUser(req).getId() == id) {
91 User assuree = User.getById(id);
92 User myself = LoginPage.getUser(req);
94 Notary.checkAssuranceIsPossible(myself, assuree);
95 new AssuranceForm(req, assuree).output(out, getLanguage(req), new HashMap<String, Object>());
96 } catch (GigiApiException e) {
97 e.format(out, Page.getLanguage(req));
102 throw new GigiApiException("I'm sorry, there was no email and date of birth matching" //
103 + " what you entered in the system. Please double check your information.");
106 } catch (GigiApiException e) {
107 e.format(out, getLanguage(req));