]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java
add: more strict ticket handling. User history page
[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.SupportedUser;
13 import org.cacert.gigi.dbObjects.User;
14 import org.cacert.gigi.localisation.Language;
15 import org.cacert.gigi.output.template.Form;
16 import org.cacert.gigi.output.template.IterableDataset;
17 import org.cacert.gigi.pages.LoginPage;
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         SupportedUser targetUser = new SupportedUser(user, getUser(req), LoginPage.getAuthorizationContext(req).getSupporterTicketId());
40         SupportUserDetailsForm f = new SupportUserDetailsForm(req, targetUser);
41         HashMap<String, Object> vars = new HashMap<String, Object>();
42         vars.put("details", f);
43         final EmailAddress[] addrs = user.getEmails();
44         vars.put("emails", new IterableDataset() {
45
46             int i = 0;
47
48             @Override
49             public boolean next(Language l, Map<String, Object> vars) {
50                 if (i == addrs.length) {
51                     return false;
52                 }
53                 String address = addrs[i].getAddress();
54                 i++;
55                 if ( !address.equals(user.getEmail())) {
56                     vars.put("secmail", address);
57                 }
58                 return true;
59             }
60         });
61         vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, targetUser));
62         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
63     }
64
65     @Override
66     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
67         try {
68             if (req.getParameter("revokeall") != null) {
69                 if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
70                     throw new GigiApiException("No ticket number set.");
71                 }
72             } else if (req.getParameter("detailupdate") != null) {
73                 if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
74                     throw new GigiApiException("No ticket number set.");
75                 }
76             }
77         } catch (GigiApiException e) {
78             e.printStackTrace();
79             e.format(resp.getWriter(), getLanguage(req));
80         }
81         super.doPost(req, resp);
82     }
83
84     @Override
85     public boolean isPermitted(AuthorizationContext ac) {
86         return ac != null && ac.canSupport();
87     }
88 }