]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/SupportedUser.java
add: Allow multiple names, name-schemes, multi-name-assurance, etc.
[gigi.git] / src / org / cacert / gigi / dbObjects / SupportedUser.java
index decf55274047b5eab4e13400c7f2c3530cf66742..193a32b0853492069c33059b007510c2636eb279 100644 (file)
@@ -1,11 +1,20 @@
 package org.cacert.gigi.dbObjects;
 
-import java.sql.Date;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Locale;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
+import org.cacert.gigi.email.SendMail;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.SprintfCommand;
+import org.cacert.gigi.util.DayDate;
+import org.cacert.gigi.util.ServerConstants;
 
 public class SupportedUser {
 
@@ -21,21 +30,12 @@ public class SupportedUser {
         this.ticket = ticket;
     }
 
-    public boolean setName(Name newName) throws GigiApiException {
-        if (newName.equals(target.getName())) {
-            return false;
-        }
-        writeSELog("SE Name change");
-        target.setName(newName);
-        return true;
-    }
-
-    public boolean setDob(Date dob) throws GigiApiException {
-        if (dob.toString().equals(target.getDoB().toString())) {
+    public boolean setDob(DayDate dob) throws GigiApiException {
+        if (dob.equals(target.getDoB())) {
             return false;
         }
         writeSELog("SE dob change");
-        target.setDoB(dob);
+        target.setDoBAsSupport(dob);
         return true;
     }
 
@@ -54,12 +54,13 @@ public class SupportedUser {
         if (ticket == null) {
             throw new GigiApiException("No ticket set!");
         }
-        GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO `adminLog` SET uid=?, admin=?, type=?, information=?");
-        prep.setInt(1, target.getId());
-        prep.setInt(2, supporter.getId());
-        prep.setString(3, type);
-        prep.setString(4, ticket);
-        prep.executeUpdate();
+        try (GigiPreparedStatement prep = new GigiPreparedStatement("INSERT INTO `adminLog` SET uid=?, admin=?, type=?, information=?")) {
+            prep.setInt(1, target.getId());
+            prep.setInt(2, supporter.getId());
+            prep.setString(3, type);
+            prep.setString(4, ticket);
+            prep.executeUpdate();
+        }
     }
 
     public int getId() {
@@ -78,8 +79,29 @@ public class SupportedUser {
         return target;
     }
 
-    public void submitSupportAction() throws GigiApiException {
-        target.rawUpdateUserData();
+    public void grant(Group toMod) {
+        target.grantGroup(supporter, toMod);
+    }
+
+    public void revoke(Group toMod) {
+        target.revokeGroup(supporter, toMod);
     }
 
+    public void sendSupportNotification(String subject, Outputable message) {
+        try {
+            StringWriter sw = new StringWriter();
+            PrintWriter outMail = new PrintWriter(sw);
+            outMail.print("Hi," + "\n\n");
+            SprintfCommand.createSimple("supporter {0} triggered:", supporter.getPreferredName().toString()).output(outMail, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+            outMail.print("\n\n");
+            message.output(outMail, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+            outMail.print("\n\n");
+            outMail.print("RA DB");
+            outMail.close();
+            String supportemailaddress = "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+            SendMail.getInstance().sendMail(supportemailaddress, "[" + this.getTicket() + "] RA DB " + subject, sw.toString(), supportemailaddress, null, null, null, null, false);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }