X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Fmain%2FRegisterPage.java;h=4bc2cd957fa9b7d6e0e0c88cffbf0392cc5bba09;hb=07f74d10bddc819f4524e2e0c1a2815eb4e7ec79;hp=b80429fb72ff753c89a782172fb08c3c803f0dc4;hpb=45b1bef0919f9115f74b5b232e8fda4c787ba03d;p=gigi.git diff --git a/src/org/cacert/gigi/pages/main/RegisterPage.java b/src/org/cacert/gigi/pages/main/RegisterPage.java index b80429fb..4bc2cd95 100644 --- a/src/org/cacert/gigi/pages/main/RegisterPage.java +++ b/src/org/cacert/gigi/pages/main/RegisterPage.java @@ -8,48 +8,59 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.cacert.gigi.output.Form; +import org.cacert.gigi.output.template.Form; import org.cacert.gigi.pages.Page; +import org.cacert.gigi.util.AuthorizationContext; +import org.cacert.gigi.util.RateLimit; public class RegisterPage extends Page { - private static final String SIGNUP_PROCESS = "signupProcess"; - public static final String PATH = "/register"; - - public RegisterPage() { - super("Register"); - } - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - PrintWriter out = resp.getWriter(); - HashMap vars = new HashMap(); - getDefaultTemplate().output(out, getLanguage(req), vars); - Signup s = new Signup(req); - s.output(out, getLanguage(req), vars); - } - - @Override - public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { - Signup s = Form.getForm(req, Signup.class); - if (s == null) { - resp.getWriter().println(translate(req, "CSRF token check failed.")); - } else if (s.submit(resp.getWriter(), req)) { - HttpSession hs = req.getSession(); - hs.setAttribute(SIGNUP_PROCESS, null); - resp.getWriter().println( - translate(req, "Your information has been submitted" - + " into our system. You will now be sent an email with a web link," - + " you need to open that link in your web browser within 24 hours" - + " or your information will be removed from our system!")); - return; - } - - super.doPost(req, resp); - } - - @Override - public boolean needsLogin() { - return false; - } + private static final String SIGNUP_PROCESS = "signupProcess"; + + public static final String PATH = "/register"; + + // 5 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 { + PrintWriter out = resp.getWriter(); + HashMap vars = new HashMap(); + getDefaultTemplate().output(out, getLanguage(req), vars); + s.output(out, getLanguage(req), vars); + } + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + Signup s = Form.getForm(req, Signup.class); + if (s == null) { + resp.getWriter().println(translate(req, "CSRF token check failed.")); + } else if (s.submit(resp.getWriter(), req)) { + HttpSession hs = req.getSession(); + hs.setAttribute(SIGNUP_PROCESS, null); + resp.getWriter().println(translate(req, "Your information has been submitted" + " into our system. You will now be sent an email with a web link," + " you need to open that link in your web browser within 24 hours" + " or your information will be removed from our system!")); + return; + } + + outputGet(req, resp, s); + } + + @Override + public boolean needsLogin() { + return false; + } + + @Override + public boolean isPermitted(AuthorizationContext ac) { + return ac == null; + } }