]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/History.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / src / org / cacert / gigi / pages / account / History.java
1 package org.cacert.gigi.pages.account;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.cacert.gigi.dbObjects.User;
10 import org.cacert.gigi.output.template.OutputableArrayIterable;
11 import org.cacert.gigi.pages.Page;
12 import org.cacert.gigi.util.AuthorizationContext;
13
14 public class History extends Page {
15
16     public static final String SUPPORT_PATH = "/support/user/*/history";
17
18     public static final String PATH = "/account/history";
19
20     private static final int intStart = SUPPORT_PATH.indexOf('*');
21
22     private boolean support;
23
24     public History(boolean support) {
25         super(support ? "Support History" : "History");
26         this.support = support;
27     }
28
29     @Override
30     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
31         User u;
32         HashMap<String, Object> vars = new HashMap<>();
33         if (support) {
34             String info = req.getPathInfo();
35             int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
36             u = User.getById(id);
37             if (u == null) {
38                 resp.sendError(404);
39                 return;
40             }
41             vars.put("username", u.getPreferredName().toString());
42         } else {
43             u = getUser(req);
44         }
45         String[] adminLog = u.getAdminLog();
46         vars.put("entries", new OutputableArrayIterable(adminLog, "entry"));
47         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
48     }
49
50     @Override
51     public boolean isPermitted(AuthorizationContext ac) {
52         return ac != null && ( !support || ac.canSupport());
53     }
54 }