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