X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2FMailOverview.java;h=7836867877245228addd832185487ee72d55c748;hb=1d24b8e1fe36651f22339ddbb7b1a3b34b48c081;hp=54eda005753ad85758dc7154731d6f234fd28766;hpb=5b276a9eb3e6d1473e7dd2891eb1d6a9fb82f6a2;p=gigi.git diff --git a/src/org/cacert/gigi/pages/account/MailOverview.java b/src/org/cacert/gigi/pages/account/MailOverview.java index 54eda005..78368678 100644 --- a/src/org/cacert/gigi/pages/account/MailOverview.java +++ b/src/org/cacert/gigi/pages/account/MailOverview.java @@ -2,97 +2,105 @@ package org.cacert.gigi.pages.account; import java.io.IOException; import java.io.PrintWriter; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.cacert.gigi.EmailAddress; import org.cacert.gigi.Language; import org.cacert.gigi.User; -import org.cacert.gigi.database.DatabaseConnection; +import org.cacert.gigi.output.Form; import org.cacert.gigi.output.Outputable; -import org.cacert.gigi.pages.LoginPage; import org.cacert.gigi.pages.Page; public class MailOverview extends Page { - public static final String DEFAULT_PATH = "/account/mails"; - private MailTable t; - public MailOverview(String title) { - super(title); - t = new MailTable("res", "us"); - } + public static final String DEFAULT_PATH = "/account/mails"; - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) - throws IOException { - final User us = LoginPage.getUser(req); - Language lang = Page.getLanguage(req); - int id = us.getId(); - try { - PreparedStatement ps = DatabaseConnection.getInstance().prepare( - "SELECT * from `email` WHERE `memid`=? AND `deleted`=0"); - ps.setInt(1, id); - ResultSet rs = ps.executeQuery(); - HashMap vars = new HashMap<>(); - vars.put("mailData", t); - vars.put("res", rs); - vars.put("us", us.getEmail()); - getDefaultTemplate().output(resp.getWriter(), lang, vars); - } catch (SQLException e) { - e.printStackTrace(); - } - } + private MailTable t; - private class MailTable implements Outputable { - private String mails, userMail; + public MailOverview(String title) { + super(title); + t = new MailTable("us"); + } - public MailTable(String mails, String userMail) { - this.mails = mails; - this.userMail = userMail; - } + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + final User us = getUser(req); + Language lang = Page.getLanguage(req); + HashMap vars = new HashMap<>(); + vars.put("mailData", t); + vars.put("us", us); + vars.put("addForm", new MailAddForm(req, us)); + vars.put("manForm", new MailManagementForm(req, us)); + getDefaultTemplate().output(resp.getWriter(), lang, vars); + } - @Override - public void output(PrintWriter out, Language l, Map vars) { - try { - ResultSet rs = (ResultSet) vars.get(mails); - String usM = (String) vars.get(userMail); - while (rs.next()) { - out.println(""); - out.println(""); - out.println(""); - if (rs.getString(7).isEmpty()) { - out.print(l.getTranslation("Verified")); - } else { - out.print(l.getTranslation("Unverified")); - } - out.print(""); - out.println(""); - String address = rs.getString(3); - if (usM.equals(address)) { - out.print(l.getTranslation("N/A")); - } else { - out.print(""); - } - out.print(""); - out.println(""); - out.print(address); - out.print(""); - out.println(""); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + PrintWriter out = resp.getWriter(); + if (req.getParameter("addmail") != null) { + MailAddForm f = Form.getForm(req, MailAddForm.class); + if (f.submit(out, req)) { + resp.sendRedirect(MailOverview.DEFAULT_PATH); + } + } else if (req.getParameter("makedefault") != null || req.getParameter("delete") != null) { + MailManagementForm f = Form.getForm(req, MailManagementForm.class); + if (f.submit(out, req)) { + resp.sendRedirect(MailOverview.DEFAULT_PATH); + } + } + super.doPost(req, resp); + } - } + private class MailTable implements Outputable { + + private String user; + + public MailTable(String user) { + this.user = user; + } + + @Override + public void output(PrintWriter out, Language l, Map vars) { + User us = (User) vars.get(user); + String usM = us.getEmail(); + EmailAddress[] emails = us.getEmails(); + + for (int i = 0; i < emails.length; i++) { + out.println(""); + out.println(""); + out.println(""); + if (emails[i].isVerified()) { + out.print(l.getTranslation("Verified")); + } else { + out.print(l.getTranslation("Unverified")); + } + out.print(""); + out.println(""); + String address = emails[i].getAddress(); + if (usM.equals(address)) { + out.print(l.getTranslation("N/A")); + } else { + out.print(""); + } + out.print(""); + out.println(""); + out.print(address); + out.print(""); + out.println(""); + } + } + } }