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;
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();
}
}
+ public void setName(Name name) {
+ this.name = name;
+ }
+
public boolean canAssure() {
if ( !isOfAge(14)) { // PoJAM
return false;
return System.currentTimeMillis() >= c.getTime().getTime();
}
- public EmailAddress[] getEmails() {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM emails WHERE memid=? AND deleted is NULL");
- ps.setInt(1, getId());
- GigiResultSet rs = ps.executeQuery();
- rs.last();
- int count = rs.getRow();
- EmailAddress[] data = new EmailAddress[count];
- rs.beforeFirst();
- for (int i = 0; i < data.length; i++) {
- if ( !rs.next()) {
- throw new Error("Internal sql api violation.");
- }
- data[i] = EmailAddress.getById(rs.getInt(1));
- }
- rs.close();
- return data;
-
- }
-
- public Domain[] getDomains() {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM domains WHERE memid=? AND deleted IS NULL");
- ps.setInt(1, getId());
- GigiResultSet rs = ps.executeQuery();
- rs.last();
- int count = rs.getRow();
- Domain[] data = new Domain[count];
- rs.beforeFirst();
- for (int i = 0; i < data.length; i++) {
- if ( !rs.next()) {
- throw new Error("Internal sql api violation.");
- }
- data[i] = Domain.getById(rs.getInt(1));
- }
- rs.close();
- return data;
-
- }
-
- public Certificate[] getCertificates() {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT serial FROM certs WHERE memid=? AND revoked IS NULL");
- ps.setInt(1, getId());
- GigiResultSet rs = ps.executeQuery();
- rs.last();
- int count = rs.getRow();
- Certificate[] data = new Certificate[count];
- rs.beforeFirst();
- for (int i = 0; i < data.length; i++) {
- if ( !rs.next()) {
- throw new Error("Internal sql api violation.");
- }
- data[i] = Certificate.getBySerial(rs.getString(1));
- }
- rs.close();
- return data;
-
- }
-
- public boolean isValidDomain(String domainname) {
- for (Domain d : getDomains()) {
- String sfx = d.getSuffix();
- if (domainname.equals(sfx) || domainname.endsWith("." + sfx)) {
- return true;
- }
- }
- return false;
- }
-
- public boolean isValidEmail(String email) {
- for (EmailAddress em : getEmails()) {
- if (em.getAddress().equals(email)) {
- return true;
- }
- }
- return false;
- }
-
public boolean isValidName(String name) {
return getName().matches(name);
}
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) {
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:
return false;
}
}
+
}