]> WPIA git - gigi.git/commitdiff
add: show support and user the account history and the trainings.
authorFelix Dörre <felix@dogcraft.de>
Fri, 6 Nov 2015 11:30:33 +0000 (12:30 +0100)
committerFelix Dörre <felix@dogcraft.de>
Fri, 6 Nov 2015 11:31:01 +0000 (12:31 +0100)
src/org/cacert/gigi/Gigi.java
src/org/cacert/gigi/dbObjects/SupportedUser.java
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/pages/account/MyDetailsForm.templ
src/org/cacert/gigi/pages/account/MyDetailsFormAssured.templ
src/org/cacert/gigi/pages/account/UserHistory.java [new file with mode: 0644]
src/org/cacert/gigi/pages/account/UserHistory.templ [new file with mode: 0644]
src/org/cacert/gigi/pages/account/UserTrainings.java [new file with mode: 0644]
src/org/cacert/gigi/pages/account/UserTrainings.templ [new file with mode: 0644]
src/org/cacert/gigi/pages/admin/support/SupportUserHistory.java [deleted file]

index b347a63f5f9a56f92a28a67e0a85703007803281..00a10f4a34b623e9f5e22ef44fb8af3f265e4974 100644 (file)
@@ -43,6 +43,8 @@ import org.cacert.gigi.pages.TestSecure;
 import org.cacert.gigi.pages.Verify;
 import org.cacert.gigi.pages.account.ChangePasswordPage;
 import org.cacert.gigi.pages.account.MyDetails;
+import org.cacert.gigi.pages.account.UserHistory;
+import org.cacert.gigi.pages.account.UserTrainings;
 import org.cacert.gigi.pages.account.certs.CertificateAdd;
 import org.cacert.gigi.pages.account.certs.Certificates;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
@@ -52,7 +54,6 @@ import org.cacert.gigi.pages.admin.support.FindDomainPage;
 import org.cacert.gigi.pages.admin.support.FindUserPage;
 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
-import org.cacert.gigi.pages.admin.support.SupportUserHistory;
 import org.cacert.gigi.pages.error.AccessDenied;
 import org.cacert.gigi.pages.error.PageNotFound;
 import org.cacert.gigi.pages.main.RegisterPage;
@@ -142,7 +143,10 @@ public class Gigi extends HttpServlet {
             putPage(FindDomainPage.PATH, new FindDomainPage("Find Domain"), "System Admin");
             putPage(SupportEnterTicketPage.PATH, new SupportEnterTicketPage(), "System Admin");
             putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage("Support: User Details"), null);
-            putPage(SupportUserHistory.PATH, new SupportUserHistory(), null);
+            putPage(UserHistory.PATH, new UserHistory(false), "My Account");
+            putPage(UserHistory.SUPPORT_PATH, new UserHistory(true), null);
+            putPage(UserTrainings.PATH, new UserTrainings(false), "My Account");
+            putPage(UserTrainings.SUPPORT_PATH, new UserTrainings(true), null);
             if (testing) {
                 try {
                     Class<?> manager = Class.forName("org.cacert.gigi.pages.Manager");
index 17d7c8cf56984d39b985ac86554c9067a93f1be6..decf55274047b5eab4e13400c7f2c3530cf66742 100644 (file)
@@ -54,7 +54,7 @@ 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=?");
+        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);
index 1b4b52eaf17c69f53afbb17a72e8d6d67d5569ad..f12002334566923764067289aa1f9cb39c281d12 100644 (file)
@@ -15,6 +15,7 @@ import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.util.Notary;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.PasswordStrengthChecker;
@@ -137,7 +138,7 @@ public class User extends CertificateOwner {
     }
 
     public boolean hasPassedCATS() {
-        GigiPreparedStatement query = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `cats_passed` where `user_id`=?");
+        GigiPreparedStatement query = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `cats_passed` where `user_id`=? AND `variant_id`=1");
         query.setInt(1, getId());
         try (GigiResultSet rs = query.executeQuery()) {
             if (rs.next()) {
@@ -468,4 +469,30 @@ public class User extends CertificateOwner {
         return false;
     }
 
+    public String[] getAdminLog() {
+        GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("SELECT `when`, type, information FROM `adminLog` WHERE uid=? ORDER BY `when` ASC");
+        prep.setInt(1, getId());
+        GigiResultSet res = prep.executeQuery();
+        List<String> entries = new LinkedList<String>();
+
+        while (res.next()) {
+            entries.add(res.getString(2) + " (" + res.getString(3) + ")");
+        }
+
+        return entries.toArray(new String[0]);
+    }
+
+    public String[] getTrainings() {
+        GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("SELECT `pass_date`, `type_text` FROM `cats_passed` LEFT JOIN `cats_type` ON `cats_type`.`id`=`cats_passed`.`variant_id`  WHERE `user_id`=? ORDER BY `pass_date` ASC");
+        prep.setInt(1, getId());
+        GigiResultSet res = prep.executeQuery();
+        List<String> entries = new LinkedList<String>();
+
+        while (res.next()) {
+
+            entries.add(DateSelector.getDateFormat().format(res.getTimestamp(1)) + " (" + res.getString(2) + ")");
+        }
+
+        return entries.toArray(new String[0]);
+    }
 }
index ec290a8ba1aaac8705c27d5945f3a3a445eb3087..ea1e9fca58746c9e181c5e96080e3fa2e2c27112 100644 (file)
@@ -30,7 +30,7 @@
     <td><?=$DoB?></td>
   </tr>
   <tr>
-    <td colspan="2" class="title"><?=_Show account history?></td>
+    <td colspan="2" class="title"><a href="/account/history"><?=_Show account history?></a></td>
   </tr>
   <tr>
     <td colspan="2" class="title"><?=_View secret question & answers and OTP phrases?></td>
index 6d7310719f957d7f1fc68cc99452a03132e129f2..a3ad85d50db2743fde5b7ec10619095ba6ed4309 100644 (file)
@@ -30,7 +30,7 @@
     <td><?=$DoB?></td>
   </tr>
   <tr>
-    <td colspan="2" class="title"><?=_Show account history?></td>
+    <td colspan="2" class="title"><a href="/account/history"><?=_Show account history?></a></td>
   </tr>
   <tr>
     <td colspan="2" class="title"><?=_View secret question & answers and OTP phrases?></td>
diff --git a/src/org/cacert/gigi/pages/account/UserHistory.java b/src/org/cacert/gigi/pages/account/UserHistory.java
new file mode 100644 (file)
index 0000000..53e81a2
--- /dev/null
@@ -0,0 +1,53 @@
+package org.cacert.gigi.pages.account;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.output.template.OutputableArrayIterable;
+import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.util.AuthorizationContext;
+
+public class UserHistory extends Page {
+
+    public static final String SUPPORT_PATH = "/support/user/*/history";
+
+    public static final String PATH = "/account/history";
+
+    private static final int intStart = SUPPORT_PATH.indexOf('*');
+
+    private boolean support;
+
+    public UserHistory(boolean support) {
+        super(support ? "Support user history" : "History");
+        this.support = support;
+    }
+
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        User u;
+        if (support) {
+            String info = req.getPathInfo();
+            int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
+            u = User.getById(id);
+            if (u == null) {
+                resp.sendError(404);
+                return;
+            }
+        } else {
+            u = getUser(req);
+        }
+        String[] adminLog = u.getAdminLog();
+        HashMap<String, Object> vars = new HashMap<>();
+        vars.put("entries", new OutputableArrayIterable(adminLog, "entry"));
+        getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
+    }
+
+    @Override
+    public boolean isPermitted(AuthorizationContext ac) {
+        return ac != null && ( !support || ac.canSupport());
+    }
+}
diff --git a/src/org/cacert/gigi/pages/account/UserHistory.templ b/src/org/cacert/gigi/pages/account/UserHistory.templ
new file mode 100644 (file)
index 0000000..238f9c4
--- /dev/null
@@ -0,0 +1,9 @@
+<table class="wrapper dataTable centertext">
+<tbody>
+<tr><th><?=_Support actions?></th></tr>
+<? foreach($entries) { ?>
+<tr><td><?=$entry?></td></tr>
+<? } ?>
+</tbody>
+</table>
+
diff --git a/src/org/cacert/gigi/pages/account/UserTrainings.java b/src/org/cacert/gigi/pages/account/UserTrainings.java
new file mode 100644 (file)
index 0000000..8c117d5
--- /dev/null
@@ -0,0 +1,52 @@
+package org.cacert.gigi.pages.account;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.output.template.OutputableArrayIterable;
+import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.util.AuthorizationContext;
+
+public class UserTrainings extends Page {
+
+    public static final String SUPPORT_PATH = "/support/user/*/trainings";
+
+    public static final String PATH = "/account/trainings";
+
+    private static final int intStart = SUPPORT_PATH.indexOf('*');
+
+    private boolean support;
+
+    public UserTrainings(boolean support) {
+        super(support ? "Support User Trainings" : "Trainings");
+        this.support = support;
+    }
+
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        User u;
+        if (support) {
+            String info = req.getPathInfo();
+            int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
+            u = User.getById(id);
+            if (u == null) {
+                resp.sendError(404);
+                return;
+            }
+        } else {
+            u = getUser(req);
+        }
+        HashMap<String, Object> vars = new HashMap<>();
+        vars.put("entries", new OutputableArrayIterable(u.getTrainings(), "entry"));
+        getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
+    }
+
+    @Override
+    public boolean isPermitted(AuthorizationContext ac) {
+        return ac != null && ( !support || ac.canSupport());
+    }
+}
diff --git a/src/org/cacert/gigi/pages/account/UserTrainings.templ b/src/org/cacert/gigi/pages/account/UserTrainings.templ
new file mode 100644 (file)
index 0000000..b4eb006
--- /dev/null
@@ -0,0 +1,9 @@
+<table class="wrapper dataTable centertext">
+<tbody>
+<tr><th><?=_Trainings?></th></tr>
+<? foreach($entries) { ?>
+<tr><td><?=$entry?></td></tr>
+<? } ?>
+</tbody>
+</table>
+
diff --git a/src/org/cacert/gigi/pages/admin/support/SupportUserHistory.java b/src/org/cacert/gigi/pages/admin/support/SupportUserHistory.java
deleted file mode 100644 (file)
index 02ad8b0..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.cacert.gigi.pages.admin.support;
-
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.cacert.gigi.dbObjects.Group;
-import org.cacert.gigi.dbObjects.User;
-import org.cacert.gigi.pages.Page;
-import org.cacert.gigi.util.AuthorizationContext;
-
-public class SupportUserHistory extends Page {
-
-    public static final String PATH = "/support/user/*/history";
-
-    private static final int intStart = PATH.indexOf('*');
-
-    public SupportUserHistory() {
-        super("Support user history");
-    }
-
-    @Override
-    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        String info = req.getPathInfo();
-        int id = Integer.parseInt(info.substring(intStart, info.length() - PATH.length() + intStart + 1));
-        User u = User.getById(id);
-        if (u == null) {
-            resp.sendError(404);
-            return;
-        }
-        // TODO get Admin log
-    }
-
-    @Override
-    public boolean isPermitted(AuthorizationContext ac) {
-        return ac != null && ac.isInGroup(Group.SUPPORTER);
-    }
-}