Browse Source

working on list submission

drop_old_mail
Stephan Richter 3 years ago
parent
commit
853926e0f7
  1. 7
      src/main/java/de/srsoftware/widerhall/data/MailingList.java
  2. 39
      src/main/java/de/srsoftware/widerhall/web/Web.java
  3. 2
      static/templates/js.st
  4. 34
      static/templates/subscribe.st

7
src/main/java/de/srsoftware/widerhall/data/MailingList.java

@ -123,6 +123,10 @@ public class MailingList { @@ -123,6 +123,10 @@ public class MailingList {
return list;
}
public static boolean isOpen(String list) {
return openLists().stream().filter(ml -> ml.email.equals(list)).count() > 0;
}
public Map<String, Object> safeMap() {
var map = new HashMap<String,Object>();
String[] parts = email.split("@", 2);
@ -163,4 +167,7 @@ public class MailingList { @@ -163,4 +167,7 @@ public class MailingList {
return this;
}
public String email() {
return email;
}
}

39
src/main/java/de/srsoftware/widerhall/web/Web.java

@ -30,6 +30,7 @@ public class Web extends HttpServlet { @@ -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 SUBSCRIBE = "subscribe";
private static final String RELOAD = "reload";
private static final String IMAP_HOST = "imap_host";
private static final String IMAP_PORT = "imap_port";
@ -153,14 +154,22 @@ public class Web extends HttpServlet { @@ -153,14 +154,22 @@ public class Web extends HttpServlet {
case "css":
case INDEX:
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":
resp.setContentType("text/javascript");
return loadTemplate(path,null,resp);
return loadTemplate(path,data,resp);
case LOGIN:
try {
if (User.noUsers()) return loadTemplate(REGISTER, Map.of(NOTES,t("User database is empty. Create admin user first:")), resp);
return loadTemplate(path,null,resp);
} catch (SQLException throwables) {
} catch (SQLException e) {
return "Error reading user database!";
}
case LOGOUT:
@ -204,12 +213,14 @@ public class Web extends HttpServlet { @@ -204,12 +213,14 @@ public class Web extends HttpServlet {
var path = req.getPathInfo();
path = path == null ? INDEX : path.substring(1);
switch (path){
case ADD_LIST:
return addList(req,resp);
case LOGIN:
return handleLogin(req,resp);
case REGISTER:
return registerUser(req,resp);
case ADD_LIST:
return addList(req,resp);
case SUBSCRIBE:
return subscribe(req,resp);
}
return t("No handler for path {}!",path);
@ -293,5 +304,25 @@ public class Web extends HttpServlet { @@ -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";
}
}

2
static/templates/js.st

@ -125,7 +125,7 @@ function start(){ @@ -125,7 +125,7 @@ function start(){
}
function subscribeTo(domain,prefix){
window.location.href='subscribe/'+prefix+'@'+domain;
window.location.href='subscribe?list='+prefix+'@'+domain;
}

34
static/templates/subscribe.st

@ -0,0 +1,34 @@ @@ -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>
Loading…
Cancel
Save