Factor out name handling.
authorFelix Dörre <felix@dogcraft.de>
Thu, 26 Jun 2014 10:31:28 +0000 (12:31 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 26 Jun 2014 10:31:28 +0000 (12:31 +0200)
src/org/cacert/gigi/Name.java [new file with mode: 0644]
src/org/cacert/gigi/User.java
src/org/cacert/gigi/pages/wot/AssuranceForm.java
src/org/cacert/gigi/pages/wot/AssuranceForm.templ
static/default.css

diff --git a/src/org/cacert/gigi/Name.java b/src/org/cacert/gigi/Name.java
new file mode 100644 (file)
index 0000000..4e74895
--- /dev/null
@@ -0,0 +1,30 @@
+package org.cacert.gigi;
+
+import java.io.PrintWriter;
+import java.util.Map;
+
+import org.cacert.gigi.output.Outputable;
+
+public class Name implements Outputable {
+       String fname;
+       String mname;
+       String lname;
+       String suffix;
+
+       public Name(String fname, String lname) {
+               this.fname = fname;
+               this.lname = lname;
+       }
+
+       @Override
+       public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+               out.println("<span class=\"accountdetail\">");
+               out.print("<span class=\"fname\">");
+               out.print(fname);
+               out.print("</span> ");
+               out.print("<span class=\"lname\">");
+               out.print(lname);
+               out.print("</span>");
+               out.println("</span>");
+       }
+}
index 055ac8384fe376e65771e5aaff1a8d52459beec4..e03c55fec2ec75be192bcc9d564bbfa91c4e0f49 100644 (file)
@@ -11,10 +11,8 @@ import org.cacert.gigi.util.PasswordHash;
 public class User {
 
        private int id;
-       String fname;
-       String mname;
-       String lname;
-       String suffix;
+       Name name;
+
        Date dob;
        String email;
 
@@ -26,8 +24,7 @@ public class User {
                        ps.setInt(1, id);
                        ResultSet rs = ps.executeQuery();
                        if (rs.next()) {
-                               fname = rs.getString(1);
-                               lname = rs.getString(2);
+                               name = new Name(rs.getString(1), rs.getString(2));
                                dob = rs.getDate(3);
                        }
                        rs.close();
@@ -41,22 +38,25 @@ public class User {
                return id;
        }
        public String getFname() {
-               return fname;
+               return name.fname;
        }
        public String getLname() {
-               return lname;
+               return name.lname;
        }
        public String getMname() {
-               return mname;
+               return name.mname;
+       }
+       public Name getName() {
+               return name;
        }
        public void setMname(String mname) {
-               this.mname = mname;
+               this.name.mname = mname;
        }
        public String getSuffix() {
-               return suffix;
+               return name.suffix;
        }
        public void setSuffix(String suffix) {
-               this.suffix = suffix;
+               this.name.suffix = suffix;
        }
        public Date getDob() {
                return dob;
@@ -74,10 +74,10 @@ public class User {
                this.id = id;
        }
        public void setFname(String fname) {
-               this.fname = fname;
+               this.name.fname = fname;
        }
        public void setLname(String lname) {
-               this.lname = lname;
+               this.name.lname = lname;
        }
        public void insert(String password) throws SQLException {
                if (id != 0) {
@@ -89,10 +89,10 @@ public class User {
                                                + "`suffix`=?, `dob`=?, `created`=NOW(), locked=0");
                query.setString(1, email);
                query.setString(2, PasswordHash.hash(password));
-               query.setString(3, fname);
-               query.setString(4, mname);
-               query.setString(5, lname);
-               query.setString(6, suffix);
+               query.setString(3, name.fname);
+               query.setString(4, name.mname);
+               query.setString(5, name.lname);
+               query.setString(6, name.suffix);
                query.setDate(7, new java.sql.Date(dob.getTime()));
                query.execute();
                id = DatabaseConnection.lastInsertId(query);
index 809743d61b5d7b38f392b2fa398fbb44a20f7060..9f8739566d135c7fa6b4652add15bb33f1124820 100644 (file)
@@ -9,7 +9,6 @@ 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;
@@ -27,14 +26,7 @@ public class AssuranceForm implements Outputable {
        public void output(PrintWriter out, Language l, Map<String, Object> vars) {
                HashMap<String, Object> res = new HashMap<String, Object>();
                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()));
+               res.put("name", assuree.getName());
                templ.output(out, l, res);
        }
 }
index b278125a757d9512368916dd3680c7cea9eba8f9..a76bad069b6247a427c2c4c07a711b9796ee5673 100644 (file)
@@ -1,12 +1,12 @@
 <form method="POST">\r
 <table class="wrapper" width="600">\r
 <tr><td colspan="2" class="title"><?=_Assurance Confirmation?></td></tr>\r
-<tr><td colspan="2" class="DataTD"><?=s,$fname,$mname,$lname,$suffix,Please check the following details match against what you witnessed when you met %s %s %s %s in person. You MUST NOT proceed unless you are sure the details are correct. You may be held responsible by the CAcert Arbitrator for any issues with this Assurance.?>\r
+<tr><td colspan="2" class="DataTD"><?=s,$name,Please check the following details match against what you witnessed when you met %s in person. You MUST NOT proceed unless you are sure the details are correct. You may be held responsible by the CAcert Arbitrator for any issues with this Assurance.?>\r
 </td></tr>\r
 \r
        <tr>\r
                <td class="DataTD"><?=_Name?>: </td>\r
-               <td class="DataTD"><span class="accountdetail"><?=$fname?> <?=$mname?> <?=$lname?> <?=$suffix?></span></td>\r
+               <td class="DataTD"><span class="accountdetail"><?=$name?></span></td>\r
        </tr>\r
        <tr>\r
                <td class="DataTD"><?=_Date of Birth?>: </td>\r
index 5c50fc8ae1986846fd011656f0d10379f7a0fd20..c30b848f7d1e442f69b9778c7b1e8c61b3140941 100644 (file)
@@ -717,13 +717,13 @@ div.footerbar {
        font-size: 1.1em;
 }
 
-.accountdetail.fname {
+.accountdetail.fname, .accountdetail .fname {
 }
 
 .accountdetail.mname {
 }
 
-.accountdetail.lname {
+.accountdetail.lname, .accountdetail .lname {
        font-weight: bold;
 }