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 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";
|
||||||
|
private static final String RELOAD = "reload";
|
||||||
private static final String IMAP_HOST = "imap_host";
|
private static final String IMAP_HOST = "imap_host";
|
||||||
private static final String IMAP_PORT = "imap_port";
|
private static final String IMAP_PORT = "imap_port";
|
||||||
private static final String IMAP_USER = "imap_user";
|
private static final String IMAP_USER = "imap_user";
|
||||||
@@ -135,18 +136,23 @@ public class Web extends HttpServlet {
|
|||||||
if (error != null) resp.sendError(400,error);
|
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();
|
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;
|
||||||
switch (path){
|
switch (path){
|
||||||
case "reload":
|
case RELOAD:
|
||||||
loadTemplates();
|
loadTemplates();
|
||||||
|
data.put(NOTES,t("Templates have been reloaded"));
|
||||||
path = INDEX;
|
path = INDEX;
|
||||||
notes = t("Templates have been reloaded");
|
|
||||||
break;
|
|
||||||
case "css":
|
case "css":
|
||||||
return loadTemplate(path,null,resp);
|
case INDEX:
|
||||||
|
return loadTemplate(path,data,resp);
|
||||||
case "js":
|
case "js":
|
||||||
resp.setContentType("text/javascript");
|
resp.setContentType("text/javascript");
|
||||||
return loadTemplate(path,null,resp);
|
return loadTemplate(path,null,resp);
|
||||||
@@ -165,10 +171,7 @@ public class Web extends HttpServlet {
|
|||||||
return loadFile("jquery-3.6.0.min.js",resp);
|
return loadFile("jquery-3.6.0.min.js",resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
var o = req.getSession().getAttribute("user");
|
if (user != null){
|
||||||
if (o instanceof User user){
|
|
||||||
var data = new HashMap<String,Object>();
|
|
||||||
data.put(USER,user.safeMap());
|
|
||||||
data.put(NOTES,notes);
|
data.put(NOTES,notes);
|
||||||
return loadTemplate(path,data,resp);
|
return loadTemplate(path,data,resp);
|
||||||
}
|
}
|
||||||
@@ -184,7 +187,8 @@ public class Web extends HttpServlet {
|
|||||||
try {
|
try {
|
||||||
var user = User.load(email,pass);
|
var user = User.load(email,pass);
|
||||||
req.getSession().setAttribute("user",user);
|
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) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
LOG.warn("Static.handleLogin failed:",e);
|
LOG.warn("Static.handleLogin failed:",e);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<link rel="stylesheet" href="css" />
|
<link rel="stylesheet" href="css" />
|
||||||
</head>
|
</head>
|
||||||
<body id="login">
|
<body id="login">
|
||||||
|
«navigation()»
|
||||||
«userinfo()»
|
«userinfo()»
|
||||||
<h1>Widerhall List Creation</h1>
|
<h1>Widerhall List Creation</h1>
|
||||||
«messages()»
|
«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>
|
<script src="js"></script>
|
||||||
<link rel="stylesheet" href="css" />
|
<link rel="stylesheet" href="css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body id="login">
|
||||||
|
«navigation()»
|
||||||
«userinfo()»
|
«userinfo()»
|
||||||
«messages()»
|
«messages()»
|
||||||
«userlist()»
|
<h1>Widerhall Index page</h1>
|
||||||
«listlist()»
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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" />
|
<link rel="stylesheet" href="css" />
|
||||||
</head>
|
</head>
|
||||||
<body id="login">
|
<body id="login">
|
||||||
|
«navigation()»
|
||||||
«userinfo()»
|
«userinfo()»
|
||||||
<h1>Widerhall user registration</h1>
|
<h1>Widerhall user registration</h1>
|
||||||
«messages()»
|
«messages()»
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
«if(data.user)»
|
«if(data.user)»
|
||||||
<div class="user">
|
<div class="user">
|
||||||
Logged in as <em>«data.user.name»</em>
|
Logged in as <em>«data.user.name»</em>
|
||||||
<a class="button" href="reload" />Reload templates</a>
|
|
||||||
<a class="button" href="logout" />Logout</a>
|
<a class="button" href="logout" />Logout</a>
|
||||||
</div>
|
</div>
|
||||||
«endif»
|
«endif»
|
||||||
Reference in New Issue
Block a user