1 package org.cacert.gigi.pages.admin;
3 import java.io.IOException;
4 import java.util.HashMap;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import org.cacert.gigi.GigiApiException;
11 import org.cacert.gigi.dbObjects.Group;
12 import org.cacert.gigi.dbObjects.User;
13 import org.cacert.gigi.localisation.Language;
14 import org.cacert.gigi.output.Form;
15 import org.cacert.gigi.output.template.IterableDataset;
16 import org.cacert.gigi.pages.Page;
18 public class TTPAdminPage extends Page {
20 public static final String PATH = "/admin/ttp";
22 public static final Group TTP_APPLICANT = Group.getByString("ttp-applicant");
24 public TTPAdminPage() {
29 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
31 Form.getForm(req, TTPAdminForm.class).submit(resp.getWriter(), req);
32 } catch (GigiApiException e) {
33 e.format(resp.getWriter(), getLanguage(req));
35 resp.sendRedirect(PATH);
38 private static final int PAGE_LEN = 30;
41 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
42 String path = req.getPathInfo();
43 if (path != null && path.length() > PATH.length()) {
44 int id = Integer.parseInt(path.substring(1 + PATH.length()));
45 User u = User.getById(id);
46 if ( !u.isInGroup(TTP_APPLICANT)) {
50 new TTPAdminForm(req, u).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
54 String offsetS = req.getParameter("offset");
55 if (offsetS != null) {
56 offset = Integer.parseInt(offsetS);
59 final User[] users = TTP_APPLICANT.getMembers(offset, PAGE_LEN + 1);
60 HashMap<String, Object> vars = new HashMap<>();
61 vars.put("users", new IterableDataset() {
66 public boolean next(Language l, Map<String, Object> vars) {
67 if (i >= Math.min(PAGE_LEN, users.length)) {
70 vars.put("id", Integer.toString(users[i].getId()));
71 vars.put("name", users[i].getName().toString());
72 vars.put("email", users[i].getEmail());
78 if (users.length == PAGE_LEN + 1) {
79 vars.put("next", Integer.toString(offset + 30));
81 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
85 public boolean isPermitted(User u) {
86 return u != null && u.isInGroup(Group.getByString("ttp-assurer"));