]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/admin/support/FindUserByEmailPage.java
upd: enforce a more strict Form call pattern.
[gigi.git] / src / org / cacert / gigi / pages / admin / support / FindUserByEmailPage.java
index 42d9e8d00ec6826df87a610885fe388f03003d2b..9d731712cb9df146018f48ba14c293ba0b8d23a3 100644 (file)
@@ -7,11 +7,11 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.EmailAddress;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.IterableDataset;
+import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.util.AuthorizationContext;
 
@@ -19,28 +19,32 @@ public class FindUserByEmailPage extends Page {
 
     public static final String PATH = "/support/find/email";
 
+    private static final Template USERTABLE = new Template(FindUserByDomainPage.class.getResource("FindUserByEmailUsertable.templ"));
+
     public FindUserByEmailPage() {
         super("Find Email");
     }
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        HashMap<String, Object> vars = new HashMap<String, Object>();
-        vars.put("first", true);
-        new FindUserByEmailForm(req).output(resp.getWriter(), Page.getLanguage(req), vars);
+        new FindUserByEmailForm(req).output(resp.getWriter(), Page.getLanguage(req), new HashMap<String, Object>());
+    }
+
+    @Override
+    public boolean beforePost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        return Form.getForm(req, FindUserByEmailForm.class).submitExceptionProtected(req, resp);
     }
 
     @Override
     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        FindUserByEmailForm form = Form.getForm(req, FindUserByEmailForm.class);
-        try {
-            form.submit(resp.getWriter(), req);
-            final EmailAddress[] emails = form.getEmails();
+        if (Form.printFormErrors(req, resp.getWriter())) {
+            Form.getForm(req, FindUserByEmailForm.class).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+        } else {
+            final EmailAddress[] emails = ((FindUserByEmailForm.FindEmailResult) req.getAttribute(Form.SUBMIT_RESULT)).getEmails();
             if (emails.length == 1) {
-                resp.sendRedirect(SupportUserDetailsPage.PATH + emails[0].getOwner().getId());
+                resp.sendRedirect(SupportUserDetailsPage.PATH + emails[0].getOwner().getId() + "/");
             } else {
                 HashMap<String, Object> vars = new HashMap<String, Object>();
-                vars.put("first", false);
                 vars.put("usertable", new IterableDataset() {
 
                     int i = 0;
@@ -56,11 +60,8 @@ public class FindUserByEmailPage extends Page {
                         return true;
                     }
                 });
-                form.output(resp.getWriter(), getLanguage(req), vars);
+                USERTABLE.output(resp.getWriter(), getLanguage(req), vars);
             }
-        } catch (GigiApiException e) {
-            e.format(resp.getWriter(), Page.getLanguage(req));
-            doGet(req, resp);
         }
     }