|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package de.srsoftware.widerhall.web; |
|
|
|
package de.srsoftware.widerhall.web; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.widerhall.Configuration; |
|
|
|
import de.srsoftware.widerhall.Configuration; |
|
|
|
|
|
|
|
import de.srsoftware.widerhall.Constants; |
|
|
|
import de.srsoftware.widerhall.Util; |
|
|
|
import de.srsoftware.widerhall.Util; |
|
|
|
import de.srsoftware.widerhall.data.ListMember; |
|
|
|
import de.srsoftware.widerhall.data.ListMember; |
|
|
|
import de.srsoftware.widerhall.data.MailingList; |
|
|
|
import de.srsoftware.widerhall.data.MailingList; |
|
|
|
@ -30,6 +31,7 @@ public class Web extends HttpServlet { |
|
|
|
private static final String ADD_LIST = "add_list"; |
|
|
|
private static final String ADD_LIST = "add_list"; |
|
|
|
private static final String CONFIRM = "confirm"; |
|
|
|
private static final String CONFIRM = "confirm"; |
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Web.class); |
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Web.class); |
|
|
|
|
|
|
|
private static final String ADMIN = "admin"; |
|
|
|
private static final String LOGIN = "login"; |
|
|
|
private static final String LOGIN = "login"; |
|
|
|
private static final String LOGOUT = "logout"; |
|
|
|
private static final String LOGOUT = "logout"; |
|
|
|
private static final String REGISTER = "register"; |
|
|
|
private static final String REGISTER = "register"; |
|
|
|
@ -58,10 +60,17 @@ public class Web extends HttpServlet { |
|
|
|
private String addList(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
private String addList(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
|
|
|
|
|
|
|
|
var o = req.getSession().getAttribute(USER); |
|
|
|
var o = req.getSession().getAttribute(USER); |
|
|
|
if (o instanceof User user){ |
|
|
|
if (!(o instanceof User user)) { |
|
|
|
|
|
|
|
return redirectTo(LOGIN,resp); |
|
|
|
|
|
|
|
} |
|
|
|
var data = new HashMap<String, Object>(); |
|
|
|
var data = new HashMap<String, Object>(); |
|
|
|
data.put(USER, user); |
|
|
|
data.put(USER, user); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!user.hashPermission(User.PERMISSION_CREATE_LISTS)){ |
|
|
|
|
|
|
|
data.put(ERROR,t("You are not allowed to create new mailing lists!")); |
|
|
|
|
|
|
|
return loadTemplate(ADMIN,data,resp); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var name = req.getParameter(NAME); |
|
|
|
var name = req.getParameter(NAME); |
|
|
|
data.put(NAME, name); |
|
|
|
data.put(NAME, name); |
|
|
|
|
|
|
|
|
|
|
|
@ -130,9 +139,6 @@ public class Web extends HttpServlet { |
|
|
|
return t("Failed to create list '{}': {}", name, e.getMessage()); |
|
|
|
return t("Failed to create list '{}': {}", name, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return redirectTo(LOGIN,resp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String confirm(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
private String confirm(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -181,8 +187,9 @@ public class Web extends HttpServlet { |
|
|
|
var path = req.getPathInfo(); |
|
|
|
var path = req.getPathInfo(); |
|
|
|
path = (path == null || path.equals("/")) ? INDEX : path.substring(1); |
|
|
|
path = (path == null || path.equals("/")) ? INDEX : path.substring(1); |
|
|
|
String notes = null; |
|
|
|
String notes = null; |
|
|
|
var list = req.getParameter(LIST); |
|
|
|
var listEmail = req.getParameter(LIST); |
|
|
|
if (list != null && !list.isBlank()) data.put(LIST,list); |
|
|
|
var list = MailingList.load(listEmail); |
|
|
|
|
|
|
|
if (list != null) data.put(LIST,list.minimalMap()); |
|
|
|
switch (path){ |
|
|
|
switch (path){ |
|
|
|
case CONFIRM: |
|
|
|
case CONFIRM: |
|
|
|
return confirm(req,resp); |
|
|
|
return confirm(req,resp); |
|
|
|
@ -195,12 +202,11 @@ public class Web extends HttpServlet { |
|
|
|
case UNSUBSCRIBE: |
|
|
|
case UNSUBSCRIBE: |
|
|
|
return loadTemplate(path,data,resp); |
|
|
|
return loadTemplate(path,data,resp); |
|
|
|
case SUBSCRIBE: |
|
|
|
case SUBSCRIBE: |
|
|
|
// TODO check permission
|
|
|
|
if (list.isOpenFor(user)) { |
|
|
|
if (MailingList.isOpen(list)) { |
|
|
|
data.put(LIST,listEmail); |
|
|
|
data.put(LIST, list); |
|
|
|
|
|
|
|
return loadTemplate(path, data, resp); |
|
|
|
return loadTemplate(path, data, resp); |
|
|
|
} |
|
|
|
} |
|
|
|
return t("You are not allowed to subscribe to '{}'!",list); |
|
|
|
return t("You are not allowed to subscribe to '{}'!",list.email()); |
|
|
|
case "js": |
|
|
|
case "js": |
|
|
|
resp.setContentType("text/javascript"); |
|
|
|
resp.setContentType("text/javascript"); |
|
|
|
return loadTemplate(path,data,resp); |
|
|
|
return loadTemplate(path,data,resp); |
|
|
|
@ -326,12 +332,9 @@ public class Web extends HttpServlet { |
|
|
|
if (!pass.equals(pass_repeat)) return loadTemplate(REGISTER,Map.of(ERROR,"Passwords do not match!",NAME,name,EMAIL,email),resp); |
|
|
|
if (!pass.equals(pass_repeat)) return loadTemplate(REGISTER,Map.of(ERROR,"Passwords do not match!",NAME,name,EMAIL,email),resp); |
|
|
|
if (Util.simplePassword(pass)) return loadTemplate(REGISTER,Map.of(ERROR,"Password to short or to simple!",NAME,name,EMAIL,email),resp); |
|
|
|
if (Util.simplePassword(pass)) return loadTemplate(REGISTER,Map.of(ERROR,"Password to short or to simple!",NAME,name,EMAIL,email),resp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var firstUser = false; |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (User.noUsers()) { // we are registering the first user, which is forced to be „Admin“
|
|
|
|
firstUser = User.noUsers(); |
|
|
|
name = ADMIN; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (ADMIN.equals(name)) return loadTemplate(REGISTER,Map.of(ERROR,t("Name must not be „{}“",ADMIN),NAME,name,EMAIL,email),resp); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
return t("Failed to access user database: {}",e.getMessage()); |
|
|
|
return t("Failed to access user database: {}",e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -339,9 +342,11 @@ public class Web extends HttpServlet { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
var user = User.create(email, name, pass); |
|
|
|
var user = User.create(email, name, pass); |
|
|
|
|
|
|
|
if (firstUser) user.addPermission(User.PERMISSION_ADMIN|User.PERMISSION_CREATE_LISTS); |
|
|
|
req.getSession().setAttribute("user",user); |
|
|
|
req.getSession().setAttribute("user",user); |
|
|
|
return redirectTo(INDEX,resp); |
|
|
|
return redirectTo(INDEX,resp); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
LOG.warn("Failed to create new user:",e); |
|
|
|
return t("Failed to create new user: {}",e.getMessage()); |
|
|
|
return t("Failed to create new user: {}",e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -388,6 +393,11 @@ public class Web extends HttpServlet { |
|
|
|
} |
|
|
|
} |
|
|
|
data.put(USER,user.safeMap()); |
|
|
|
data.put(USER,user.safeMap()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!list.isOpenFor(user)){ |
|
|
|
|
|
|
|
data.put(ERROR,t("You are not allowed to join {}!",list.email())); |
|
|
|
|
|
|
|
return loadTemplate(SUBSCRIBE,data,resp); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
list.requestSubscription(user,skipConfirmation); |
|
|
|
list.requestSubscription(user,skipConfirmation); |
|
|
|
data.put(NOTES,t("Successfully subscribed '{}' to '{}'.",user.email(),list.email())); |
|
|
|
data.put(NOTES,t("Successfully subscribed '{}' to '{}'.",user.email(),list.email())); |
|
|
|
@ -454,6 +464,4 @@ public class Web extends HttpServlet { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|