]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/account/MyDetailsForm.java
upd: enforce a more strict Form call pattern.
[gigi.git] / src / org / cacert / gigi / pages / account / MyDetailsForm.java
index 813902289e623f925e5b89c2d9dad7ef10123169..f5b6f514fc6c3c9eca77816f5ab00a8b1d1eeefe 100644 (file)
@@ -19,7 +19,6 @@ import org.cacert.gigi.output.GroupSelector;
 import org.cacert.gigi.output.NameInput;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.Template;
-import org.cacert.gigi.pages.Page;
 
 public class MyDetailsForm extends Form {
 
@@ -56,7 +55,7 @@ public class MyDetailsForm extends Form {
     }
 
     @Override
-    public boolean submit(PrintWriter out, HttpServletRequest req) {
+    public SubmissionResult submit(HttpServletRequest req) throws GigiApiException {
         try {
             String rn = req.getParameter("removeName");
             if (rn != null) {
@@ -68,7 +67,7 @@ public class MyDetailsForm extends Form {
                     throw new GigiApiException("Cannot remove the account's preferred name.");
                 }
                 n.remove();
-                return true;
+                return new RedirectResult(MyDetails.PATH);
             }
             String dn = req.getParameter("deprecateName");
             if (dn != null) {
@@ -80,31 +79,29 @@ public class MyDetailsForm extends Form {
                     throw new GigiApiException("Cannot deprecate the account's preferred name.");
                 }
                 n.deprecate();
-                return true;
+                return new RedirectResult(MyDetails.PATH);
             }
             String pn = req.getParameter("preferred");
             if (pn != null) {
                 Name n = Name.getById(Integer.parseInt(pn));
                 target.setPreferredName(n);
-                return true;
+                return new RedirectResult(MyDetails.PATH);
             }
 
             String action = req.getParameter("action");
             if ("addName".equals(action)) {
                 ni.update(req);
                 ni.createName(target);
-                return true;
-            }
-            if ("updateDoB".equals(action)) {
+                return new RedirectResult(MyDetails.PATH);
+            } else if ("updateDoB".equals(action)) {
                 ds.update(req);
                 target.setDoB(ds.getDate());
-            }
-            if ("updateResidenceCountry".equals(action)) {
+                return new RedirectResult(MyDetails.PATH);
+            } else if ("updateResidenceCountry".equals(action)) {
                 cs.update(req);
                 target.setResidenceCountry(cs.getCountry());
-            }
-
-            if ("addGroup".equals(action) || "removeGroup".equals(action)) {
+                return new RedirectResult(MyDetails.PATH);
+            } else if ("addGroup".equals(action) || "removeGroup".equals(action)) {
                 selectedGroup.update(req);
                 Group toMod = selectedGroup.getGroup();
                 if ("addGroup".equals(action)) {
@@ -112,17 +109,14 @@ public class MyDetailsForm extends Form {
                 } else {
                     target.revokeGroup(target, toMod);
                 }
-                return true;
+                return new RedirectResult(MyDetails.PATH);
+            } else {
+                throw new GigiApiException("Invalid action.");
             }
 
-        } catch (GigiApiException e) {
-            e.format(out, Page.getLanguage(req));
-            return false;
         } catch (NumberFormatException e) {
-            new GigiApiException("Invalid value.").format(out, Page.getLanguage(req));
-            return false;
+            throw new GigiApiException("Invalid value.");
         }
-        return false;
     }
 
     @Override