first version with working archive
This commit is contained in:
@@ -3,6 +3,7 @@ package de.srsoftware.widerhall.web;
|
||||
import de.srsoftware.widerhall.Util;
|
||||
import de.srsoftware.widerhall.data.ListMember;
|
||||
import de.srsoftware.widerhall.data.MailingList;
|
||||
import de.srsoftware.widerhall.data.Post;
|
||||
import de.srsoftware.widerhall.data.User;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -12,6 +13,7 @@ import javax.mail.MessagingException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
@@ -26,9 +28,11 @@ public class Web extends TemplateServlet {
|
||||
private static final String CONFIRM = "confirm";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||
private static final String ADMIN = "admin";
|
||||
private static final String ARCHIVE = "archive";
|
||||
private static final String INSPECT = "inspect";
|
||||
private static final String LOGIN = "login";
|
||||
private static final String LOGOUT = "logout";
|
||||
private static final String POST = "post";
|
||||
private static final String REGISTER = "register";
|
||||
private static final String RELOAD = "reload";
|
||||
private static final String SUBSCRIBE = "subscribe";
|
||||
@@ -130,6 +134,12 @@ public class Web extends TemplateServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private String archive(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var domain = req.getParameter(DOMAIN);
|
||||
var prefix = req.getParameter(PREFIX);
|
||||
return loadTemplate(ARCHIVE,Map.of(DOMAIN,domain,PREFIX,prefix),resp);
|
||||
}
|
||||
|
||||
private String confirm(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
var token = req.getParameter(TOKEN);
|
||||
@@ -181,8 +191,12 @@ public class Web extends TemplateServlet {
|
||||
var list = MailingList.load(listEmail);
|
||||
if (list != null) data.put(LIST,list.minimalMap());
|
||||
switch (path){
|
||||
case ARCHIVE:
|
||||
return archive(req,resp);
|
||||
case CONFIRM:
|
||||
return confirm(req,resp);
|
||||
case POST:
|
||||
return post(req,resp);
|
||||
case RELOAD:
|
||||
loadTemplates();
|
||||
data.put(NOTES,t("Templates have been reloaded"));
|
||||
@@ -223,8 +237,6 @@ public class Web extends TemplateServlet {
|
||||
return redirectTo(LOGIN,resp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String handleLogin(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var email = req.getParameter("email");
|
||||
var pass = req.getParameter("pass");
|
||||
@@ -293,7 +305,8 @@ public class Web extends TemplateServlet {
|
||||
.forwardAttached(Util.getCheckbox(req, "forward_attached"))
|
||||
.hideReceivers(Util.getCheckbox(req, "hide_receivers"))
|
||||
.replyToList(Util.getCheckbox(req, "reply_to_list"))
|
||||
.open(Util.getCheckbox(req,"open"));
|
||||
.open(Util.getCheckbox(req,"open"))
|
||||
.archive(Util.getCheckbox(req,"archive"));
|
||||
data.put(NOTES,t("Sucessfully updated MailingList!"));
|
||||
} catch (SQLException e){
|
||||
LOG.warn("Failed to update MailingList:",e);
|
||||
@@ -304,6 +317,21 @@ public class Web extends TemplateServlet {
|
||||
return loadTemplate(INSPECT,data,resp);
|
||||
}
|
||||
|
||||
private String post(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var id = req.getParameter(ID);
|
||||
if (id == null) return t("Could not find email with id!");
|
||||
try {
|
||||
var post = Post.load(id);
|
||||
var map = new HashMap<String,Object>();
|
||||
map.putAll(post.safeMap());
|
||||
String content = Files.readString(post.file().toPath());
|
||||
map.put("text",Util.dropEmail(content));
|
||||
return loadTemplate("post",map,resp);
|
||||
} catch (SQLException | IOException e) {
|
||||
LOG.debug("Failed to load post from file!",e);
|
||||
return t("Failed to load post from file!");
|
||||
}
|
||||
}
|
||||
|
||||
private String redirectTo(String page, HttpServletResponse resp) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user