]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java
add: show verification status of email address for support
[gigi.git] / src / org / cacert / gigi / pages / admin / support / SupportUserDetailsPage.java
1 package org.cacert.gigi.pages.admin.support;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import org.cacert.gigi.GigiApiException;
11 import org.cacert.gigi.dbObjects.Domain;
12 import org.cacert.gigi.dbObjects.EmailAddress;
13 import org.cacert.gigi.dbObjects.SupportedUser;
14 import org.cacert.gigi.dbObjects.User;
15 import org.cacert.gigi.localisation.Language;
16 import org.cacert.gigi.output.template.Form;
17 import org.cacert.gigi.output.template.IterableDataset;
18 import org.cacert.gigi.pages.LoginPage;
19 import org.cacert.gigi.pages.Page;
20 import org.cacert.gigi.util.AuthorizationContext;
21
22 public class SupportUserDetailsPage extends Page {
23
24     public static final String PATH = "/support/user/";
25
26     public SupportUserDetailsPage() {
27         super("Support: User Details");
28     }
29
30     @Override
31     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32         int id = -1;
33         String[] idP = req.getPathInfo().split("/");
34         try {
35             id = Integer.parseInt(idP[idP.length - 1]);
36         } catch (NumberFormatException e) {
37             resp.sendError(404);
38         }
39         final User user = User.getById(id);
40         SupportedUser targetUser = new SupportedUser(user, getUser(req), LoginPage.getAuthorizationContext(req).getSupporterTicketId());
41         SupportUserDetailsForm f = new SupportUserDetailsForm(req, targetUser);
42         HashMap<String, Object> vars = new HashMap<String, Object>();
43         vars.put("details", f);
44         final EmailAddress[] addrs = user.getEmails();
45         vars.put("emails", new IterableDataset() {
46
47             int i = 0;
48
49             @Override
50             public boolean next(Language l, Map<String, Object> vars) {
51                 for (; i < addrs.length;) {
52                     EmailAddress secAddress = addrs[i++];
53                     String address = secAddress.getAddress();
54                     if ( !address.equals(user.getEmail())) {
55                         vars.put("secmail", address);
56                         vars.put("status", l.getTranslation(secAddress.isVerified() ? "verified" : "not verified"));
57                         return true;
58                     }
59                 }
60                 return false;
61             }
62         });
63
64         final Domain[] doms = user.getDomains();
65         vars.put("domains", new IterableDataset() {
66
67             private int point = 0;
68
69             @Override
70             public boolean next(Language l, Map<String, Object> vars) {
71                 if (point >= doms.length) {
72                     return false;
73                 }
74                 Domain domain = doms[point];
75                 vars.put("domain", domain.getSuffix());
76                 vars.put("status", l.getTranslation(domain.isVerified() ? "verified" : "not verified"));
77                 point++;
78                 return true;
79             }
80         });
81
82         vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, targetUser));
83         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
84     }
85
86     @Override
87     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
88         try {
89             if (req.getParameter("revokeall") != null) {
90                 if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
91                     throw new GigiApiException("No ticket number set.");
92                 }
93             } else if (req.getParameter("detailupdate") != null || req.getParameter("resetPass") != null || req.getParameter("deny") != null || req.getParameter("grant") != null) {
94                 if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
95                     throw new GigiApiException("No ticket number set.");
96                 }
97             }
98         } catch (GigiApiException e) {
99             e.printStackTrace();
100             e.format(resp.getWriter(), getLanguage(req));
101         }
102         super.doPost(req, resp);
103     }
104
105     @Override
106     public boolean isPermitted(AuthorizationContext ac) {
107         return ac != null && ac.canSupport();
108     }
109 }