]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/User.java
upd: tighten synchronizeation on User Objects while assuring
[gigi.git] / src / org / cacert / gigi / dbObjects / User.java
index e6f06921c08b2ad4e0a53633b12660d86ebf198b..70fd821442ccbce19454cd91f888b1a07dc15d80 100644 (file)
@@ -19,6 +19,10 @@ import org.cacert.gigi.util.Notary;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.PasswordStrengthChecker;
 
+/**
+ * Represents an acting, assurable, user. Synchronizing on user means: no
+ * name-change and no assurance.
+ */
 public class User extends CertificateOwner {
 
     private Name name = new Name(null, null, null, null);
@@ -154,7 +158,7 @@ public class User extends CertificateOwner {
     }
 
     public int getAssurancePoints() {
-        try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT sum(points) FROM `notary` where `to`=? AND `deleted` is NULL")) {
+        try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT sum(points) FROM `notary` where `to`=? AND `deleted` is NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP)")) {
             query.setInt(1, getId());
 
             GigiResultSet rs = query.executeQuery();
@@ -278,7 +282,7 @@ public class User extends CertificateOwner {
                 List<Assurance> assurances = new LinkedList<Assurance>();
 
                 while (res.next()) {
-                    assurances.add(new Assurance(res));
+                    assurances.add(assuranceByRes(res));
                 }
 
                 this.receivedAssurances = assurances.toArray(new Assurance[0]);
@@ -297,7 +301,7 @@ public class User extends CertificateOwner {
                     List<Assurance> assurances = new LinkedList<Assurance>();
 
                     while (res.next()) {
-                        assurances.add(new Assurance(res));
+                        assurances.add(assuranceByRes(res));
                     }
 
                     this.madeAssurances = assurances.toArray(new Assurance[0]);
@@ -542,4 +546,8 @@ public class User extends CertificateOwner {
             ps.executeUpdate();
         }
     }
+
+    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"));
+    }
 }