working on list administration
This commit is contained in:
@@ -28,13 +28,14 @@ import static de.srsoftware.widerhall.Util.t;
|
||||
|
||||
public class Web extends HttpServlet {
|
||||
private static final String ADD_LIST = "add_list";
|
||||
private static final String CONFIRM = "confirm";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||
private static final String LOGIN = "login";
|
||||
private static final String LOGOUT = "logout";
|
||||
private static final String REGISTER = "register";
|
||||
private static final String RELOAD = "reload";
|
||||
private static final String SUBSCRIBE = "subscribe";
|
||||
private static final String UNSUBSCRIBE = "unsubscribe";
|
||||
private static final String RELOAD = "reload";
|
||||
private static final String IMAP_HOST = "imap_host";
|
||||
private static final String IMAP_PORT = "imap_port";
|
||||
private static final String IMAP_USER = "imap_user";
|
||||
@@ -128,6 +129,19 @@ public class Web extends HttpServlet {
|
||||
|
||||
}
|
||||
|
||||
private String confirm(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
var token = req.getParameter(TOKEN);
|
||||
if (token== null || token.isBlank()) return t("Invalid or missing token!");
|
||||
var user = ListMember.confirm(token);
|
||||
if (user != null) return loadTemplate(INDEX,Map.of(USER,user.safeMap(),NOTES,"Confirmed list subscription!"),resp);
|
||||
return t("Unknown user");
|
||||
} catch (SQLException e) {
|
||||
LOG.debug("Failed to confirm list membership:",e);
|
||||
return t("Confirmation of list membership failed!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
@@ -150,6 +164,10 @@ public class Web extends HttpServlet {
|
||||
return sqle;
|
||||
}
|
||||
|
||||
private User getSessionUser(HttpServletRequest req) {
|
||||
return req.getSession().getAttribute(USER) instanceof User user ? user : null;
|
||||
}
|
||||
|
||||
private String handleGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var o = req.getSession().getAttribute("user");
|
||||
User user = o instanceof User ? (User) o : null;
|
||||
@@ -161,6 +179,8 @@ public class Web extends HttpServlet {
|
||||
var list = req.getParameter(LIST);
|
||||
if (list != null && !list.isBlank()) data.put(LIST,list);
|
||||
switch (path){
|
||||
case CONFIRM:
|
||||
return confirm(req,resp);
|
||||
case RELOAD:
|
||||
loadTemplates();
|
||||
data.put(NOTES,t("Templates have been reloaded"));
|
||||
@@ -203,6 +223,7 @@ public class Web extends HttpServlet {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String handleLogin(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var email = req.getParameter("email");
|
||||
var pass = req.getParameter("pass");
|
||||
@@ -218,7 +239,7 @@ public class Web extends HttpServlet {
|
||||
LOG.warn("Static.handleLogin failed:",e);
|
||||
Thread.sleep(10000);
|
||||
} finally {
|
||||
return loadTemplate("login", Map.of("error",t("Invalid username/password")), resp);
|
||||
return loadTemplate("login", Map.of(ERROR,t("Invalid username/password"),EMAIL,email), resp);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -429,7 +450,5 @@ public class Web extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private User getSessionUser(HttpServletRequest req) {
|
||||
return req.getSession().getAttribute(USER) instanceof User user ? user : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user