working on configuration
This commit is contained in:
@@ -6,7 +6,7 @@ import de.srsoftware.widerhall.data.User;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupDir;
|
||||
import org.stringtemplate.v4.STRawGroupDir;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
@@ -19,17 +19,19 @@ import java.util.Map;
|
||||
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
|
||||
public class Static extends HttpServlet {
|
||||
public class Web extends HttpServlet {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Static.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||
private static final String LOGIN = "login";
|
||||
private final String baseDir;
|
||||
private final STGroup templates;
|
||||
private static final String WEB_ROOT = "/web";
|
||||
|
||||
public Static(){
|
||||
public Web(){
|
||||
var config = Configuration.instance();
|
||||
baseDir = config.baseDir();
|
||||
var templateDir = String.join(File.separator,baseDir,"templates");
|
||||
templates = new STGroupDir(templateDir,'{','}');
|
||||
var templateDir = String.join(File.separator,baseDir,"static","templates");
|
||||
templates = new STRawGroupDir(templateDir,'«','»');
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,13 +45,11 @@ public class Static extends HttpServlet {
|
||||
path = path == null ? "index" : path.substring(1);
|
||||
switch (path){
|
||||
case "css":
|
||||
return loadFile("style.css",resp);
|
||||
case "js":
|
||||
return loadFile("widerhall.js",resp);
|
||||
case "login":
|
||||
return loadTemplate(path,null,resp);
|
||||
case "jquery":
|
||||
return loadFile("jquery-3.6.0.min.js",resp);
|
||||
case "login":
|
||||
return loadTemplate(path, null, resp);
|
||||
}
|
||||
|
||||
var u = req.getSession().getAttribute("user");
|
||||
@@ -77,7 +77,7 @@ public class Static extends HttpServlet {
|
||||
|
||||
private String loginRedirect(HttpServletResponse resp) {
|
||||
try {
|
||||
resp.sendRedirect("/static/login");
|
||||
resp.sendRedirect(String.join("/",WEB_ROOT,LOGIN));
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return t("Was not able to redirect to login page: {}", e.getMessage());
|
||||
@@ -123,7 +123,7 @@ public class Static extends HttpServlet {
|
||||
try {
|
||||
var user = User.load(email,pass);
|
||||
req.getSession().setAttribute("user",user);
|
||||
resp.sendRedirect("/static");
|
||||
resp.sendRedirect(String.join("/",WEB_ROOT,"index"));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
LOG.warn("Static.handleLogin failed:",e);
|
||||
Reference in New Issue
Block a user