]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/User.java
ADD: Get infomation about user's directory listing options
[gigi.git] / src / org / cacert / gigi / User.java
index fd1989b26aa41e168d4b38cfc54a3eb5270b54ad..22f76c4c5f8347e968e6d6c65b54948d8e9e3c8b 100644 (file)
@@ -7,6 +7,8 @@ import java.sql.SQLException;
 import java.util.Calendar;
 
 import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.util.Notary;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.PasswordStrengthChecker;
 
@@ -24,6 +26,10 @@ public class User {
 
     public User(int id) {
         this.id = id;
+        updateName(id);
+    }
+
+    private void updateName(int id) {
         try {
             PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `fname`, `lname`,`mname`, `suffix`, `dob`, `email` FROM `users` WHERE id=?");
             ps.setInt(1, id);
@@ -423,4 +429,41 @@ public class User {
     public void invalidateReceivedAssurances() {
         receivedAssurances = null;
     }
+
+    public void updateUserData() throws SQLException, GigiApiException {
+        synchronized (Notary.class) {
+            if (getAssurancePoints() != 0) {
+                updateUserData();
+                throw new GigiApiException("No change after assurance allowed.");
+            }
+            PreparedStatement update = DatabaseConnection.getInstance().prepare("UPDATE users SET fname=?, lname=?, mname=?, suffix=?, dob=? WHERE id=?");
+            update.setString(1, getFname());
+            update.setString(2, getLname());
+            update.setString(3, getMname());
+            update.setString(4, getSuffix());
+            update.setDate(5, getDob());
+            update.setInt(6, getId());
+            update.executeUpdate();
+        }
+    }
+
+    public Language getPrefferedLanguage() {
+        return Language.getInstance("de");
+    }
+
+    public boolean wantsDirectoryListing() throws SQLException {
+        PreparedStatement get = DatabaseConnection.getInstance().prepare("SELECT listme FROM users WHERE id=?");
+        get.setInt(1, getId());
+        ResultSet exec = get.executeQuery();
+        exec.next();
+        return exec.getBoolean("listme");
+    }
+
+    public String getContactInformation() throws SQLException {
+        PreparedStatement get = DatabaseConnection.getInstance().prepare("SELECT contactinfo FROM users WHERE id=?");
+        get.setInt(1, getId());
+        ResultSet exec = get.executeQuery();
+        exec.next();
+        return exec.getString("contactinfo");
+    }
 }