From 41277f3156ec60c230d670b7f0b18b5646019522 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Thu, 26 Jun 2014 10:54:29 +0200 Subject: [PATCH] Begin the assurance form --- src/org/cacert/gigi/User.java | 3 +- .../cacert/gigi/pages/wot/AssuranceForm.java | 28 +++++++++++++++++-- .../cacert/gigi/pages/wot/AssuranceForm.templ | 7 +++++ src/org/cacert/gigi/pages/wot/AssurePage.java | 11 ++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/org/cacert/gigi/pages/wot/AssuranceForm.templ diff --git a/src/org/cacert/gigi/User.java b/src/org/cacert/gigi/User.java index bf47552a..055ac838 100644 --- a/src/org/cacert/gigi/User.java +++ b/src/org/cacert/gigi/User.java @@ -22,12 +22,13 @@ public class User { this.id = id; try { PreparedStatement ps = DatabaseConnection.getInstance().prepare( - "SELECT `fname`, `lname` FROM `users` WHERE id=?"); + "SELECT `fname`, `lname`, `dob` FROM `users` WHERE id=?"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); if (rs.next()) { fname = rs.getString(1); lname = rs.getString(2); + dob = rs.getDate(3); } rs.close(); } catch (SQLException e) { diff --git a/src/org/cacert/gigi/pages/wot/AssuranceForm.java b/src/org/cacert/gigi/pages/wot/AssuranceForm.java index 28a1ddfb..809743d6 100644 --- a/src/org/cacert/gigi/pages/wot/AssuranceForm.java +++ b/src/org/cacert/gigi/pages/wot/AssuranceForm.java @@ -1,16 +1,40 @@ package org.cacert.gigi.pages.wot; +import java.io.InputStreamReader; import java.io.PrintWriter; +import java.util.HashMap; import java.util.Map; import org.cacert.gigi.Language; +import org.cacert.gigi.User; import org.cacert.gigi.output.Outputable; +import org.cacert.gigi.output.Template; +import org.cacert.gigi.util.HTMLEncoder; public class AssuranceForm implements Outputable { + User assuree; + static final Template templ; + static { + templ = new Template(new InputStreamReader( + AssuranceForm.class.getResourceAsStream("AssuranceForm.templ"))); + } + + public AssuranceForm(int assuree) { + this.assuree = new User(assuree); + } @Override public void output(PrintWriter out, Language l, Map vars) { - + HashMap res = new HashMap(); + res.putAll(vars); + res.put("fname", HTMLEncoder.encodeHTML(assuree.getFname())); + res.put("mname", + assuree.getMname() == null ? "" : HTMLEncoder + .encodeHTML(assuree.getMname())); + res.put("lname", HTMLEncoder.encodeHTML(assuree.getLname())); + res.put("suffix", + assuree.getSuffix() == null ? "" : HTMLEncoder + .encodeHTML(assuree.getSuffix())); + templ.output(out, l, res); } - } diff --git a/src/org/cacert/gigi/pages/wot/AssuranceForm.templ b/src/org/cacert/gigi/pages/wot/AssuranceForm.templ new file mode 100644 index 00000000..e0c6ed41 --- /dev/null +++ b/src/org/cacert/gigi/pages/wot/AssuranceForm.templ @@ -0,0 +1,7 @@ +
+ + + +
+
+
\ No newline at end of file diff --git a/src/org/cacert/gigi/pages/wot/AssurePage.java b/src/org/cacert/gigi/pages/wot/AssurePage.java index 6c5622b7..5fae0f8c 100644 --- a/src/org/cacert/gigi/pages/wot/AssurePage.java +++ b/src/org/cacert/gigi/pages/wot/AssurePage.java @@ -11,9 +11,11 @@ import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.cacert.gigi.User; import org.cacert.gigi.database.DatabaseConnection; import org.cacert.gigi.output.DateSelector; import org.cacert.gigi.output.Template; +import org.cacert.gigi.pages.LoginPage; import org.cacert.gigi.pages.Page; public class AssurePage extends Page { @@ -36,6 +38,15 @@ public class AssurePage extends Page { 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()) { + out.println("Cannot assure myself."); + return; + } + + new AssuranceForm(mid).output(out, getLanguage(req), + new HashMap());; } else { HashMap vars = new HashMap(); vars.put("DoB", ds); -- 2.39.2