started working on pulblic pages
This commit is contained in:
@@ -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<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 {
|
||||
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 {
|
||||
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);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<link rel="stylesheet" href="css" />
|
||||
</head>
|
||||
<body id="login">
|
||||
«navigation()»
|
||||
«userinfo()»
|
||||
<h1>Widerhall List Creation</h1>
|
||||
«messages()»
|
||||
|
||||
17
static/templates/admin.st
Normal file
17
static/templates/admin.st
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script src="jquery"></script>
|
||||
<script src="js"></script>
|
||||
<link rel="stylesheet" href="css" />
|
||||
</head>
|
||||
<body>
|
||||
«navigation()»
|
||||
«userinfo()»
|
||||
<h1>Widerhall Administration</h1>
|
||||
«messages()»
|
||||
«userlist()»
|
||||
«listlist()»
|
||||
</body>
|
||||
</html>
|
||||
@@ -6,10 +6,10 @@
|
||||
<script src="js"></script>
|
||||
<link rel="stylesheet" href="css" />
|
||||
</head>
|
||||
<body>
|
||||
<body id="login">
|
||||
«navigation()»
|
||||
«userinfo()»
|
||||
«messages()»
|
||||
«userlist()»
|
||||
«listlist()»
|
||||
<h1>Widerhall Index page</h1>
|
||||
</body>
|
||||
</html>
|
||||
5
static/templates/navigation.st
Normal file
5
static/templates/navigation.st
Normal file
@@ -0,0 +1,5 @@
|
||||
<nav>
|
||||
<a href="index">Home</a>
|
||||
<a href="admin">Administration</a>
|
||||
<a class="button" href="reload" />Reload templates</a>
|
||||
</nav>
|
||||
@@ -7,6 +7,7 @@
|
||||
<link rel="stylesheet" href="css" />
|
||||
</head>
|
||||
<body id="login">
|
||||
«navigation()»
|
||||
«userinfo()»
|
||||
<h1>Widerhall user registration</h1>
|
||||
«messages()»
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
«if(data.user)»
|
||||
<div class="user">
|
||||
Logged in as <em>«data.user.name»</em>
|
||||
<a class="button" href="reload" />Reload templates</a>
|
||||
|
||||
<a class="button" href="logout" />Logout</a>
|
||||
</div>
|
||||
«endif»
|
||||
Reference in New Issue
Block a user