X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FUser.java;h=cf43f80f3182a4377a1578b3f11ac370375f8e53;hp=9f5d8e17cf1455a38c3cc7b874300b7f61c55893;hb=557a8a2e5f395400467459f003956bf7660cc044;hpb=edb152f5a1d445e97b6a9db4a0288c5020b3a476 diff --git a/src/org/cacert/gigi/dbObjects/User.java b/src/org/cacert/gigi/dbObjects/User.java index 9f5d8e17..cf43f80f 100644 --- a/src/org/cacert/gigi/dbObjects/User.java +++ b/src/org/cacert/gigi/dbObjects/User.java @@ -21,6 +21,7 @@ import org.cacert.gigi.util.DayDate; import org.cacert.gigi.util.Notary; import org.cacert.gigi.util.PasswordHash; import org.cacert.gigi.util.PasswordStrengthChecker; +import org.cacert.gigi.util.TimeConditions; /** * Represents an acting, assurable, user. Synchronizing on user means: no @@ -42,18 +43,20 @@ public class User extends CertificateOwner { public static final int MINIMUM_AGE = 16; + public static final int MAXIMUM_PLAUSIBLE_AGE = 120; + public static final int POJAM_AGE = 14; public static final int ADULT_AGE = 18; public static final boolean POJAM_ENABLED = false; - public static final int EXPERIENCE_POINTS = 2; + public static final int EXPERIENCE_POINTS = 4; /** * Time in months a verification is considered "recent". */ - public static final int VERIFICATION_MONTHS = 39; + public static final int VERIFICATION_MONTHS = TimeConditions.getInstance().getVerificationMonths(); private Name preferredName; @@ -133,7 +136,15 @@ public class User extends CertificateOwner { public void setDoB(DayDate dob) throws GigiApiException { synchronized (Notary.class) { if (getReceivedAssurances().length != 0) { - throw new GigiApiException("No change after assurance allowed."); + throw new GigiApiException("No change after verification allowed."); + } + + if ( !CalendarUtil.isOfAge(dob, User.MINIMUM_AGE)) { + throw new GigiApiException("Entered date of birth is below the restricted age requirements."); + } + + if (CalendarUtil.isOfAge(dob, User.MAXIMUM_PLAUSIBLE_AGE)) { + throw new GigiApiException("Entered date of birth exceeds the maximum age set in our policies. Please check your DoB is correct and contact support if the issue persists."); } this.dob = dob; rawUpdateUserData(); @@ -246,6 +257,7 @@ public class User extends CertificateOwner { * * @return the maximal points @ */ + @SuppressWarnings("unused") public int getMaxAssurePoints() { if ( !CalendarUtil.isOfAge(dob, ADULT_AGE) && POJAM_ENABLED) { return 10; // PoJAM @@ -322,7 +334,7 @@ public class User extends CertificateOwner { public synchronized Assurance[] getReceivedAssurances() { if (receivedAssurances == null) { - try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT * FROM `notary` INNER JOIN `names` ON `names`.`id` = `notary`.`to` WHERE `names`.`uid`=? AND `notary`.`deleted` IS NULL")) { + try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT * FROM `notary` INNER JOIN `names` ON `names`.`id` = `notary`.`to` WHERE `names`.`uid`=? AND `notary`.`deleted` IS NULL ORDER BY `when` DESC")) { query.setInt(1, getId()); GigiResultSet res = query.executeQuery(); @@ -341,7 +353,7 @@ public class User extends CertificateOwner { public synchronized Assurance[] getMadeAssurances() { if (madeAssurances == null) { - try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT * FROM notary WHERE `from`=? AND deleted is NULL")) { + try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT * FROM notary WHERE `from`=? AND deleted is NULL ORDER BY `when` DESC")) { query.setInt(1, getId()); try (GigiResultSet res = query.executeQuery()) { @@ -384,7 +396,7 @@ public class User extends CertificateOwner { } - public Name getPreferredName() { + public synchronized Name getPreferredName() { return preferredName; }