]> WPIA git - gigi.git/commitdiff
upd: Beautify up the verification form.
authorFelix Dörre <felix@dogcraft.de>
Sun, 15 Mar 2015 08:53:44 +0000 (09:53 +0100)
committerFelix Dörre <felix@dogcraft.de>
Sun, 15 Mar 2015 08:55:21 +0000 (09:55 +0100)
src/org/cacert/gigi/dbObjects/Domain.java
src/org/cacert/gigi/dbObjects/EmailAddress.java
src/org/cacert/gigi/dbObjects/Verifyable.java [new file with mode: 0644]
src/org/cacert/gigi/pages/Verify.java
src/org/cacert/gigi/pages/Verify.templ

index 9df2e4822c7f33eae8cc8f1003011e8a44078c4e..00f51c1fe87df68cf050dd3020c49bbc7e245f9f 100644 (file)
@@ -18,7 +18,7 @@ import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
 import org.cacert.gigi.util.PublicSuffixes;
 
-public class Domain implements IdCachable {
+public class Domain implements IdCachable, Verifyable {
 
     public class DomainPingExecution {
 
@@ -233,7 +233,7 @@ public class Domain implements IdCachable {
         configs = null;
     }
 
-    public void verify(String hash) throws GigiApiException {
+    public synchronized void verify(String hash) throws GigiApiException {
         GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE domainPinglog SET state='success' WHERE challenge=? AND configId IN (SELECT id FROM pingconfig WHERE domainId=?)");
         ps.setString(1, hash);
         ps.setInt(2, id);
index 13e2e457c769c58b9159e2ab6b3ce72fedbfde40..c499b1a97264207becee6cb1348e73e9292e5dd0 100644 (file)
@@ -11,7 +11,7 @@ import org.cacert.gigi.email.MailProbe;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.RandomToken;
 
-public class EmailAddress implements IdCachable {
+public class EmailAddress implements IdCachable, Verifyable {
 
     private String address;
 
diff --git a/src/org/cacert/gigi/dbObjects/Verifyable.java b/src/org/cacert/gigi/dbObjects/Verifyable.java
new file mode 100644 (file)
index 0000000..68e7173
--- /dev/null
@@ -0,0 +1,8 @@
+package org.cacert.gigi.dbObjects;
+
+import org.cacert.gigi.GigiApiException;
+
+public interface Verifyable {
+
+    public void verify(String hash) throws GigiApiException;
+}
index a1d613a744346984602f33444889fb086eec662b..cdcf490fa01cb58d29d497b0e1c15055d65c310c 100644 (file)
@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.EmailAddress;
+import org.cacert.gigi.dbObjects.Verifyable;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
 
@@ -24,19 +25,25 @@ public class Verify extends Page {
 
         private String id;
 
+        private Verifyable target;
+
         public VerificationForm(HttpServletRequest hsr) {
             super(hsr, PATH);
             hash = hsr.getParameter("hash");
             type = hsr.getParameter("type");
             id = hsr.getParameter("id");
+            if ("email".equals(type)) {
+                target = EmailAddress.getById(Integer.parseInt(id));
+            } else if ("domain".equals("type")) {
+                target = Domain.getById(Integer.parseInt(id));
+            }
         }
 
         @Override
         public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
             if ("email".equals(type)) {
                 try {
-                    EmailAddress ea = EmailAddress.getById(Integer.parseInt(id));
-                    ea.verify(hash);
+                    target.verify(hash);
                     out.println("Email verification completed.");
                 } catch (IllegalArgumentException e) {
                     out.println(translate(req, "The email address is invalid."));
@@ -45,11 +52,10 @@ public class Verify extends Page {
                 }
             } else if ("domain".equals(type)) {
                 try {
-                    Domain ea = Domain.getById(Integer.parseInt(id));
-                    ea.verify(hash);
+                    target.verify(hash);
                     out.println("Domain verification completed.");
                 } catch (IllegalArgumentException e) {
-                    out.println(translate(req, "The domain address is invalid."));
+                    out.println(translate(req, "The domain is invalid."));
                 } catch (GigiApiException e) {
                     e.format(out, getLanguage(req));
                 }
@@ -62,9 +68,13 @@ public class Verify extends Page {
             vars.put("hash", hash);
             vars.put("id", id);
             vars.put("type", type);
+            if (target instanceof EmailAddress) {
+                vars.put("subject", ((EmailAddress) target).getAddress());
+            } else if (target instanceof Domain) {
+                vars.put("subject", ((Domain) target).getSuffix());
+            }
             getDefaultTemplate().output(out, l, vars);
         }
-
     }
 
     public static final String PATH = "/verify";
@@ -90,7 +100,12 @@ public class Verify extends Page {
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        new VerificationForm(req).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+        try {
+            new VerificationForm(req).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+        } catch (IllegalArgumentException e) {
+            resp.getWriter().println(translate(req, "The object to verify is invalid."));
+
+        }
     }
 
 }
index 68cfb7754cdf5500b4e47e38058f446b2f8cef27..1101f911ec9fdb34c705f99c8504dc93634aa8e9 100644 (file)
@@ -1,4 +1,4 @@
-<?=_Verify this element:?>
+<?=_Verify this element: ${subject}?>
 <input type="hidden" name="hash" value="<?=$hash?>"/>
 <input type="hidden" name="type" value="<?=$type?>"/>
 <input type="hidden" name="id" value="<?=$id?>"/>