ADD: Mail delete
authorJanis Streib <janis@dogcraft.de>
Thu, 24 Jul 2014 21:32:38 +0000 (23:32 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 24 Jul 2014 23:44:44 +0000 (01:44 +0200)
src/org/cacert/gigi/User.java
src/org/cacert/gigi/pages/account/MailManagementForm.java
src/org/cacert/gigi/pages/account/MailOverview.java

index 2c1178171c797a2b32fbcab0058ea869940d8f06..0eed2b8c501cfd93aa20754535a20f5e3464c66a 100644 (file)
@@ -287,4 +287,17 @@ public class User {
                        e.printStackTrace();
                }
        }
+
+       public void deleteEmail(EmailAddress mail) {
+               if (getEmail().equals(mail.getAddress())) {
+                       throw new IllegalArgumentException("Can't delete user's default e-mail.");
+               }
+               try {
+                       PreparedStatement ps = DatabaseConnection.getInstance().prepare("DELETE FROM email WHERE id=?");
+                       ps.setInt(1, mail.getId());
+                       ps.execute();
+               } catch (SQLException e) {
+                       e.printStackTrace();
+               }
+       }
 }
index 842ad051f8e9f5f9969fae13fb5498b51cda9812..c6a96543251300f08f77a4e3565d8b61d366b752 100644 (file)
@@ -27,7 +27,11 @@ public class MailManagementForm extends Form {
        public boolean submit(PrintWriter out, HttpServletRequest req) {
                if (req.getParameter("makedefault") != null) {
                        try {
-                               target.updateDefaultEmail(EmailAddress.getById(Integer.parseInt(req.getParameter("emailid").trim())));
+                               String mailid = req.getParameter("emailid");
+                               if (mailid == null) {
+                                       return false;
+                               }
+                               target.updateDefaultEmail(EmailAddress.getById(Integer.parseInt(mailid.trim())));
                        } catch (Exception e) {
                                out.println("<b>Error precessing your request.</b>");
                                e.printStackTrace();
@@ -35,6 +39,23 @@ public class MailManagementForm extends Form {
                        }
                        return true;
                }
+               if (req.getParameter("delete") != null) {
+                       String[] toDel = req.getParameterValues("delid[]");
+                       if (toDel == null) {
+                               return false;
+                       }
+                       for (int i = 0; i < toDel.length; i++) {
+                               try {
+                                       target.deleteEmail(EmailAddress.getById(Integer.parseInt(toDel[i].trim())));
+                               } catch (Exception e) {
+                                       out.println("<b>Error precessing your request.</b>");
+                                       e.printStackTrace();
+                                       return false;
+                               }
+                       }
+                       return true;
+
+               }
                return false;
        }
 
index a1360531f1a45cd097806bd4935a63e218617d44..7fd5a7faf2337c65ee7ed5c407127ee303c6a873 100644 (file)
@@ -46,7 +46,6 @@ public class MailOverview extends Page {
                                resp.sendRedirect(MailOverview.DEFAULT_PATH);
                        }
                } else if (req.getParameter("makedefault") != null || req.getParameter("delete") != null) {
-                       System.out.println("MakeDefault/Delete");
                        MailManagementForm f = Form.getForm(req, MailManagementForm.class);
                        f.submit(out, req);
                }