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