]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/User.java
add: check if the last valid verification is within the last 39 month
[gigi.git] / src / org / cacert / gigi / dbObjects / User.java
index 370790c91f9db8bd641528325e594b19e6949cdc..8e9bc762b227d88844edf05c0028b41df1488224 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Set;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.dbObjects.CATS.CATSType;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.pages.PasswordResetPage;
@@ -48,6 +49,11 @@ public class User extends CertificateOwner {
 
     public static final boolean POJAM_ENABLED = false;
 
+    /**
+     * Time in months a verification is considered "recent".
+     */
+    public static final int VERIFICATION_MONTHS = 39;
+
     protected User(GigiResultSet rs) {
         super(rs.getInt("id"));
         updateName(rs);
@@ -161,7 +167,7 @@ public class User extends CertificateOwner {
     public boolean hasPassedCATS() {
         try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT 1 FROM `cats_passed` where `user_id`=? AND `variant_id`=?")) {
             query.setInt(1, getId());
-            query.setInt(2, CATS.ASSURER_CHALLENGE_ID);
+            query.setInt(2, CATSType.ASSURER_CHALLENGE.getId());
             try (GigiResultSet rs = query.executeQuery()) {
                 if (rs.next()) {
                     return true;
@@ -567,4 +573,14 @@ public class User extends CertificateOwner {
     private Assurance assuranceByRes(GigiResultSet res) {
         return new Assurance(res.getInt("id"), User.getById(res.getInt("from")), User.getById(res.getInt("to")), res.getString("location"), res.getString("method"), res.getInt("points"), res.getString("date"));
     }
+
+    public static boolean isInVerificationLimit(int id) {
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `notary` WHERE `to` = ? AND `when` > (now() - (interval '1 month' * ?)) AND (`expire` IS NULL OR `expire` > now()) AND `deleted` IS NULL;")) {
+            ps.setInt(1, id);
+            ps.setInt(2, VERIFICATION_MONTHS);
+
+            GigiResultSet rs = ps.executeQuery();
+            return rs.next();
+        }
+    }
 }