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;
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;
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");
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);
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;
}
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()) {
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]);
+ }
}
<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>
<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>
--- /dev/null
+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());
+ }
+}
--- /dev/null
+<table class="wrapper dataTable centertext">
+<tbody>
+<tr><th><?=_Support actions?></th></tr>
+<? foreach($entries) { ?>
+<tr><td><?=$entry?></td></tr>
+<? } ?>
+</tbody>
+</table>
+
--- /dev/null
+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());
+ }
+}
--- /dev/null
+<table class="wrapper dataTable centertext">
+<tbody>
+<tr><th><?=_Trainings?></th></tr>
+<? foreach($entries) { ?>
+<tr><td><?=$entry?></td></tr>
+<? } ?>
+</tbody>
+</table>
+
+++ /dev/null
-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);
- }
-}