]> WPIA git - gigi.git/blobdiff - src/club/wpia/gigi/pages/main/RegisterPage.java
upd: rename package name and all references to it
[gigi.git] / src / club / wpia / gigi / pages / main / RegisterPage.java
diff --git a/src/club/wpia/gigi/pages/main/RegisterPage.java b/src/club/wpia/gigi/pages/main/RegisterPage.java
new file mode 100644 (file)
index 0000000..74f9107
--- /dev/null
@@ -0,0 +1,58 @@
+package club.wpia.gigi.pages.main;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import club.wpia.gigi.output.template.Form;
+import club.wpia.gigi.pages.Page;
+import club.wpia.gigi.util.AuthorizationContext;
+import club.wpia.gigi.util.RateLimit;
+
+public class RegisterPage extends Page {
+
+    public static final String PATH = "/register";
+
+    // 50 per 5 min
+    public static final RateLimit RATE_LIMIT = new RateLimit(50, 5 * 60 * 1000);
+
+    public RegisterPage() {
+        super("Register");
+    }
+
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        Signup s = new Signup(req);
+        outputGet(req, resp, s);
+    }
+
+    private void outputGet(HttpServletRequest req, HttpServletResponse resp, Signup s) throws IOException {
+        getDefaultTemplate().output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+        s.output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+    }
+
+    @Override
+    public boolean beforePost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        return Form.getForm(req, Signup.class).submitExceptionProtected(req, resp);
+    }
+
+    @Override
+    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        if (Form.printFormErrors(req, resp.getWriter())) {
+            Signup s = Form.getForm(req, Signup.class);
+            outputGet(req, resp, s);
+        }
+    }
+
+    @Override
+    public boolean needsLogin() {
+        return false;
+    }
+
+    @Override
+    public boolean isPermitted(AuthorizationContext ac) {
+        return ac == null;
+    }
+}