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)) {
49 new TTPAdminForm(req, u).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
53 String offsetS = req.getParameter("offset");
54 if (offsetS != null) {
55 offset = Integer.parseInt(offsetS);
58 final User[] users = TTP_APPLICANT.getMembers(offset, PAGE_LEN + 1);
59 HashMap<String, Object> vars = new HashMap<>();
60 vars.put("users", new IterableDataset() {
65 public boolean next(Language l, Map<String, Object> vars) {
66 if (i >= Math.min(PAGE_LEN, users.length)) {
69 vars.put("id", Integer.toString(users[i].getId()));
70 vars.put("name", users[i].getName().toString());
71 vars.put("email", users[i].getEmail());
77 if (users.length == PAGE_LEN + 1) {
78 vars.put("next", Integer.toString(offset + 30));
80 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
84 public boolean isPermitted(User u) {
85 return u != null && u.isInGroup(Group.getByString("ttp-assurer"));