1 package org.cacert.gigi.pages.admin.support;
3 import java.io.IOException;
4 import java.util.HashMap;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
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;
22 public class SupportUserDetailsPage extends Page {
24 public static final String PATH = "/support/user/";
26 public SupportUserDetailsPage() {
27 super("Support: User Details");
31 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
33 if ( !req.getPathInfo().endsWith("/")) {
36 String[] idP = req.getPathInfo().split("/");
38 id = Integer.parseInt(idP[idP.length - 1]);
39 } catch (NumberFormatException e) {
42 final User user = User.getById(id);
43 SupportedUser targetUser = new SupportedUser(user, getUser(req), LoginPage.getAuthorizationContext(req).getSupporterTicketId());
44 SupportUserDetailsForm f = new SupportUserDetailsForm(req, targetUser);
45 HashMap<String, Object> vars = new HashMap<String, Object>();
46 vars.put("details", f);
47 final EmailAddress[] addrs = user.getEmails();
48 vars.put("emails", new IterableDataset() {
53 public boolean next(Language l, Map<String, Object> vars) {
54 for (; i < addrs.length;) {
55 EmailAddress secAddress = addrs[i++];
56 String address = secAddress.getAddress();
57 if ( !address.equals(user.getEmail())) {
58 vars.put("secmail", address);
59 vars.put("status", l.getTranslation(secAddress.isVerified() ? "verified" : "not verified"));
67 final Domain[] doms = user.getDomains();
68 vars.put("domains", new IterableDataset() {
70 private int point = 0;
73 public boolean next(Language l, Map<String, Object> vars) {
74 if (point >= doms.length) {
77 Domain domain = doms[point];
78 vars.put("domain", domain.getSuffix());
79 vars.put("status", l.getTranslation(domain.isVerified() ? "verified" : "not verified"));
85 vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, targetUser));
86 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
90 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
92 if (req.getParameter("revokeall") != null) {
93 if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
94 throw new GigiApiException("No ticket number set.");
96 } else if (req.getParameter("detailupdate") != null || req.getParameter("resetPass") != null || req.getParameter("deny") != null || req.getParameter("grant") != null) {
97 if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
98 throw new GigiApiException("No ticket number set.");
101 } catch (GigiApiException e) {
103 e.format(resp.getWriter(), getLanguage(req));
105 super.doPost(req, resp);
109 public boolean isPermitted(AuthorizationContext ac) {
110 return ac != null && ac.canSupport();