Added mailOverview (form dummy)
authorJanis Streib <janis@dogcraft.de>
Fri, 27 Jun 2014 08:34:10 +0000 (10:34 +0200)
committerJanis Streib <janis@dogcraft.de>
Fri, 27 Jun 2014 08:34:34 +0000 (10:34 +0200)
src/org/cacert/gigi/Gigi.java
src/org/cacert/gigi/output/MailTable.java
src/org/cacert/gigi/pages/account/MailOverview.java

index 39af0f7..8cc076e 100644 (file)
@@ -24,6 +24,7 @@ import org.cacert.gigi.pages.PolicyRedir;
 import org.cacert.gigi.pages.TestSecure;
 import org.cacert.gigi.pages.Verify;
 import org.cacert.gigi.pages.account.MailCertificates;
+import org.cacert.gigi.pages.account.MailOverview;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.pages.main.RegisterPage;
 import org.cacert.gigi.pages.wot.AssurePage;
@@ -51,6 +52,8 @@ public class Gigi extends HttpServlet {
                pages.put(MyDetails.PATH, new MyDetails());
                pages.put(RegisterPage.PATH, new RegisterPage());
                pages.put(PolicyRedir.PATH, new PolicyRedir());
+               pages.put(MailOverview.DEFAULT_PATH, new MailOverview(
+                               "My email addresses"));
                String templ = "";
                try (BufferedReader reader = new BufferedReader(new InputStreamReader(
                                new FileInputStream(new File("templates/base.html"))))) {
index 2eed4af..5e310b7 100644 (file)
@@ -1,6 +1,8 @@
 package org.cacert.gigi.output;
 
 import java.io.PrintWriter;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.LinkedList;
 import java.util.Map;
 
@@ -8,20 +10,52 @@ import org.cacert.gigi.Language;
 import org.cacert.gigi.output.DataTable.Cell;
 
 public class MailTable implements Outputable {
+       private String resultSet, userMail;
+
+       public MailTable(String key, String userMail) {
+               this.resultSet = key;
+               this.userMail = userMail;
+       }
 
        @Override
        public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+               ResultSet rs = (ResultSet) vars.get(resultSet);
+               String userMail = (String) vars.get(this.userMail);
                LinkedList<Cell> cells = new LinkedList<>();
                cells.add(new Cell("Email Accounts", true, 4, "class=\"title\""));
                cells.add(new Cell("Default", true));
-               cells.add(new Cell("Delete", true));
                cells.add(new Cell("Status", true));
+               cells.add(new Cell("Delete", true));
                cells.add(new Cell("Address", true));
-
+               try {
+                       rs.beforeFirst();
+                       while (rs.next()) {
+                               cells.add(new Cell());
+                               cells.add(new Cell(
+                                               rs.getString("hash").trim().isEmpty() ? "Verified"
+                                                               : "Unverified", true));
+                               if (rs.getString("email").equals(userMail)) {
+                                       cells.add(new Cell(
+                                                       "N/A"
+                                                                       , true));
+                               } else {
+                                       cells.add(new Cell("<input type=\"checkbox\" name=\"delid[]\" value=\""
+                                                                                       + rs.getInt("id") + "\">", false));
+                               }
+                               cells.add(new Cell(rs.getString("email"), false));
+                       }
+               } catch (SQLException e) {
+                       e.printStackTrace();
+               }
+               String trans = l.getTranslation("Make Default");
+               cells.add(new Cell(
+                               "<input type=\"submit\" name=\"makedefault\" value=\"" + trans
+                                               + "\">", false, 2));
+               trans = l.getTranslation("Delete");
+               cells.add(new Cell("<input type=\"submit\" name=\"process\" value=\""
+                               + trans + "\">", false, 2));
                DataTable t = new DataTable(4, cells);
                t.output(out, l, vars);
        }
 
-
-
 }
index f165cc1..edc88c9 100644 (file)
@@ -1,17 +1,23 @@
 package org.cacert.gigi.pages.account;
 
 import java.io.IOException;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.HashMap;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.cacert.gigi.User;
+import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.output.MailTable;
+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 table = new MailTable("mails", "userMail");
        public MailOverview(String title) {
                super(title);
        }
@@ -20,8 +26,20 @@ public class MailOverview extends Page {
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {
                HashMap<String, Object> vars = new HashMap<String, Object>();
-
-               new MailTable().output(resp.getWriter(), getLanguage(req), vars);
+               User us = LoginPage.getUser(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();
+                       vars.put("mails", rs);
+                       vars.put("userMail", us.getEmail());
+
+               } catch (SQLException e) {
+                       e.printStackTrace();
+               }
+               table.output(resp.getWriter(), getLanguage(req), vars);
 
        }