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