]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/mail/MailOverview.java
b828b7189d7e6fcc8b10bd966cce9cbf7023003f
[gigi.git] / src / org / cacert / gigi / pages / account / mail / MailOverview.java
1 package org.cacert.gigi.pages.account.mail;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.HashMap;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import org.cacert.gigi.GigiApiException;
11 import org.cacert.gigi.dbObjects.User;
12 import org.cacert.gigi.localisation.Language;
13 import org.cacert.gigi.output.template.Form;
14 import org.cacert.gigi.pages.Page;
15 import org.cacert.gigi.util.AuthorizationContext;
16
17 public class MailOverview extends Page {
18
19     public static final String DEFAULT_PATH = "/account/mails";
20
21     public MailOverview() {
22         super("Email addresses");
23     }
24
25     @Override
26     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
27         final User us = getUser(req);
28         Language lang = Page.getLanguage(req);
29         HashMap<String, Object> vars = new HashMap<>();
30         vars.put("addForm", new MailAddForm(req, us));
31         vars.put("manForm", new MailManagementForm(req, us));
32         getDefaultTemplate().output(resp.getWriter(), lang, vars);
33     }
34
35     @Override
36     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
37         PrintWriter out = resp.getWriter();
38         if (req.getParameter("addmail") != null) {
39             MailAddForm f = Form.getForm(req, MailAddForm.class);
40             try {
41                 if (f.submit(out, req)) {
42                     resp.sendRedirect(MailOverview.DEFAULT_PATH);
43                 }
44             } catch (GigiApiException e) {
45                 e.format(resp.getWriter(), getLanguage(req));
46             }
47         } else {
48             MailManagementForm f = Form.getForm(req, MailManagementForm.class);
49             if (f.submit(out, req)) {
50                 resp.sendRedirect(MailOverview.DEFAULT_PATH);
51             }
52         }
53         super.doPost(req, resp);
54     }
55
56     @Override
57     public boolean isPermitted(AuthorizationContext ac) {
58         return ac != null && ac.getTarget() instanceof User;
59     }
60 }