X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FDomain.java;h=f7c963c9e40e83c1033943d0d5d6f3004ac5add2;hb=3238dff5b3beca228359b370bc104f48d6247632;hp=fcd6709f2d50c7721d4cebab2f621ac1215a469e;hpb=ff8b2a0142c24f22a0fac2518eb0a6cd6b95ef12;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/Domain.java b/src/org/cacert/gigi/dbObjects/Domain.java index fcd6709f..f7c963c9 100644 --- a/src/org/cacert/gigi/dbObjects/Domain.java +++ b/src/org/cacert/gigi/dbObjects/Domain.java @@ -110,7 +110,7 @@ public class Domain implements IdCachable, Verifyable { public void addPing(DomainPingType type, String config) throws GigiApiException { try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `pingconfig` SET `domainid`=?, `type`=?::`pingType`, `info`=?")) { ps.setInt(1, id); - ps.setString(2, type.toString().toLowerCase()); + ps.setEnum(2, type); ps.setString(3, config); ps.execute(); } @@ -125,11 +125,21 @@ public class Domain implements IdCachable, Verifyable { configs = null; } + public synchronized boolean isVerifyable(String hash) throws GigiApiException { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `domainPinglog` 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); + return ps.executeQuery().next(); + } + } + public synchronized void verify(String hash) throws GigiApiException { 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)."); + } } }