]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java
upd: use bootstrap class for button
[gigi.git] / src / org / cacert / gigi / pages / admin / support / SupportUserDetailsPage.java
index fccdd5ee2121fbc6af5db801e468dab3e175b5d6..5f626b4ef5d24e3c78a8c7afea46843e664b91f3 100644 (file)
@@ -7,28 +7,41 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.EmailAddress;
-import org.cacert.gigi.dbObjects.Group;
+import org.cacert.gigi.dbObjects.SupportedUser;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.IterableDataset;
+import org.cacert.gigi.pages.LoginPage;
 import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.util.AuthorizationContext;
 
 public class SupportUserDetailsPage extends Page {
 
     public static final String PATH = "/support/user/";
 
-    public SupportUserDetailsPage(String title) {
-        super(title);
+    public SupportUserDetailsPage() {
+        super("Support: User Details");
     }
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        int id;
+        int id = -1;
+        if ( !req.getPathInfo().endsWith("/")) {
+            resp.sendError(404);
+        }
         String[] idP = req.getPathInfo().split("/");
-        id = Integer.parseInt(idP[idP.length - 1]);
+        try {
+            id = Integer.parseInt(idP[idP.length - 1]);
+        } catch (NumberFormatException e) {
+            resp.sendError(404);
+        }
         final User user = User.getById(id);
-        SupportUserDetailsForm f = new SupportUserDetailsForm(req, user);
+        SupportedUser targetUser = new SupportedUser(user, getUser(req), LoginPage.getAuthorizationContext(req).getSupporterTicketId());
+        SupportUserDetailsForm f = new SupportUserDetailsForm(req, targetUser);
         HashMap<String, Object> vars = new HashMap<String, Object>();
         vars.put("details", f);
         final EmailAddress[] addrs = user.getEmails();
@@ -38,23 +51,62 @@ public class SupportUserDetailsPage extends Page {
 
             @Override
             public boolean next(Language l, Map<String, Object> vars) {
-                String address = addrs[i].getAddress();
-                if ( !address.equals(user.getEmail())) {
-                    vars.put("secmail", address);
+                for (; i < addrs.length;) {
+                    EmailAddress secAddress = addrs[i++];
+                    String address = secAddress.getAddress();
+                    if ( !address.equals(user.getEmail())) {
+                        vars.put("secmail", address);
+                        vars.put("status", l.getTranslation(secAddress.isVerified() ? "verified" : "not verified"));
+                        return true;
+                    }
                 }
-                i++;
-                return i != addrs.length - 1;
+                return false;
             }
         });
-        vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, user));
+
+        final Domain[] doms = user.getDomains();
+        vars.put("domains", new IterableDataset() {
+
+            private int point = 0;
+
+            @Override
+            public boolean next(Language l, Map<String, Object> vars) {
+                if (point >= doms.length) {
+                    return false;
+                }
+                Domain domain = doms[point];
+                vars.put("domain", domain.getSuffix());
+                vars.put("status", l.getTranslation(domain.isVerified() ? "verified" : "not verified"));
+                point++;
+                return true;
+            }
+        });
+
+        vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, targetUser));
         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
     }
 
     @Override
-    public boolean isPermitted(User u) {
-        if (u == null) {
-            return false;
+    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        try {
+            if (req.getParameter("revokeall") != null) {
+                if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
+                    throw new GigiApiException("No ticket number set.");
+                }
+            } else if (req.getParameter("detailupdate") != null || req.getParameter("resetPass") != null || req.getParameter("deny") != null || req.getParameter("grant") != null) {
+                if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
+                    throw new GigiApiException("No ticket number set.");
+                }
+            }
+        } catch (GigiApiException e) {
+            e.printStackTrace();
+            e.format(resp.getWriter(), getLanguage(req));
         }
-        return u.isInGroup(Group.getByString("supporter"));
+        super.doPost(req, resp);
+    }
+
+    @Override
+    public boolean isPermitted(AuthorizationContext ac) {
+        return ac != null && ac.canSupport();
     }
 }