]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/main/RegisterPage.java
Fix test for csrf.
[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.Form;
12 import org.cacert.gigi.pages.Page;
13
14 public class RegisterPage extends Page {
15
16         private static final String SIGNUP_PROCESS = "signupProcess";
17         public static final String PATH = "/register";
18
19         public RegisterPage() {
20                 super("Register");
21         }
22
23         @Override
24         public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
25                 Signup s = new Signup(req);
26                 outputGet(req, resp, s);
27         }
28
29         private void outputGet(HttpServletRequest req, HttpServletResponse resp, Signup s) throws IOException {
30                 PrintWriter out = resp.getWriter();
31                 HashMap<String, Object> vars = new HashMap<String, Object>();
32                 getDefaultTemplate().output(out, getLanguage(req), vars);
33                 s.output(out, getLanguage(req), vars);
34         }
35
36         @Override
37         public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
38                 Signup s = Form.getForm(req, Signup.class);
39                 if (s == null) {
40                         resp.getWriter().println(translate(req, "CSRF token check failed."));
41                 } else if (s.submit(resp.getWriter(), req)) {
42                         HttpSession hs = req.getSession();
43                         hs.setAttribute(SIGNUP_PROCESS, null);
44                         resp.getWriter().println(
45                                 translate(req, "Your information has been submitted"
46                                         + " into our system. You will now be sent an email with a web link,"
47                                         + " you need to open that link in your web browser within 24 hours"
48                                         + " or your information will be removed from our system!"));
49                         return;
50                 }
51
52                 outputGet(req, resp, s);
53         }
54
55         @Override
56         public boolean needsLogin() {
57                 return false;
58         }
59 }