]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/account/domain/DomainOverview.java
upd: enforce a more strict Form call pattern.
[gigi.git] / src / org / cacert / gigi / pages / account / domain / DomainOverview.java
index 906e2a16b88e266cc2c11c1e08b7fc04b2d057d3..aa2043a1fbd0765f867b12229279213577f86f8b 100644 (file)
@@ -7,48 +7,32 @@ 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.DomainPingConfiguration;
+import org.cacert.gigi.dbObjects.CertificateOwner;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.output.template.Form;
-import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.output.template.Form.CSRFException;
+import org.cacert.gigi.pages.LoginPage;
+import org.cacert.gigi.pages.ManagedMultiFormPage;
 
-public class DomainOverview extends Page {
+public class DomainOverview extends ManagedMultiFormPage {
 
-    public static final String PATH = "/account/domains/";
+    public static final String PATH = "/account/domains";
 
-    public DomainOverview(String title) {
-        super(title);
+    public DomainOverview() {
+        super("Domains");
     }
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        User u = getUser(req);
-        String pi = req.getPathInfo();
-        if (pi.length() - PATH.length() > 0) {
-            int i = Integer.parseInt(pi.substring(PATH.length()));
-            Domain d = Domain.getById(i);
-            if (u.getId() != d.getOwner().getId()) {
-                System.out.println(u.getId());
-                System.out.println(d.getOwner().getId());
-                return;
-            }
-            new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
-            try {
-                new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
-            } catch (GigiApiException e) {
-                e.format(resp.getWriter(), getLanguage(req));
-            }
-            return;
-
-        }
+        CertificateOwner u = LoginPage.getAuthorizationContext(req).getTarget();
         try {
-            DomainManagementForm domMan = new DomainManagementForm(req, u);
-            DomainAddForm domAdd = new DomainAddForm(req, u);
+            DomainManagementForm domMan = new DomainManagementForm(req, u, false);
             HashMap<String, Object> vars = new HashMap<>();
-            vars.put("doms", u.getDomains());
             vars.put("domainman", domMan);
-            vars.put("domainadd", domAdd);
+            if (u instanceof User) {
+                DomainAddForm domAdd = new DomainAddForm(req, (User) u);
+                vars.put("domainadd", domAdd);
+            }
             getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
         } catch (GigiApiException e) {
             e.format(resp.getWriter(), getLanguage(req));
@@ -56,39 +40,12 @@ public class DomainOverview extends Page {
     }
 
     @Override
-    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        User u = getUser(req);
-        String pi = req.getPathInfo();
-        if (pi.length() - PATH.length() > 0) {
-            int i = Integer.parseInt(pi.substring(PATH.length()));
-            Domain d = Domain.getById(i);
-            if (u.getId() != d.getOwner().getId()) {
-                return;
-            }
-            int reping = Integer.parseInt(req.getParameter("configId"));
-            DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
-            if (dpc.getTarget() != d) {
-                return;
-            }
-            try {
-                dpc.requestReping();
-            } catch (GigiApiException e) {
-                e.format(resp.getWriter(), getLanguage(req));
-                return;
-            }
-            resp.sendRedirect(PATH + i);
-        }
+    public Form getForm(HttpServletRequest req) throws CSRFException {
         if (req.getParameter("adddomain") != null) {
-            DomainAddForm f = Form.getForm(req, DomainAddForm.class);
-            if (f.submit(resp.getWriter(), req)) {
-                resp.sendRedirect(PATH);
-            }
-        } else if (req.getParameter("domdel") != null) {
-            DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
-            if (f.submit(resp.getWriter(), req)) {
-                resp.sendRedirect(PATH);
-            }
+            return Form.getForm(req, DomainAddForm.class);
+        } else if (req.getParameter("delete") != null) {
+            return Form.getForm(req, DomainManagementForm.class);
         }
-        super.doPost(req, resp);
+        return null;
     }
 }