]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/main/RegisterPage.java
Add "register completed" page
[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.InputStreamReader;
5 import java.io.PrintWriter;
6 import java.io.UnsupportedEncodingException;
7 import java.util.HashMap;
8
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 import javax.servlet.http.HttpSession;
12
13 import org.cacert.gigi.output.Template;
14 import org.cacert.gigi.pages.Page;
15
16 public class RegisterPage extends Page {
17
18         private static final String SIGNUP_PROCESS = "signupProcess";
19         public static final String PATH = "/register";
20         Template t;
21
22         public RegisterPage() {
23                 super("Register");
24                 try {
25                         t = new Template(new InputStreamReader(
26                                         Signup.class.getResourceAsStream("RegisterPage.templ"),
27                                         "UTF-8"));
28                 } catch (UnsupportedEncodingException e) {
29                         e.printStackTrace();
30                 }
31         }
32
33         @Override
34         public void doGet(HttpServletRequest req, HttpServletResponse resp)
35                         throws IOException {
36                 PrintWriter out = resp.getWriter();
37                 t.output(out, getLanguage(req), new HashMap<String, Object>());
38                 Signup s = getForm(req);
39                 s.writeForm(out, getLanguage(req));
40         }
41         public Signup getForm(HttpServletRequest req) {
42                 HttpSession hs = req.getSession();
43                 Signup s = (Signup) hs.getAttribute(SIGNUP_PROCESS);
44                 if (s == null) {
45                         s = new Signup();
46                         hs.setAttribute(SIGNUP_PROCESS, s);
47                 }
48                 return s;
49
50         }
51         @Override
52         public void doPost(HttpServletRequest req, HttpServletResponse resp)
53                         throws IOException {
54                 Signup s = getForm(req);
55                 if (s.submit(resp.getWriter(), req)) {
56                         HttpSession hs = req.getSession();
57                         hs.setAttribute(SIGNUP_PROCESS, null);
58                         resp.getWriter()
59                                         .println(
60                                                         translate(
61                                                                         req,
62                                                                         "Your information has been submitted"
63                                                                                         + " into our system. You will now be sent an email with a web link,"
64                                                                                         + " you need to open that link in your web browser within 24 hours"
65                                                                                         + " or your information will be removed from our system!"));
66                         return;
67                 }
68
69                 super.doPost(req, resp);
70         }
71         @Override
72         public boolean needsLogin() {
73                 return false;
74         }
75 }