]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/main/RegisterPage.java
30c428333702991664e451aa3dc6b9b9452d32d7
[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.GigiApiException;
12 import org.cacert.gigi.output.template.Form;
13 import org.cacert.gigi.pages.Page;
14 import org.cacert.gigi.util.AuthorizationContext;
15 import org.cacert.gigi.util.RateLimit;
16
17 public class RegisterPage extends Page {
18
19     private static final String SIGNUP_PROCESS = "signupProcess";
20
21     public static final String PATH = "/register";
22
23     // 50 per 5 min
24     public static final RateLimit RATE_LIMIT = new RateLimit(50, 5 * 60 * 1000);
25
26     public RegisterPage() {
27         super("Register");
28     }
29
30     @Override
31     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32         Signup s = new Signup(req);
33         outputGet(req, resp, s);
34     }
35
36     private void outputGet(HttpServletRequest req, HttpServletResponse resp, Signup s) throws IOException {
37         PrintWriter out = resp.getWriter();
38         HashMap<String, Object> vars = new HashMap<String, Object>();
39         getDefaultTemplate().output(out, getLanguage(req), vars);
40         s.output(out, getLanguage(req), vars);
41     }
42
43     @Override
44     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
45         Signup s = Form.getForm(req, Signup.class);
46         try {
47             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         } catch (GigiApiException e) {
54             e.format(resp.getWriter(), getLanguage(req));
55         }
56
57         outputGet(req, resp, s);
58     }
59
60     @Override
61     public boolean needsLogin() {
62         return false;
63     }
64
65     @Override
66     public boolean isPermitted(AuthorizationContext ac) {
67         return ac == null;
68     }
69 }