X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=inline;f=src%2Forg%2Fcacert%2Fgigi%2FUser.java;h=eebf9317e2b4839aadc894fd0f86363787e17ab2;hb=fb38a9c8b9d86289213a36bd3d2afddc58ec7d3f;hp=f6d3c548ce51a7b608c508f4cb67425747820b7f;hpb=c7f07265ee5cd2af26fb62949d6cd768b16434fe;p=gigi.git diff --git a/src/org/cacert/gigi/User.java b/src/org/cacert/gigi/User.java index f6d3c548..eebf9317 100644 --- a/src/org/cacert/gigi/User.java +++ b/src/org/cacert/gigi/User.java @@ -14,11 +14,11 @@ public class User { private int id; - Name name = new Name(null, null, null, null); + private Name name = new Name(null, null, null, null); - Date dob; + private Date dob; - String email; + private String email; public User(int id) { this.id = id; @@ -241,7 +241,7 @@ public class User { public EmailAddress[] getEmails() { try { - PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM email WHERE memid=? AND deleted=0"); + PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM emails WHERE memid=? AND deleted=0"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); rs.last(); @@ -265,7 +265,7 @@ public class User { public Domain[] getDomains() { try { - PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM domain WHERE memid=? AND deleted IS NULL"); + PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM domains WHERE memid=? AND deleted IS NULL"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); rs.last(); @@ -287,6 +287,53 @@ public class User { return null; } + public Certificate[] getCertificates() { + try { + PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT serial FROM certs WHERE memid=? AND revoked=0"); + ps.setInt(1, id); + ResultSet 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; + } catch (SQLException e) { + e.printStackTrace(); + } + + return null; + } + + 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); + } + public void updateDefaultEmail(EmailAddress newMail) throws GigiApiException { try { EmailAddress[] adrs = getEmails(); @@ -317,7 +364,7 @@ public class User { for (int i = 0; i < emails.length; i++) { if (emails[i].getId() == mail.getId()) { try { - PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE email SET deleted=? WHERE id=?"); + PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE emails SET deleted=? WHERE id=?"); ps.setDate(1, new Date(System.currentTimeMillis())); ps.setInt(2, mail.getId()); ps.execute();