]> 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 7c45661e8a13dab11a72c3392ea1b82610b7d93e..8e9bc762b227d88844edf05c0028b41df1488224 100644 (file)
@@ -49,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);
@@ -568,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();
+        }
+    }
 }