From: Felix Dörre Date: Fri, 27 Jun 2014 12:52:01 +0000 (+0200) Subject: The assurance form outputs errors, but does nothing. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=b207830cd86cf9c0459ab074ef050380d6d9f598;hp=f8808e481a30a36b3bf8dc269c6ac7a30639ea79 The assurance form outputs errors, but does nothing. --- diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index a96396db..754fe3a0 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -48,7 +48,7 @@ public class Gigi extends HttpServlet { pages.put("/", new MainPage("CACert - Home")); pages.put("/secure", new TestSecure()); pages.put(Verify.PATH, new Verify()); - pages.put(AssurePage.PATH, new AssurePage()); + pages.put(AssurePage.PATH + "/*", new AssurePage()); pages.put(MailCertificates.PATH, new MailCertificates()); pages.put(MyDetails.PATH, new MyDetails()); pages.put(RegisterPage.PATH, new RegisterPage()); diff --git a/src/org/cacert/gigi/pages/wot/AssuranceForm.java b/src/org/cacert/gigi/pages/wot/AssuranceForm.java index 5240fc4c..d4d7f84b 100644 --- a/src/org/cacert/gigi/pages/wot/AssuranceForm.java +++ b/src/org/cacert/gigi/pages/wot/AssuranceForm.java @@ -2,6 +2,9 @@ package org.cacert.gigi.pages.wot; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -31,13 +34,58 @@ public class AssuranceForm extends Form { res.put("name", assuree.getName()); templ.output(out, l, res); } + SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd"); @Override public boolean submit(PrintWriter out, HttpServletRequest req) { - if (!"1".equals(req.getAttribute("certify"))) { - // s + out.println("
"); + boolean failed = false; + 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"); + failed = true; + + } + if (req.getParameter("date") == null + || req.getParameter("date").equals("")) { + outputError(out, req, + "You must enter the date when you met the assuree."); + failed = true; + } else { + try { + Date d = sdf.parse(req.getParameter("date")); + if (d.getTime() > System.currentTimeMillis()) { + outputError(out, req, + "You must not enter a date in the future."); + failed = true; + } + } catch (ParseException e) { + outputError(out, req, + "You must enter the date in this format: YYYY-MM-DD."); + failed = true; + } + } + // check location, min 3 characters + if (req.getParameter("location") == null + || req.getParameter("location").equals("")) { + outputError(out, req, + "You failed to enter a location of your meeting."); + failed = true; + } else if (req.getParameter("location").length() <= 2) { + outputError(out, req, + "You must enter a location with at least 3 characters eg town and country."); + failed = true; } + // TODO checkPoints + out.println("
"); + if (failed) { + return false; + } + return false; } } diff --git a/src/org/cacert/gigi/pages/wot/AssurePage.java b/src/org/cacert/gigi/pages/wot/AssurePage.java index 1ff8410c..a25f5573 100644 --- a/src/org/cacert/gigi/pages/wot/AssurePage.java +++ b/src/org/cacert/gigi/pages/wot/AssurePage.java @@ -20,7 +20,7 @@ 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; @@ -36,7 +36,7 @@ public class AssurePage extends Page { throws IOException { PrintWriter out = resp.getWriter(); - String pi = req.getPathInfo().substring(PATH.length() - 2); + String pi = req.getPathInfo().substring(PATH.length()); if (pi.length() > 1) { User myself = LoginPage.getUser(req); int mid = Integer.parseInt(pi.substring(1)); @@ -63,12 +63,13 @@ 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() - 2); + 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); @@ -87,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("
"); + 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("
"); } rs.close();