]> WPIA git - gigi.git/blob - src/club/wpia/gigi/pages/wot/RequestTTPPage.java
Merge "upd: remove 'browser install'"
[gigi.git] / src / club / wpia / gigi / pages / wot / RequestTTPPage.java
1 package club.wpia.gigi.pages.wot;
2
3 import java.io.IOException;
4 import java.util.Map;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import club.wpia.gigi.dbObjects.User;
10 import club.wpia.gigi.dbObjects.Verification;
11 import club.wpia.gigi.output.template.Form;
12 import club.wpia.gigi.pages.LoginPage;
13 import club.wpia.gigi.pages.Page;
14 import club.wpia.gigi.util.AuthorizationContext;
15 import club.wpia.gigi.util.ServerConstants;
16
17 public class RequestTTPPage extends Page {
18
19     public static final String PATH = "/wot/ttp";
20
21     public RequestTTPPage() {
22         super("Request TTP");
23     }
24
25     @Override
26     public boolean beforePost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
27         return Form.getForm(req, RequestTTPForm.class).submitExceptionProtected(req, resp);
28     }
29
30     @Override
31     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32         if (Form.printFormErrors(req, resp.getWriter())) {
33             Form.getForm(req, RequestTTPForm.class).output(resp.getWriter(), getLanguage(req), getDefaultVars(req));
34         }
35     }
36
37     @Override
38     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
39         User u = LoginPage.getUser(req);
40         Map<String, Object> map = getDefaultVars(req);
41         if (u.isInGroup(RequestTTPForm.TTP_APPLICANT)) {
42             map.put("inProgress", true);
43         } else {
44             if (u.getVerificationPoints() < 100) {
45                 int ttpCount = 0;
46                 for (Verification a : u.getReceivedVerifications()) {
47                     if (a.getMethod().equals(Verification.VerificationType.TTP_ASSISTED.getDescription())) {
48                         ttpCount++;
49                     }
50                 }
51                 if (ttpCount < 2) {
52                     map.put("ttp", true);
53                     map.put("form", new RequestTTPForm(req));
54                 } else {
55                     map.put("nothing", true);
56                 }
57             } else {
58                 map.put("nothing", true);
59             }
60         }
61         map.put("form", new RequestTTPForm(req));
62         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), map);
63     }
64
65     @Override
66     public boolean isPermitted(AuthorizationContext ac) {
67         return ac != null && ac.getTarget() instanceof User && !ServerConstants.isCommunityCA();
68     }
69
70 }