Browse Source

minor code improvements

drop_old_mail
Stephan Richter 3 years ago
parent
commit
efa4bcbc99
  1. 2
      pom.xml
  2. 33
      src/main/java/de/srsoftware/widerhall/web/Web.java
  3. 3
      static/templates/css.st
  4. 19
      static/templates/js.st
  5. 2
      static/templates/listlist.st
  6. 2
      static/templates/subscribe.st
  7. 6
      static/templates/unsubscribe.st

2
pom.xml

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<groupId>org.example</groupId>
<artifactId>Widerhall</artifactId>
<version>0.2.15</version>
<version>0.2.16</version>
<build>
<plugins>
<plugin>

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

@ -178,17 +178,14 @@ public class Web extends TemplateServlet { @@ -178,17 +178,14 @@ public class Web extends TemplateServlet {
}
private String handleGet(HttpServletRequest req, HttpServletResponse resp) {
var path = req.getPathInfo();
if (path == null) return redirectTo(INDEX,resp);
var o = req.getSession().getAttribute("user");
User user = o instanceof User ? (User) o : null;
var path = Util.getPath(req);
var user = Util.getUser(req);
var data = new HashMap<String,Object>();
var list = Util.getMailingList(req);
if (user != null) data.put(USER,user.safeMap());
path = path.equals("/") ? INDEX : path.substring(1);
String notes = null;
var listEmail = req.getParameter(LIST);
var list = MailingList.load(listEmail);
if (list != null) data.put(LIST,list.minimalMap());
String notes = null;
switch (path){
case ARCHIVE:
return archive(req,resp);
@ -206,7 +203,7 @@ public class Web extends TemplateServlet { @@ -206,7 +203,7 @@ public class Web extends TemplateServlet {
return loadTemplate(path,data,resp);
case SUBSCRIBE:
if (list.isOpenFor(user)) {
data.put(LIST,listEmail);
data.put(LIST,list.email());
return loadTemplate(path, data, resp);
}
return t("You are not allowed to subscribe to '{}'!",list.email());
@ -258,9 +255,7 @@ public class Web extends TemplateServlet { @@ -258,9 +255,7 @@ public class Web extends TemplateServlet {
}
private String handlePost(HttpServletRequest req, HttpServletResponse resp) {
final var user = Util.getUser(req);
final var path = Util.getPath(req);
final var list = Util.getMailingList(req);
switch (path){
case ADD_LIST:
@ -382,14 +377,13 @@ public class Web extends TemplateServlet { @@ -382,14 +377,13 @@ public class Web extends TemplateServlet {
var name = req.getParameter(NAME);
var email = req.getParameter(EMAIL);
var pass = req.getParameter(PASSWORD);
var listEmail = req.getParameter(LIST);
var list = Util.getMailingList(req);
var data = new HashMap<String,Object>();
data.put(NAME,name);
data.put(EMAIL,email);
data.put(LIST,listEmail);
if (list != null) data.put(LIST,list.email());
var skipConfirmation = false;
var list = MailingList.load(listEmail);
if (list == null){
data.put(ERROR,"No list provided by form data!");
@ -454,24 +448,19 @@ public class Web extends TemplateServlet { @@ -454,24 +448,19 @@ public class Web extends TemplateServlet {
var data = new HashMap<String,Object>();
var user = getSessionUser(req);
var email = req.getParameter(EMAIL);
var pass = req.getParameter(PASSWORD);
var listEmail = req.getParameter(LIST);
var list = Util.getMailingList(req);
data.put(EMAIL,email);
data.put(LIST,listEmail);
var list = MailingList.load(listEmail);
if (user != null) data.put(USER,user.safeMap());
if (list == null){
data.put(ERROR,"No list provided by form data!");
return loadTemplate(UNSUBSCRIBE,data,resp);
}
} else data.put(LIST,list.email());
if (user == null) {
if (email == null || email.isBlank()) {
data.put(ERROR, "Email is required for list un-subscription!");
return loadTemplate(UNSUBSCRIBE, data, resp);
}
var pass = req.getParameter(PASSWORD);
if (pass != null && pass.isBlank()) pass = null;
try {

3
static/templates/css.st

@ -4,7 +4,8 @@ label { @@ -4,7 +4,8 @@ label {
}
#login form,
#register form{
#register form,
#subscribe form{
width: 450px;
margin: 0 auto;
}

19
static/templates/js.st

@ -142,18 +142,17 @@ function showListList(data){ @@ -142,18 +142,17 @@ function showListList(data){
for (let i in data.lists){
let list = data.lists[i];
let row = $('<tr/>');
$('<td/>').html('<a href="archive?prefix='+list.email.prefix+'&domain='+list.email.domain+'">'+list.name+'</a>').appendTo(row);
$('<td/>',{class:'right'}).text(list.email.prefix).appendTo(row);
$('<td/>',{class:'right'}).text('@').appendTo(row);
$('<td/>').text(list.email.domain).appendTo(row);
let email = list.email.prefix + '@' + list.email.domain;
$('<td/>').html('<a href="archive?list='+email+'">'+list.name+'</a>').appendTo(row);
$('<td/>').text(email).appendTo(row);
let states = [];
for (let state in list.state){
if (list.state[state] > 0) states.push(state);
}
$('<td/>').text(states.toString()).appendTo(row);
let td = $('<td/>',{class:'actions'});
$('<button/>',{onclick:"subscribeTo('"+list.email.domain+"', '"+list.email.prefix+"');"}).text('subscribe').appendTo(td);
$('<button/>',{onclick:"unsubscribeFrom('"+list.email.domain+"', '"+list.email.prefix+"');"}).text('unsubcribe').appendTo(td);
$('<button/>',{onclick:"subscribeTo('"+email+"');"}).text('subscribe').appendTo(td);
$('<button/>',{onclick:"unsubscribeFrom('"+email+"');"}).text('unsubcribe').appendTo(td);
td.appendTo(row);
row.appendTo('#listlist');
@ -229,16 +228,16 @@ function start(){ @@ -229,16 +228,16 @@ function start(){
console.log("application started");
}
function subscribeTo(domain,prefix){
window.location.href='subscribe?list='+prefix+'@'+domain;
function subscribeTo(listEmail){
window.location.href='subscribe?list='+listEmail;
}
function testList(listEmail){
$.post('/api/list/test',{list:listEmail},showListResult,'json');
}
function unsubscribeFrom(domain,prefix){
window.location.href='unsubscribe?list='+prefix+'@'+domain;
function unsubscribeFrom(listEmail){
window.location.href='unsubscribe?list='+listEmail;
}

2
static/templates/listlist.st

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
<table id="listlist">
<tr>
<th>List Name</th>
<th colspan="3">List Address</th>
<th>List Address</th>
<th>State</th>
<th>Actions</th>
</tr>

2
static/templates/subscribe.st

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<script src="js"></script>
<link rel="stylesheet" href="css" />
</head>
<body>
<body id="subscribe">
«navigation()»
«userinfo()»
«messages()»

6
static/templates/unsubscribe.st

@ -6,15 +6,15 @@ @@ -6,15 +6,15 @@
<script src="js"></script>
<link rel="stylesheet" href="css" />
</head>
<body>
<body id="subscribe">
«navigation()»
«userinfo()»
«messages()»
<h1>Widerhall Subscription</h1>
<form method="POST">
<input type="hidden" name="list" value="«data.list»" />
<input type="hidden" name="list" value="«data.list.email.prefix»@«data.list.email.domain»" />
<fieldset>
<legend>Un-subscribe from "«data.list»"</legend>
<legend>Un-subscribe from "«data.list.email.prefix»@«data.list.email.domain»"</legend>
<label>
<input type="text" name="email" value="«if(data.email)»«data.email»«else»«data.user.email»«endif»">
Email

Loading…
Cancel
Save