X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Fmain%2FRegisterPage.java;h=1e6b33783ee3b89c47c3e602cb90b0196bb949a8;hp=f552189f7ff27e827bc91ca863d045925c5109d8;hb=d23d7a6fa9dc38c6193fea70017e0bff11257be5;hpb=391351cfb8554b94fd38b3b404f34f7e3916f8f5 diff --git a/src/org/cacert/gigi/pages/main/RegisterPage.java b/src/org/cacert/gigi/pages/main/RegisterPage.java index f552189f..1e6b3378 100644 --- a/src/org/cacert/gigi/pages/main/RegisterPage.java +++ b/src/org/cacert/gigi/pages/main/RegisterPage.java @@ -8,58 +8,59 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +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"; + private static final String SIGNUP_PROCESS = "signupProcess"; - public RegisterPage() { - super("Register"); - } + public static final String PATH = "/register"; - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) - throws IOException { - PrintWriter out = resp.getWriter(); - getDefaultTemplate().output(out, getLanguage(req), - new HashMap()); - Signup s = getForm(req); - s.writeForm(out, getLanguage(req)); - } - public Signup getForm(HttpServletRequest req) { - HttpSession hs = req.getSession(); - Signup s = (Signup) hs.getAttribute(SIGNUP_PROCESS); - if (s == null) { - s = new Signup(); - hs.setAttribute(SIGNUP_PROCESS, s); - } - return s; + // 50 per 5 min + public static final RateLimit RATE_LIMIT = new RateLimit(50, 5 * 60 * 1000); - } - @Override - public void doPost(HttpServletRequest req, HttpServletResponse resp) - throws IOException { - Signup s = getForm(req); - 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; - } + public RegisterPage() { + super("Register"); + } - super.doPost(req, resp); - } - @Override - public boolean needsLogin() { - return false; - } + @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; + } }