1 package org.cacert.gigi.pages.wot;
3 import java.io.PrintWriter;
4 import java.sql.SQLException;
5 import java.text.SimpleDateFormat;
7 import java.util.HashMap;
10 import javax.servlet.http.HttpServletRequest;
12 import org.cacert.gigi.GigiApiException;
13 import org.cacert.gigi.dbObjects.Name;
14 import org.cacert.gigi.dbObjects.User;
15 import org.cacert.gigi.localisation.Language;
16 import org.cacert.gigi.output.Form;
17 import org.cacert.gigi.output.template.Template;
18 import org.cacert.gigi.pages.Page;
19 import org.cacert.gigi.util.Notary;
21 public class AssuranceForm extends Form {
25 private Name assureeName;
29 private static final Template templ;
31 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
34 public AssuranceForm(HttpServletRequest hsr, User assuree) {
36 this.assuree = assuree;
37 assureeName = this.assuree.getName();
38 dob = this.assuree.getDob();
41 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
43 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
46 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
47 HashMap<String, Object> res = new HashMap<String, Object>();
49 res.put("nameExplicit", assuree.getName());
50 res.put("name", assuree.getName().toString());
52 res.put("maxpoints", assuree.getMaxAssurePoints());
53 } catch (SQLException e) {
56 res.put("dob", sdf.format(assuree.getDob()));
57 res.put("dobFmt2", sdf2.format(assuree.getDob()));
58 templ.output(out, l, res);
62 public boolean submit(PrintWriter out, HttpServletRequest req) {
63 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
64 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
68 String points = req.getParameter("points");
69 if (points == null || "".equals(points)) {
70 outputError(out, req, "For an assurance, you need to enter points.");
73 pointsI = Integer.parseInt(points);
74 } catch (NumberFormatException e) {
75 outputError(out, req, "The points entered were not a number.");
83 Notary.assure(Page.getUser(req), assuree, assureeName, dob, pointsI, req.getParameter("location"), req.getParameter("date"));
85 } catch (SQLException e) {
87 } catch (GigiApiException e) {
88 e.format(out, Page.getLanguage(req));
94 public User getAssuree() {