diff --git a/src/main/java/de/srsoftware/widerhall/web/Web.java b/src/main/java/de/srsoftware/widerhall/web/Web.java index 3827408..ef3509d 100644 --- a/src/main/java/de/srsoftware/widerhall/web/Web.java +++ b/src/main/java/de/srsoftware/widerhall/web/Web.java @@ -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 { 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(); + 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 { return loadFile("jquery-3.6.0.min.js",resp); } - var o = req.getSession().getAttribute("user"); - if (o instanceof User user){ - var data = new HashMap(); - 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 { 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); diff --git a/static/templates/add_list.st b/static/templates/add_list.st index bd91f0a..f855957 100644 --- a/static/templates/add_list.st +++ b/static/templates/add_list.st @@ -7,6 +7,7 @@ + «navigation()» «userinfo()»

Widerhall List Creation

«messages()» diff --git a/static/templates/admin.st b/static/templates/admin.st new file mode 100644 index 0000000..c657e55 --- /dev/null +++ b/static/templates/admin.st @@ -0,0 +1,17 @@ + + + + + + + + + + «navigation()» + «userinfo()» +

Widerhall Administration

+ «messages()» + «userlist()» + «listlist()» + + \ No newline at end of file diff --git a/static/templates/index.st b/static/templates/index.st index d6f570f..40ebffc 100644 --- a/static/templates/index.st +++ b/static/templates/index.st @@ -6,10 +6,10 @@ - + + «navigation()» «userinfo()» «messages()» - «userlist()» - «listlist()» +

Widerhall Index page

\ No newline at end of file diff --git a/static/templates/navigation.st b/static/templates/navigation.st new file mode 100644 index 0000000..5f76d05 --- /dev/null +++ b/static/templates/navigation.st @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/static/templates/register.st b/static/templates/register.st index 55caea3..c0b64e1 100644 --- a/static/templates/register.st +++ b/static/templates/register.st @@ -7,6 +7,7 @@ + «navigation()» «userinfo()»

Widerhall user registration

«messages()» diff --git a/static/templates/userinfo.st b/static/templates/userinfo.st index b25c1f6..9da6d04 100644 --- a/static/templates/userinfo.st +++ b/static/templates/userinfo.st @@ -1,7 +1,7 @@ «if(data.user)»
Logged in as «data.user.name» - Reload templates + Logout
«endif» \ No newline at end of file