]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/wot/AssurePage.java
add: Allow multiple names, name-schemes, multi-name-assurance, etc.
[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("Assure 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             try {
53                 if (form.submit(out, req)) {
54                     out.println(translate(req, "Assurance complete."));
55                     return;
56                 }
57             } catch (GigiApiException e) {
58                 e.format(out, Page.getLanguage(req));
59                 form.output(out, getLanguage(req), new HashMap<String, Object>());
60             }
61
62             return;
63         }
64
65         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")) {
66             ds.update(req);
67
68             ps.setString(1, req.getParameter("email"));
69             ps.setDate(2, ds.getDate().toSQLDate());
70             GigiResultSet rs = ps.executeQuery();
71             int id = 0;
72             if (rs.next()) {
73                 id = rs.getInt(1);
74                 boolean verified = rs.getBoolean(2);
75                 if (rs.next()) {
76                     out.println("Error, ambigous user. Please contact support@cacert.org.");
77                 } else {
78                     if ( !verified) {
79                         out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
80                     } else if (getUser(req).getId() == id) {
81
82                     } else {
83                         User assuree = User.getById(id);
84                         try {
85                             new AssuranceForm(req, assuree).output(out, getLanguage(req), new HashMap<String, Object>());
86                         } catch (GigiApiException e) {
87                             e.format(out, Page.getLanguage(req));
88                         }
89                     }
90                 }
91             } else {
92                 throw new GigiApiException("I'm sorry, there was no email and date of birth matching" //
93                         + " what you entered in the system. Please double check your information.");
94             }
95
96         } catch (GigiApiException e) {
97             e.format(out, getLanguage(req));
98         }
99     }
100 }