]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java
Clean: use "authorizationContexts"
[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.EmailAddress;
12 import org.cacert.gigi.dbObjects.Group;
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.Page;
19 import org.cacert.gigi.util.AuthorizationContext;
20
21 public class SupportUserDetailsPage extends Page {
22
23     public static final String PATH = "/support/user/";
24
25     public SupportUserDetailsPage(String title) {
26         super(title);
27     }
28
29     @Override
30     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
31         int id = -1;
32         String[] idP = req.getPathInfo().split("/");
33         try {
34             id = Integer.parseInt(idP[idP.length - 1]);
35         } catch (NumberFormatException e) {
36             resp.sendError(404);
37         }
38         final User user = User.getById(id);
39         String ticket = (String) req.getSession().getAttribute("ticketNo" + user.getId());
40         SupportUserDetailsForm f = new SupportUserDetailsForm(req, new SupportedUser(user, getUser(req), ticket));
41         HashMap<String, Object> vars = new HashMap<String, Object>();
42         vars.put("details", f);
43         vars.put("ticketNo", ticket);
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                 if (i == addrs.length) {
52                     return false;
53                 }
54                 String address = addrs[i].getAddress();
55                 i++;
56                 if ( !address.equals(user.getEmail())) {
57                     vars.put("secmail", address);
58                 }
59                 return true;
60             }
61         });
62         vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, new SupportedUser(user, getUser(req), ticket)));
63         vars.put("tickethandling", new SupportEnterTicketForm(req, user));
64         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
65     }
66
67     @Override
68     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
69         try {
70             if (req.getParameter("setTicket") != null) {
71
72                 if ( !Form.getForm(req, SupportEnterTicketForm.class).submit(resp.getWriter(), req)) {
73                     throw new GigiApiException("Invalid ticket number!");
74                 }
75             } else if (req.getParameter("revokeall") != null) {
76                 if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
77                     throw new GigiApiException("No ticket number set.");
78                 }
79             } else if (req.getParameter("detailupdate") != null) {
80                 if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
81                     throw new GigiApiException("No ticket number set.");
82                 }
83             }
84         } catch (GigiApiException e) {
85             e.printStackTrace();
86             e.format(resp.getWriter(), getLanguage(req));
87         }
88         super.doPost(req, resp);
89     }
90
91     @Override
92     public boolean isPermitted(AuthorizationContext ac) {
93         return ac != null && ac.isInGroup(Group.SUPPORTER);
94     }
95 }