]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/wot/AssurePage.java
95ab35f0bc223b3246d61325e0577f446864596c
[gigi.git] / src / org / cacert / gigi / pages / wot / AssurePage.java
1 package org.cacert.gigi.pages.wot;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.HashMap;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
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;
19
20 public class AssurePage extends Page {
21
22     public static final String PATH = "/wot/assure";
23
24     DateSelector ds = new DateSelector("day", "month", "year");
25
26     private static final Template t = new Template(AssuranceForm.class.getResource("AssureeSearch.templ"));
27
28     public AssurePage() {
29         super("Verify someone");
30
31     }
32
33     @Override
34     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
35
36         PrintWriter out = resp.getWriter();
37         HashMap<String, Object> vars = new HashMap<String, Object>();
38         vars.put("DoB", ds);
39         t.output(out, getLanguage(req), vars);
40     }
41
42     @Override
43     public boolean isPermitted(AuthorizationContext ac) {
44         return ac != null && ac.canAssure();
45     }
46
47     @Override
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."));
54                 return;
55             }
56             return;
57         }
58
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")) {
60             ds.update(req);
61
62             ps.setString(1, req.getParameter("email"));
63             ps.setDate(2, ds.getDate().toSQLDate());
64             GigiResultSet rs = ps.executeQuery();
65             int id = 0;
66             if (rs.next()) {
67                 id = rs.getInt(1);
68                 boolean verified = rs.getBoolean(2);
69                 if (rs.next()) {
70                     out.println("Error, ambigous user. Please contact support@cacert.org.");
71                 } else {
72                     if ( !verified) {
73                         out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
74                     } else if (getUser(req).getId() == id) {
75
76                     } else {
77                         User assuree = User.getById(id);
78                         try {
79                             new AssuranceForm(req, assuree).output(out, getLanguage(req), new HashMap<String, Object>());
80                         } catch (GigiApiException e) {
81                             e.format(out, Page.getLanguage(req));
82                         }
83                     }
84                 }
85             } else {
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.");
88             }
89
90         } catch (GigiApiException e) {
91             e.format(out, getLanguage(req));
92         }
93     }
94 }