]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/User.java
UPD: Removed small debug output
[gigi.git] / src / org / cacert / gigi / dbObjects / User.java
index 398af91adf7304fbad0867817d1c14768425b3bc..c453465b505c36c460626c3ff149b83202225463 100644 (file)
@@ -1,9 +1,12 @@
 package org.cacert.gigi.dbObjects;
 
 import java.sql.Date;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
@@ -130,7 +133,7 @@ public class User extends CertificateOwner {
         if ( !rs.next()) {
             throw new GigiApiException("User not found... very bad.");
         }
-        if ( !PasswordHash.verifyHash(oldPass, rs.getString(1))) {
+        if (PasswordHash.verifyHash(oldPass, rs.getString(1)) == null) {
             throw new GigiApiException("Old password does not match.");
         }
         rs.close();
@@ -143,6 +146,10 @@ public class User extends CertificateOwner {
         }
     }
 
+    public void setName(Name name) {
+        this.name = name;
+    }
+
     public boolean canAssure() {
         if ( !isOfAge(14)) { // PoJAM
             return false;
@@ -411,6 +418,18 @@ public class User extends CertificateOwner {
         ps.execute();
     }
 
+    public List<Organisation> getOrganisations() {
+        List<Organisation> orgas = new ArrayList<>();
+        GigiPreparedStatement query = DatabaseConnection.getInstance().prepare("SELECT orgid FROM org_admin WHERE `memid`=? AND deleted is NULL");
+        query.setInt(1, getId());
+        GigiResultSet res = query.executeQuery();
+
+        while (res.next()) {
+            orgas.add(Organisation.getById(res.getInt(1)));
+        }
+        return orgas;
+    }
+
     public static synchronized User getById(int id) {
         CertificateOwner co = CertificateOwner.getById(id);
         if (co instanceof User) {
@@ -419,6 +438,27 @@ public class User extends CertificateOwner {
         return null;
     }
 
+    public static User getByEmail(String mail) {
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT users.id FROM users inner join certOwners on certOwners.id=users.id WHERE email=? AND deleted is null");
+        ps.setString(1, mail);
+        GigiResultSet rs = ps.executeQuery();
+        if ( !rs.next()) {
+            return null;
+        }
+        return User.getById(rs.getInt(1));
+    }
+
+    public static User[] findByEmail(String mail) {
+        LinkedList<User> results = new LinkedList<User>();
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT users.id FROM users inner join certOwners on certOwners.id=users.id WHERE users.email LIKE ? AND deleted is null GROUP BY users.id ASC LIMIT 100");
+        ps.setString(1, mail);
+        GigiResultSet rs = ps.executeQuery();
+        while (rs.next()) {
+            results.add(User.getById(rs.getInt(1)));
+        }
+        return results.toArray(new User[results.size()]);
+    }
+
     public boolean canIssue(CertificateProfile p) {
         switch (p.getCAId()) {
         case 0:
@@ -434,4 +474,5 @@ public class User extends CertificateOwner {
             return false;
         }
     }
+
 }