]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/wot/RequestTTPPage.java
7e50059d63172f58db35d536017e045ee8ae29ff
[gigi.git] / src / org / cacert / gigi / pages / wot / RequestTTPPage.java
1 package org.cacert.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 org.cacert.gigi.dbObjects.Assurance;
10 import org.cacert.gigi.dbObjects.User;
11 import org.cacert.gigi.output.template.Form;
12 import org.cacert.gigi.pages.LoginPage;
13 import org.cacert.gigi.pages.Page;
14 import org.cacert.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 void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
26         Form.getForm(req, RequestTTPForm.class).submitProtected(resp.getWriter(), req);
27     }
28
29     @Override
30     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
31         User u = LoginPage.getUser(req);
32         HashMap<String, Object> map = new HashMap<String, Object>();
33         if (u.isInGroup(RequestTTPForm.TTP_APPLICANT)) {
34             map.put("inProgress", true);
35         } else {
36             if (u.getAssurancePoints() < 100) {
37                 int ttpCount = 0;
38                 for (Assurance a : u.getReceivedAssurances()) {
39                     if (a.getMethod().equals(Assurance.AssuranceType.TTP_ASSISTED.getDescription())) {
40                         ttpCount++;
41                     }
42                 }
43                 if (ttpCount < 2) {
44                     map.put("ttp", true);
45                     map.put("form", new RequestTTPForm(req));
46                 } else {
47                     map.put("nothing", true);
48                 }
49             } else {
50                 map.put("nothing", true);
51             }
52         }
53         map.put("form", new RequestTTPForm(req));
54         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), map);
55     }
56
57     @Override
58     public boolean isPermitted(AuthorizationContext ac) {
59         return ac != null && ac.getTarget() instanceof User;
60     }
61
62 }