1 package club.wpia.gigi.pages.wot;
3 import java.io.IOException;
4 import java.io.PrintWriter;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import club.wpia.gigi.GigiApiException;
11 import club.wpia.gigi.database.GigiPreparedStatement;
12 import club.wpia.gigi.database.GigiResultSet;
13 import club.wpia.gigi.dbObjects.User;
14 import club.wpia.gigi.output.DateSelector;
15 import club.wpia.gigi.output.template.Form;
16 import club.wpia.gigi.output.template.Template;
17 import club.wpia.gigi.pages.Page;
18 import club.wpia.gigi.util.AuthorizationContext;
20 public class VerifyPage extends Page {
22 public static final String PATH = "/wot/verify";
24 DateSelector ds = new DateSelector("day", "month", "year");
26 private static final Template t = new Template(VerificationForm.class.getResource("ApplicantSearch.templ"));
29 super("Verify someone");
34 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
36 PrintWriter out = resp.getWriter();
37 Map<String, Object> vars = getDefaultVars(req);
39 t.output(out, getLanguage(req), vars);
43 public boolean isPermitted(AuthorizationContext ac) {
44 return ac != null && ac.canVerify();
48 public boolean beforePost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
49 if (req.getParameter("search") == null) {
50 VerificationForm form = Form.getForm(req, VerificationForm.class);
51 return form.submitExceptionProtected(req, resp);
53 return super.beforePost(req, resp);
57 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
58 PrintWriter out = resp.getWriter();
59 if (req.getParameter("search") == null) {
60 if (Form.printFormErrors(req, out)) {
61 VerificationForm form = Form.getForm(req, VerificationForm.class);
62 form.output(out, getLanguage(req), getDefaultVars(req));
67 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")) {
70 ps.setString(1, req.getParameter("email"));
71 ps.setDate(2, ds.getDate().toSQLDate());
72 GigiResultSet rs = ps.executeQuery();
76 boolean verified = rs.getBoolean(2);
78 out.println("Error, ambigous user. Please contact support.");
81 out.println(translate(req, "User is not yet verified. Please try again in 24 hours!"));
83 User applicant = User.getById(id);
85 new VerificationForm(req, applicant).output(out, getLanguage(req), getDefaultVars(req));
86 } catch (GigiApiException e) {
87 e.format(out, Page.getLanguage(req), getDefaultVars(req));
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.");
96 } catch (GigiApiException e) {
97 e.format(out, getLanguage(req), getDefaultVars(req));