]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/wot/AssurePage.java
fix: seems I missed one "static final Template"
[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.LoginPage;
18 import org.cacert.gigi.pages.Page;
19 import org.cacert.gigi.util.AuthorizationContext;
20 import org.cacert.gigi.util.Notary;
21
22 public class AssurePage extends Page {
23
24     public static final String PATH = "/wot/assure";
25
26     DateSelector ds = new DateSelector("day", "month", "year");
27
28     private static final Template t = new Template(AssuranceForm.class.getResource("AssureeSearch.templ"));
29
30     public AssurePage() {
31         super("Assure someone");
32
33     }
34
35     @Override
36     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
37
38         PrintWriter out = resp.getWriter();
39         HashMap<String, Object> vars = new HashMap<String, Object>();
40         vars.put("DoB", ds);
41         t.output(out, getLanguage(req), vars);
42     }
43
44     @Override
45     public boolean isPermitted(AuthorizationContext ac) {
46         return ac != null && ac.canAssure();
47     }
48
49     @Override
50     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
51         PrintWriter out = resp.getWriter();
52         if (req.getParameter("search") == null) {
53             AssuranceForm form = Form.getForm(req, AssuranceForm.class);
54             try {
55                 if (form.submit(out, req)) {
56                     out.println(translate(req, "Assurance complete."));
57                     return;
58                 }
59             } catch (GigiApiException e) {
60                 e.format(out, Page.getLanguage(req));
61                 try {
62                     Notary.checkAssuranceIsPossible(LoginPage.getUser(req), form.getAssuree());
63                     form.output(out, getLanguage(req), new HashMap<String, Object>());
64                 } catch (GigiApiException e1) {
65                     e1.format(out, Page.getLanguage(req));
66                 }
67             }
68
69             return;
70         }
71
72         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")) {
73             ds.update(req);
74
75             ps.setString(1, req.getParameter("email"));
76             ps.setDate(2, ds.getDate().toSQLDate());
77             GigiResultSet rs = ps.executeQuery();
78             int id = 0;
79             if (rs.next()) {
80                 id = rs.getInt(1);
81                 boolean verified = rs.getBoolean(2);
82                 if (rs.next()) {
83                     out.println("Error, ambigous user. Please contact support@cacert.org.");
84                 } else {
85                     if ( !verified) {
86                         out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
87                     } else if (getUser(req).getId() == id) {
88
89                     } else {
90                         User assuree = User.getById(id);
91                         User myself = LoginPage.getUser(req);
92                         try {
93                             Notary.checkAssuranceIsPossible(myself, assuree);
94                             new AssuranceForm(req, assuree).output(out, getLanguage(req), new HashMap<String, Object>());
95                         } catch (GigiApiException e) {
96                             e.format(out, Page.getLanguage(req));
97                         }
98                     }
99                 }
100             } else {
101                 throw new GigiApiException("I'm sorry, there was no email and date of birth matching" //
102                         + " what you entered in the system. Please double check your information.");
103             }
104
105         } catch (GigiApiException e) {
106             e.format(out, getLanguage(req));
107         }
108     }
109 }