]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/main/RegisterPage.java
Merge "Update notes about password security"
[gigi.git] / src / org / cacert / gigi / pages / main / RegisterPage.java
1 package org.cacert.gigi.pages.main;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.HashMap;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9 import javax.servlet.http.HttpSession;
10
11 import org.cacert.gigi.output.template.Form;
12 import org.cacert.gigi.pages.Page;
13 import org.cacert.gigi.util.AuthorizationContext;
14 import org.cacert.gigi.util.RateLimit;
15
16 public class RegisterPage extends Page {
17
18     private static final String SIGNUP_PROCESS = "signupProcess";
19
20     public static final String PATH = "/register";
21
22     // 50 per 5 min
23     public static final RateLimit RATE_LIMIT = new RateLimit(50, 5 * 60 * 1000);
24
25     public RegisterPage() {
26         super("Register");
27     }
28
29     @Override
30     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
31         Signup s = new Signup(req);
32         outputGet(req, resp, s);
33     }
34
35     private void outputGet(HttpServletRequest req, HttpServletResponse resp, Signup s) throws IOException {
36         PrintWriter out = resp.getWriter();
37         HashMap<String, Object> vars = new HashMap<String, Object>();
38         getDefaultTemplate().output(out, getLanguage(req), vars);
39         s.output(out, getLanguage(req), vars);
40     }
41
42     @Override
43     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
44         Signup s = Form.getForm(req, Signup.class);
45         if (s == null) {
46             resp.getWriter().println(translate(req, "CSRF token check failed."));
47         } else if (s.submit(resp.getWriter(), req)) {
48             HttpSession hs = req.getSession();
49             hs.setAttribute(SIGNUP_PROCESS, null);
50             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!"));
51             return;
52         }
53
54         outputGet(req, resp, s);
55     }
56
57     @Override
58     public boolean needsLogin() {
59         return false;
60     }
61
62     @Override
63     public boolean isPermitted(AuthorizationContext ac) {
64         return ac == null;
65     }
66 }