]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/main/RegisterPage.java
Move the "dbObject"s to their own package.
[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.dbObjects.User;
12 import org.cacert.gigi.output.Form;
13 import org.cacert.gigi.pages.Page;
14
15 public class RegisterPage extends Page {
16
17     private static final String SIGNUP_PROCESS = "signupProcess";
18
19     public static final String PATH = "/register";
20
21     public RegisterPage() {
22         super("Register");
23     }
24
25     @Override
26     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
27         Signup s = new Signup(req);
28         outputGet(req, resp, s);
29     }
30
31     private void outputGet(HttpServletRequest req, HttpServletResponse resp, Signup s) throws IOException {
32         PrintWriter out = resp.getWriter();
33         HashMap<String, Object> vars = new HashMap<String, Object>();
34         getDefaultTemplate().output(out, getLanguage(req), vars);
35         s.output(out, getLanguage(req), vars);
36     }
37
38     @Override
39     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
40         Signup s = Form.getForm(req, Signup.class);
41         if (s == null) {
42             resp.getWriter().println(translate(req, "CSRF token check failed."));
43         } else if (s.submit(resp.getWriter(), req)) {
44             HttpSession hs = req.getSession();
45             hs.setAttribute(SIGNUP_PROCESS, null);
46             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!"));
47             return;
48         }
49
50         outputGet(req, resp, s);
51     }
52
53     @Override
54     public boolean needsLogin() {
55         return false;
56     }
57
58     @Override
59     public boolean isPermitted(User u) {
60         return u == null;
61     }
62 }