working on list submission
This commit is contained in:
@@ -123,6 +123,10 @@ public class MailingList {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isOpen(String list) {
|
||||||
|
return openLists().stream().filter(ml -> ml.email.equals(list)).count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Object> safeMap() {
|
public Map<String, Object> safeMap() {
|
||||||
var map = new HashMap<String,Object>();
|
var map = new HashMap<String,Object>();
|
||||||
String[] parts = email.split("@", 2);
|
String[] parts = email.split("@", 2);
|
||||||
@@ -163,4 +167,7 @@ public class MailingList {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String email() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 SUBSCRIBE = "subscribe";
|
||||||
private static final String RELOAD = "reload";
|
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";
|
||||||
@@ -153,14 +154,22 @@ public class Web extends HttpServlet {
|
|||||||
case "css":
|
case "css":
|
||||||
case INDEX:
|
case INDEX:
|
||||||
return loadTemplate(path,data,resp);
|
return loadTemplate(path,data,resp);
|
||||||
|
case SUBSCRIBE:
|
||||||
|
var list = req.getParameter(LIST);
|
||||||
|
// TODO check permission
|
||||||
|
if (MailingList.isOpen(list)) {
|
||||||
|
data.put(LIST, list);
|
||||||
|
return loadTemplate(path, data, resp);
|
||||||
|
}
|
||||||
|
return t("You are not allowed to subscribe to '{}'!",list);
|
||||||
case "js":
|
case "js":
|
||||||
resp.setContentType("text/javascript");
|
resp.setContentType("text/javascript");
|
||||||
return loadTemplate(path,null,resp);
|
return loadTemplate(path,data,resp);
|
||||||
case LOGIN:
|
case LOGIN:
|
||||||
try {
|
try {
|
||||||
if (User.noUsers()) return loadTemplate(REGISTER, Map.of(NOTES,t("User database is empty. Create admin user first:")), resp);
|
if (User.noUsers()) return loadTemplate(REGISTER, Map.of(NOTES,t("User database is empty. Create admin user first:")), resp);
|
||||||
return loadTemplate(path,null,resp);
|
return loadTemplate(path,null,resp);
|
||||||
} catch (SQLException throwables) {
|
} catch (SQLException e) {
|
||||||
return "Error reading user database!";
|
return "Error reading user database!";
|
||||||
}
|
}
|
||||||
case LOGOUT:
|
case LOGOUT:
|
||||||
@@ -204,12 +213,14 @@ public class Web extends HttpServlet {
|
|||||||
var path = req.getPathInfo();
|
var path = req.getPathInfo();
|
||||||
path = path == null ? INDEX : path.substring(1);
|
path = path == null ? INDEX : path.substring(1);
|
||||||
switch (path){
|
switch (path){
|
||||||
|
case ADD_LIST:
|
||||||
|
return addList(req,resp);
|
||||||
case LOGIN:
|
case LOGIN:
|
||||||
return handleLogin(req,resp);
|
return handleLogin(req,resp);
|
||||||
case REGISTER:
|
case REGISTER:
|
||||||
return registerUser(req,resp);
|
return registerUser(req,resp);
|
||||||
case ADD_LIST:
|
case SUBSCRIBE:
|
||||||
return addList(req,resp);
|
return subscribe(req,resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return t("No handler for path {}!",path);
|
return t("No handler for path {}!",path);
|
||||||
@@ -293,5 +304,25 @@ public class Web extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String subscribe(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
|
var name = req.getParameter(NAME);
|
||||||
|
var email = req.getParameter(EMAIL);
|
||||||
|
var pass = req.getParameter(PASSWORD);
|
||||||
|
var list = req.getParameter(LIST);
|
||||||
|
var data = new HashMap<String,String>();
|
||||||
|
data.put(NAME,name);
|
||||||
|
data.put(EMAIL,email);
|
||||||
|
data.put(PASSWORD,pass);
|
||||||
|
data.put(LIST,list);
|
||||||
|
if (list == null || list.isBlank()){
|
||||||
|
data.put(ERROR,"No list provided by form data!");
|
||||||
|
return loadTemplate(SUBSCRIBE,data,resp);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (name == null || name.isBlank() || email == null || email.isBlank()){
|
||||||
|
data.put(ERROR,"Name and email are required fields for list subscription!");
|
||||||
|
return loadTemplate(SUBSCRIBE,data,resp);
|
||||||
|
}
|
||||||
|
return "not implemented";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ function start(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function subscribeTo(domain,prefix){
|
function subscribeTo(domain,prefix){
|
||||||
window.location.href='subscribe/'+prefix+'@'+domain;
|
window.location.href='subscribe?list='+prefix+'@'+domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
34
static/templates/subscribe.st
Normal file
34
static/templates/subscribe.st
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<script src="jquery"></script>
|
||||||
|
<script src="js"></script>
|
||||||
|
<link rel="stylesheet" href="css" />
|
||||||
|
</head>
|
||||||
|
<body id="login">
|
||||||
|
«navigation()»
|
||||||
|
«userinfo()»
|
||||||
|
«messages()»
|
||||||
|
<h1>Widerhall Subscription</h1>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="list" value="«data.list»" />
|
||||||
|
<fieldset>
|
||||||
|
<legend>Suscribe to "«data.list»"</legend>
|
||||||
|
<label>
|
||||||
|
<input type="text" name="name" value="«data.name»">
|
||||||
|
Name
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="text" name="email" value="«data.email»">
|
||||||
|
Email
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="password" name="password">
|
||||||
|
Password (optional)
|
||||||
|
</label>
|
||||||
|
<button type="submit">Subscribe</button>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user