From 3691e44c4806677cad61a5da0fe8e5c8a985577d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Fri, 5 Sep 2014 11:38:07 +0200 Subject: [PATCH] Factor out age check. --- src/org/cacert/gigi/dbObjects/User.java | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/org/cacert/gigi/dbObjects/User.java b/src/org/cacert/gigi/dbObjects/User.java index 2d8cd96f..7a11cdb4 100644 --- a/src/org/cacert/gigi/dbObjects/User.java +++ b/src/org/cacert/gigi/dbObjects/User.java @@ -162,6 +162,9 @@ public class User implements IdCachable { } public boolean canAssure() throws SQLException { + if ( !isOfAge(14)) { // PoJAM + return false; + } if (getAssurancePoints() < 100) { return false; } @@ -227,17 +230,12 @@ public class User implements IdCachable { * @throws SQLException */ public int getMaxAssurePoints() throws SQLException { + if ( !isOfAge(18)) { + return 10; // PoJAM + } + int exp = getExperiencePoints(); int points = 10; - Calendar c = Calendar.getInstance(); - c.setTime(dob); - int year = c.get(Calendar.YEAR); - int month = c.get(Calendar.MONTH); - int day = c.get(Calendar.DAY_OF_MONTH); - c.set(year + 18, month, day); - if (System.currentTimeMillis() < c.getTime().getTime()) { - return points; // not 18 Years old. - } if (exp >= 10) { points += 5; @@ -257,6 +255,17 @@ public class User implements IdCachable { return points; } + public boolean isOfAge(int desiredAge) { + Calendar c = Calendar.getInstance(); + c.setTime(dob); + 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 EmailAddress[] getEmails() { try { PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM emails WHERE memid=? AND deleted=0"); -- 2.39.2