]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/User.java
assert a minimum age while signup
[gigi.git] / src / org / cacert / gigi / dbObjects / User.java
index d68b183fa330ead188befeecd67eb73bd1e74c31..8f7c3f148cc4cdc1a18b5e5b25a6aa7e2fb293c2 100644 (file)
@@ -1,7 +1,6 @@
 package org.cacert.gigi.dbObjects;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -14,6 +13,7 @@ import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.DateSelector;
+import org.cacert.gigi.util.CalendarUtil;
 import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.Notary;
 import org.cacert.gigi.util.PasswordHash;
@@ -39,6 +39,8 @@ public class User extends CertificateOwner {
 
     private final Set<Group> groups = new HashSet<>();
 
+    public static final int MINIMUM_AGE = 16;
+
     protected User(GigiResultSet rs) {
         super(rs.getInt("id"));
         updateName(rs);
@@ -132,7 +134,7 @@ public class User extends CertificateOwner {
     }
 
     public boolean canAssure() {
-        if ( !isOfAge(14)) { // PoJAM
+        if ( !CalendarUtil.isOfAge(dob, 14)) { // PoJAM
             return false;
         }
         if (getAssurancePoints() < 100) {
@@ -194,7 +196,7 @@ public class User extends CertificateOwner {
      * @return the maximal points @
      */
     public int getMaxAssurePoints() {
-        if ( !isOfAge(18)) {
+        if ( !CalendarUtil.isOfAge(dob, 18)) {
             return 10; // PoJAM
         }
 
@@ -220,17 +222,6 @@ public class User extends CertificateOwner {
         return points;
     }
 
-    public boolean isOfAge(int desiredAge) {
-        Calendar c = Calendar.getInstance();
-        c.setTimeInMillis(dob.getTime());
-        int year = c.get(Calendar.YEAR);
-        int month = c.get(Calendar.MONTH);
-        int day = c.get(Calendar.DAY_OF_MONTH);
-        c.set(year, month, day);
-        c.add(Calendar.YEAR, desiredAge);
-        return System.currentTimeMillis() >= c.getTime().getTime();
-    }
-
     public boolean isValidName(String name) {
         return getName().matches(name);
     }