]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/wot/AssurePage.java
The assurance form outputs errors, but does nothing.
[gigi.git] / src / org / cacert / gigi / pages / wot / AssurePage.java
index 5fae0f8cd042374e86ff5aabe3a9fd86fc0c90c3..a25f55732f316cd831a2f74138756f728e174950 100644 (file)
@@ -10,6 +10,7 @@ import java.util.HashMap;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 
 import org.cacert.gigi.User;
 import org.cacert.gigi.database.DatabaseConnection;
@@ -19,7 +20,8 @@ import org.cacert.gigi.pages.LoginPage;
 import org.cacert.gigi.pages.Page;
 
 public class AssurePage extends Page {
-       public static final String PATH = "/wot/assure/*";
+       public static final String PATH = "/wot/assure";
+       public static final String SESSION = "/wot/assure/FORM";
        DateSelector ds = new DateSelector("day", "month", "year");
        Template t;
 
@@ -32,12 +34,10 @@ public class AssurePage extends Page {
        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {
-               PrintWriter out = resp.getWriter();
 
-               String pi = req.getPathInfo().substring(PATH.length() - 2);
+               PrintWriter out = resp.getWriter();
+               String pi = req.getPathInfo().substring(PATH.length());
                if (pi.length() > 1) {
-                       out.println("I am a Placeholder for the Assurance form # ");
-                       out.println(pi.substring(1));
                        User myself = LoginPage.getUser(req);
                        int mid = Integer.parseInt(pi.substring(1));
                        if (mid == myself.getId()) {
@@ -45,8 +45,14 @@ public class AssurePage extends Page {
                                return;
                        }
 
-                       new AssuranceForm(mid).output(out, getLanguage(req),
-                                       new HashMap<String, Object>());;
+                       HttpSession hs = req.getSession();
+                       AssuranceForm form = (AssuranceForm) hs.getAttribute(SESSION);
+                       if (form == null || form.assuree.getId() != mid) {
+                               form = new AssuranceForm(mid);
+                               hs.setAttribute(SESSION, form);
+                       }
+
+                       form.output(out, getLanguage(req), new HashMap<String, Object>());;
                } else {
                        HashMap<String, Object> vars = new HashMap<String, Object>();
                        vars.put("DoB", ds);
@@ -57,6 +63,19 @@ public class AssurePage extends Page {
        public void doPost(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {
                PrintWriter out = resp.getWriter();
+               String pi = req.getPathInfo().substring(PATH.length());
+               if (pi.length() > 1) {
+                       AssuranceForm form = (AssuranceForm) req.getSession().getAttribute(
+                                       SESSION);
+                       if (form == null) {
+                               out.println("No form found. This is an Error. Fill in the form again.");
+                               return;
+                       }
+                       form.submit(out, req);
+
+                       return;
+               }
+
                System.out.println("searching for");
                try {
                        PreparedStatement ps = DatabaseConnection.getInstance().prepare(
@@ -69,12 +88,19 @@ public class AssurePage extends Page {
                        int id = 0;
                        if (rs.next()) {
                                id = rs.getInt(1);
-                       }
-                       if (rs.next()) {
-                               out.println("Error, ambigous user. Please contact support@cacert.org");
+                               if (rs.next()) {
+                                       out.println("Error, ambigous user. Please contact support@cacert.org.");
+                               } else {
+                                       resp.sendRedirect(PATH + "/" + id);
+                               }
                        } else {
-                               resp.sendRedirect(PATH.substring(0, PATH.length() - 2) + "/"
-                                               + id);
+                               out.print("<div class='formError'>");
+                               out.println(translate(
+                                               req,
+                                               "I'm sorry, there was no email and date of birth matching"
+                                                               + " what you entered in the system. Please double check"
+                                                               + " your information."));
+                               out.print("</div>");
                        }
 
                        rs.close();