]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/wot/AssuranceForm.java
fix: assurance form, keep location and date + testCase
[gigi.git] / src / org / cacert / gigi / pages / wot / AssuranceForm.java
index bb378dfb8e3b41bc70e180ea94fac404ffab733e..4b6f9232a3f4f16dfdebae65b3518b823ec74212 100644 (file)
@@ -1,17 +1,18 @@
 package org.cacert.gigi.pages.wot;
 
 import java.io.PrintWriter;
-import java.sql.SQLException;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Name;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
-import org.cacert.gigi.output.Form;
+import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.util.Notary;
@@ -20,14 +21,24 @@ public class AssuranceForm extends Form {
 
     private User assuree;
 
+    private Name assureeName;
+
+    private Date dob;
+
+    private String location = "";
+
+    private String date = "";
+
     private static final Template templ;
     static {
         templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
     }
 
-    public AssuranceForm(HttpServletRequest hsr, int assuree) {
+    public AssuranceForm(HttpServletRequest hsr, User assuree) {
         super(hsr);
-        this.assuree = new User(assuree);
+        this.assuree = assuree;
+        assureeName = this.assuree.getName();
+        dob = this.assuree.getDoB();
     }
 
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -40,18 +51,22 @@ public class AssuranceForm extends Form {
         res.putAll(vars);
         res.put("nameExplicit", assuree.getName());
         res.put("name", assuree.getName().toString());
-        try {
-            res.put("maxpoints", assuree.getMaxAssurePoints());
-        } catch (SQLException e) {
-            e.printStackTrace();
-        }
-        res.put("dob", sdf.format(assuree.getDob()));
-        res.put("dobFmt2", sdf2.format(assuree.getDob()));
+        res.put("maxpoints", assuree.getMaxAssurePoints());
+        res.put("dob", sdf.format(assuree.getDoB()));
+        res.put("dobFmt2", sdf2.format(assuree.getDoB()));
+        res.put("location", location);
+        res.put("date", date);
         templ.output(out, l, res);
     }
 
     @Override
     public boolean submit(PrintWriter out, HttpServletRequest req) {
+        location = req.getParameter("location");
+        date = req.getParameter("date");
+        if (date == null || location == null) {
+            outputError(out, req, "You need to enter location and date!");
+        }
+
         if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
             outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
 
@@ -72,10 +87,8 @@ public class AssuranceForm extends Form {
             return false;
         }
         try {
-            Notary.assure(Page.getUser(req), assuree, pointsI, req.getParameter("location"), req.getParameter("date"));
+            Notary.assure(Page.getUser(req), assuree, assureeName, dob, pointsI, location, req.getParameter("date"));
             return true;
-        } catch (SQLException e) {
-            e.printStackTrace();
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
         }