1 package org.cacert.gigi.pages.wot;
3 import java.io.IOException;
4 import java.io.PrintWriter;
6 import java.util.Calendar;
7 import java.util.HashMap;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
12 import org.cacert.gigi.GigiApiException;
13 import org.cacert.gigi.database.GigiPreparedStatement;
14 import org.cacert.gigi.database.GigiResultSet;
15 import org.cacert.gigi.dbObjects.User;
16 import org.cacert.gigi.output.DateSelector;
17 import org.cacert.gigi.output.template.Form;
18 import org.cacert.gigi.output.template.Template;
19 import org.cacert.gigi.pages.LoginPage;
20 import org.cacert.gigi.pages.Page;
21 import org.cacert.gigi.util.AuthorizationContext;
22 import org.cacert.gigi.util.Notary;
24 public class AssurePage extends Page {
26 public static final String PATH = "/wot/assure";
28 DateSelector ds = new DateSelector("day", "month", "year");
33 super("Assure someone");
34 t = new Template(AssuranceForm.class.getResource("AssureeSearch.templ"));
39 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
41 PrintWriter out = resp.getWriter();
42 HashMap<String, Object> vars = new HashMap<String, Object>();
44 t.output(out, getLanguage(req), vars);
48 public boolean isPermitted(AuthorizationContext ac) {
49 return ac != null && ac.canAssure();
53 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
54 PrintWriter out = resp.getWriter();
55 if (req.getParameter("search") == null) {
56 AssuranceForm form = Form.getForm(req, AssuranceForm.class);
57 if (form.submit(out, req)) {
58 out.println(translate(req, "Assurance complete."));
61 Notary.checkAssuranceIsPossible(LoginPage.getUser(req), form.getAssuree());
62 form.output(out, getLanguage(req), new HashMap<String, Object>());
63 } catch (GigiApiException e) {
64 e.format(out, Page.getLanguage(req));
71 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")) {
72 ps.setString(1, req.getParameter("email"));
73 Calendar c = Calendar.getInstance();
74 c.set(Integer.parseInt(req.getParameter("year")), Integer.parseInt(req.getParameter("month")) - 1, Integer.parseInt(req.getParameter("day")));
75 ps.setDate(2, new Date(c.getTimeInMillis()));
76 GigiResultSet rs = ps.executeQuery();
80 boolean verified = rs.getBoolean(2);
82 out.println("Error, ambigous user. Please contact support@cacert.org.");
85 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
86 } else if (getUser(req).getId() == id) {
89 User assuree = User.getById(id);
90 User myself = LoginPage.getUser(req);
92 Notary.checkAssuranceIsPossible(myself, assuree);
93 new AssuranceForm(req, assuree).output(out, getLanguage(req), new HashMap<String, Object>());
94 } catch (GigiApiException e) {
95 e.format(out, Page.getLanguage(req));
100 out.print("<div class='formError'>");
102 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."));