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