1 package club.wpia.gigi.pages.account;
3 import java.io.IOException;
4 import java.util.HashMap;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
9 import club.wpia.gigi.dbObjects.User;
10 import club.wpia.gigi.output.template.OutputableArrayIterable;
11 import club.wpia.gigi.pages.Page;
12 import club.wpia.gigi.util.AuthorizationContext;
14 public class History extends Page {
16 public static final String SUPPORT_PATH = "/support/user/*/history";
18 public static final String PATH = "/account/history";
20 private static final int intStart = SUPPORT_PATH.indexOf('*');
22 private boolean support;
24 public History(boolean support) {
25 super(support ? "Support History" : "History");
26 this.support = support;
30 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32 HashMap<String, Object> vars = new HashMap<>();
34 String info = req.getPathInfo();
35 int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
41 vars.put("username", u.getPreferredName().toString());
45 String[] adminLog = u.getAdminLog();
46 vars.put("entries", new OutputableArrayIterable(adminLog, "entry"));
47 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
51 public boolean isPermitted(AuthorizationContext ac) {
52 return ac != null && ( !support || ac.canSupport());