|
|
|
@ -30,6 +30,7 @@ public class Web extends HttpServlet {
@@ -30,6 +30,7 @@ public class Web extends HttpServlet {
|
|
|
|
|
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 IMAP_HOST = "imap_host"; |
|
|
|
|
private static final String IMAP_PORT = "imap_port"; |
|
|
|
|
private static final String IMAP_USER = "imap_user"; |
|
|
|
@ -135,18 +136,23 @@ public class Web extends HttpServlet {
@@ -135,18 +136,23 @@ public class Web extends HttpServlet {
|
|
|
|
|
if (error != null) resp.sendError(400,error); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String handleGet(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
|
private String handleGet(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
|
var o = req.getSession().getAttribute("user"); |
|
|
|
|
User user = o instanceof User ? (User) o : null; |
|
|
|
|
var data = new HashMap<String,Object>(); |
|
|
|
|
if (user != null) data.put(USER,user.safeMap()); |
|
|
|
|
|
|
|
|
|
var path = req.getPathInfo(); |
|
|
|
|
path = (path == null || path.equals("/")) ? INDEX : path.substring(1); |
|
|
|
|
String notes = null; |
|
|
|
|
switch (path){ |
|
|
|
|
case "reload": |
|
|
|
|
case RELOAD: |
|
|
|
|
loadTemplates(); |
|
|
|
|
data.put(NOTES,t("Templates have been reloaded")); |
|
|
|
|
path = INDEX; |
|
|
|
|
notes = t("Templates have been reloaded"); |
|
|
|
|
break; |
|
|
|
|
case "css": |
|
|
|
|
return loadTemplate(path,null,resp); |
|
|
|
|
case INDEX: |
|
|
|
|
return loadTemplate(path,data,resp); |
|
|
|
|
case "js": |
|
|
|
|
resp.setContentType("text/javascript"); |
|
|
|
|
return loadTemplate(path,null,resp); |
|
|
|
@ -165,10 +171,7 @@ public class Web extends HttpServlet {
@@ -165,10 +171,7 @@ public class Web extends HttpServlet {
|
|
|
|
|
return loadFile("jquery-3.6.0.min.js",resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var o = req.getSession().getAttribute("user"); |
|
|
|
|
if (o instanceof User user){ |
|
|
|
|
var data = new HashMap<String,Object>(); |
|
|
|
|
data.put(USER,user.safeMap()); |
|
|
|
|
if (user != null){ |
|
|
|
|
data.put(NOTES,notes); |
|
|
|
|
return loadTemplate(path,data,resp); |
|
|
|
|
} |
|
|
|
@ -184,7 +187,8 @@ public class Web extends HttpServlet {
@@ -184,7 +187,8 @@ public class Web extends HttpServlet {
|
|
|
|
|
try { |
|
|
|
|
var user = User.load(email,pass); |
|
|
|
|
req.getSession().setAttribute("user",user); |
|
|
|
|
resp.sendRedirect(String.join("/",WEB_ROOT,"index")); |
|
|
|
|
// loading user successfull: goto index
|
|
|
|
|
resp.sendRedirect(String.join("/",WEB_ROOT,"admin")); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
try { |
|
|
|
|
LOG.warn("Static.handleLogin failed:",e); |
|
|
|
|