diff --git a/pom.xml b/pom.xml index 7023c6d..875c21e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.example Widerhall - 0.2.15 + 0.2.16 diff --git a/src/main/java/de/srsoftware/widerhall/web/Web.java b/src/main/java/de/srsoftware/widerhall/web/Web.java index f2afac1..617fef5 100644 --- a/src/main/java/de/srsoftware/widerhall/web/Web.java +++ b/src/main/java/de/srsoftware/widerhall/web/Web.java @@ -178,17 +178,14 @@ public class Web extends TemplateServlet { } private String handleGet(HttpServletRequest req, HttpServletResponse resp) { - var path = req.getPathInfo(); - if (path == null) return redirectTo(INDEX,resp); - var o = req.getSession().getAttribute("user"); - User user = o instanceof User ? (User) o : null; + var path = Util.getPath(req); + var user = Util.getUser(req); var data = new HashMap(); + var list = Util.getMailingList(req); + if (user != null) data.put(USER,user.safeMap()); - path = path.equals("/") ? INDEX : path.substring(1); - String notes = null; - var listEmail = req.getParameter(LIST); - var list = MailingList.load(listEmail); if (list != null) data.put(LIST,list.minimalMap()); + String notes = null; switch (path){ case ARCHIVE: return archive(req,resp); @@ -206,7 +203,7 @@ public class Web extends TemplateServlet { return loadTemplate(path,data,resp); case SUBSCRIBE: if (list.isOpenFor(user)) { - data.put(LIST,listEmail); + data.put(LIST,list.email()); return loadTemplate(path, data, resp); } return t("You are not allowed to subscribe to '{}'!",list.email()); @@ -258,9 +255,7 @@ public class Web extends TemplateServlet { } private String handlePost(HttpServletRequest req, HttpServletResponse resp) { - final var user = Util.getUser(req); final var path = Util.getPath(req); - final var list = Util.getMailingList(req); switch (path){ case ADD_LIST: @@ -382,14 +377,13 @@ public class Web extends TemplateServlet { var name = req.getParameter(NAME); var email = req.getParameter(EMAIL); var pass = req.getParameter(PASSWORD); - var listEmail = req.getParameter(LIST); + var list = Util.getMailingList(req); var data = new HashMap(); data.put(NAME,name); data.put(EMAIL,email); - data.put(LIST,listEmail); + if (list != null) data.put(LIST,list.email()); var skipConfirmation = false; - var list = MailingList.load(listEmail); if (list == null){ data.put(ERROR,"No list provided by form data!"); @@ -454,24 +448,19 @@ public class Web extends TemplateServlet { var data = new HashMap(); var user = getSessionUser(req); var email = req.getParameter(EMAIL); - var pass = req.getParameter(PASSWORD); - var listEmail = req.getParameter(LIST); + var list = Util.getMailingList(req); data.put(EMAIL,email); - data.put(LIST,listEmail); - - var list = MailingList.load(listEmail); - if (user != null) data.put(USER,user.safeMap()); if (list == null){ data.put(ERROR,"No list provided by form data!"); return loadTemplate(UNSUBSCRIBE,data,resp); - - } + } else data.put(LIST,list.email()); if (user == null) { if (email == null || email.isBlank()) { data.put(ERROR, "Email is required for list un-subscription!"); return loadTemplate(UNSUBSCRIBE, data, resp); } + var pass = req.getParameter(PASSWORD); if (pass != null && pass.isBlank()) pass = null; try { diff --git a/static/templates/css.st b/static/templates/css.st index 606bcdb..d44e55a 100644 --- a/static/templates/css.st +++ b/static/templates/css.st @@ -4,7 +4,8 @@ label { } #login form, -#register form{ +#register form, +#subscribe form{ width: 450px; margin: 0 auto; } diff --git a/static/templates/js.st b/static/templates/js.st index 7456975..0199ac1 100644 --- a/static/templates/js.st +++ b/static/templates/js.st @@ -142,18 +142,17 @@ function showListList(data){ for (let i in data.lists){ let list = data.lists[i]; let row = $(''); - $('').html(''+list.name+'').appendTo(row); - $('',{class:'right'}).text(list.email.prefix).appendTo(row); - $('',{class:'right'}).text('@').appendTo(row); - $('').text(list.email.domain).appendTo(row); + let email = list.email.prefix + '@' + list.email.domain; + $('').html(''+list.name+'').appendTo(row); + $('').text(email).appendTo(row); let states = []; for (let state in list.state){ if (list.state[state] > 0) states.push(state); } $('').text(states.toString()).appendTo(row); let td = $('',{class:'actions'}); - $('