1 package org.cacert.gigi.pages.wot;
3 import java.io.PrintWriter;
4 import java.sql.SQLException;
5 import java.text.SimpleDateFormat;
6 import java.util.HashMap;
9 import javax.servlet.http.HttpServletRequest;
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.User;
13 import org.cacert.gigi.localisation.Language;
14 import org.cacert.gigi.output.Form;
15 import org.cacert.gigi.output.template.Template;
16 import org.cacert.gigi.pages.Page;
17 import org.cacert.gigi.util.Notary;
19 public class AssuranceForm extends Form {
23 private static final Template templ;
25 templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ"));
28 public AssuranceForm(HttpServletRequest hsr, int assuree) {
30 this.assuree = new User(assuree);
33 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
35 SimpleDateFormat sdf2 = new SimpleDateFormat("dd. MMM yyyy");
38 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
39 HashMap<String, Object> res = new HashMap<String, Object>();
41 res.put("nameExplicit", assuree.getName());
42 res.put("name", assuree.getName().toString());
44 res.put("maxpoints", assuree.getMaxAssurePoints());
45 } catch (SQLException e) {
48 res.put("dob", sdf.format(assuree.getDob()));
49 res.put("dobFmt2", sdf2.format(assuree.getDob()));
50 templ.output(out, l, res);
54 public boolean submit(PrintWriter out, HttpServletRequest req) {
55 if ( !"1".equals(req.getParameter("certify")) || !"1".equals(req.getParameter("rules")) || !"1".equals(req.getParameter("CCAAgreed")) || !"1".equals(req.getParameter("assertion"))) {
56 outputError(out, req, "You failed to check all boxes to validate" + " your adherence to the rules and policies of CAcert");
60 String points = req.getParameter("points");
61 if (points == null || "".equals(points)) {
62 outputError(out, req, "For an assurance, you need to enter points.");
65 pointsI = Integer.parseInt(points);
66 } catch (NumberFormatException e) {
67 outputError(out, req, "The points entered were not a number.");
75 Notary.assure(Page.getUser(req), assuree, pointsI, req.getParameter("location"), req.getParameter("date"));
77 } catch (SQLException e) {
79 } catch (GigiApiException e) {
80 e.format(out, Page.getLanguage(req));
86 public User getAssuree() {