]> WPIA git - gigi.git/commitdiff
upd: make verification processes more consistent on failure
authorFelix Dörre <felix@dogcraft.de>
Thu, 22 Sep 2016 21:49:48 +0000 (23:49 +0200)
committerFelix Dörre <felix@dogcraft.de>
Tue, 27 Sep 2016 14:16:14 +0000 (16:16 +0200)
Change-Id: I0a1dfd77fea5f9b365cc166196d0068607cc2b5d

src/org/cacert/gigi/database/GigiPreparedStatement.java
src/org/cacert/gigi/dbObjects/Domain.java
src/org/cacert/gigi/dbObjects/EmailAddress.java
src/org/cacert/gigi/pages/Verify.java

index a779f965fb56c150a2329b9dc6bddb6fd4842424..4dea5f981f68eb28679734eb1ed88c74e2dc7328 100644 (file)
@@ -49,6 +49,19 @@ public class GigiPreparedStatement implements AutoCloseable {
         }
     }
 
+    public boolean executeMaybeUpdate() {
+        try {
+            int updated = target.executeUpdate();
+            if (updated > 1) {
+                throw new Error("More than one record (" + updated + ") updated.");
+            }
+            return updated == 1;
+        } catch (SQLException e) {
+            handleSQL(e);
+            throw new Error(e);
+        }
+    }
+
     public boolean execute() {
         try {
             return target.execute();
index 36b7dc6f651dec5c071f15796ac38c42a3117a56..3ecf728567f6c166aa5dc960091c8c26061c6f28 100644 (file)
@@ -129,7 +129,9 @@ public class Domain implements IdCachable, Verifyable {
         try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')")) {
             ps.setString(1, hash);
             ps.setInt(2, id);
-            ps.executeUpdate();
+            if ( !ps.executeMaybeUpdate()) {
+                throw new IllegalArgumentException("Given token could not be found to complete the verification process (Domain Ping).");
+            }
         }
     }
 
index afd7f2c1fa13321e2beee95e1f063f03b02d8b1e..b2106d8bff71c901c3e51c1bfe9e6b3d8f160c8c 100644 (file)
@@ -96,11 +96,13 @@ public class EmailAddress implements IdCachable, Verifyable {
     }
 
     public synchronized void verify(String hash) throws GigiApiException {
-        try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE `emailPinglog` SET `status`='success'::`pingState` WHERE `email`=? AND `uid`=? AND `type`='active' AND `challenge`=?")) {
+        try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE `emailPinglog` SET `status`='success'::`pingState` WHERE `email`=? AND `uid`=? AND `type`='active' AND `challenge`=? AND `status`='open'::`pingState`")) {
             stmt.setString(1, address);
             stmt.setInt(2, owner.getId());
             stmt.setString(3, hash);
-            stmt.executeUpdate();
+            if ( !stmt.executeMaybeUpdate()) {
+                throw new IllegalArgumentException("Given token could not be found to complete the verification process (Domain Ping).");
+            }
         }
         // Verify user with that primary email
         try (GigiPreparedStatement ps2 = new GigiPreparedStatement("update `users` set `verified`='1' where `id`=? and `email`=? and `verified`='0'")) {
index d7e5aed6bfe405c22512822755ab108da412c759..2b4cd82605cfe2ffc62fa76b2cde50e489717ad0 100644 (file)
@@ -62,14 +62,14 @@ public class Verify extends Page {
                 try {
                     target.verify(hash);
                 } catch (IllegalArgumentException e) {
-                    throw new GigiApiException("The email address is invalid.");
+                    throw new PermamentFormException(new GigiApiException("Given token could not be found to complete the verification process (Email Ping)."));
                 }
                 return new SuccessMessageResult(new Scope(emailAddressVerified, data));
             } else if ("domain".equals(type)) {
                 try {
                     target.verify(hash);
                 } catch (IllegalArgumentException e) {
-                    throw new GigiApiException("The domain is invalid.");
+                    throw new PermamentFormException(new GigiApiException("Given token could not be found to complete the verification process (Domain Ping)."));
                 }
                 return new SuccessMessageResult(new Scope(domainVerified, data));
             } else {