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.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;
21 public class SupportUserDetailsPage extends Page {
23 public static final String PATH = "/support/user/";
25 public SupportUserDetailsPage(String title) {
30 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32 String[] idP = req.getPathInfo().split("/");
34 id = Integer.parseInt(idP[idP.length - 1]);
35 } catch (NumberFormatException e) {
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() {
49 public boolean next(Language l, Map<String, Object> vars) {
50 for (; i < addrs.length;) {
51 String address = addrs[i++].getAddress();
52 if ( !address.equals(user.getEmail())) {
53 vars.put("secmail", address);
60 vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, targetUser));
61 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
65 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
67 if (req.getParameter("revokeall") != null) {
68 if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
69 throw new GigiApiException("No ticket number set.");
71 } else if (req.getParameter("detailupdate") != null || req.getParameter("resetPass") != null || req.getParameter("deny") != null || req.getParameter("grant") != null) {
72 if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
73 throw new GigiApiException("No ticket number set.");
76 } catch (GigiApiException e) {
78 e.format(resp.getWriter(), getLanguage(req));
80 super.doPost(req, resp);
84 public boolean isPermitted(AuthorizationContext ac) {
85 return ac != null && ac.canSupport();