Browse Source

Merge branch 'main' into lang_de

lang_de
Stephan Richter 3 years ago
parent
commit
578a748b68
  1. 2
      pom.xml
  2. 39
      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. 3
      static/templates/unsubscribe.st

2
pom.xml

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

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

@ -26,6 +26,7 @@ public class Web extends TemplateServlet {
public static final String WEB_ROOT = "/web"; public static final String WEB_ROOT = "/web";
private static final String ADD_LIST = "add_list"; private static final String ADD_LIST = "add_list";
private static final String CONFIRM = "confirm"; private static final String CONFIRM = "confirm";
private static final String CSS = "css";
private static final Logger LOG = LoggerFactory.getLogger(Web.class); private static final Logger LOG = LoggerFactory.getLogger(Web.class);
private static final String ADMIN = "admin"; private static final String ADMIN = "admin";
private static final String INSPECT = "inspect"; private static final String INSPECT = "inspect";
@ -178,17 +179,14 @@ public class Web extends TemplateServlet {
} }
private String handleGet(HttpServletRequest req, HttpServletResponse resp) { private String handleGet(HttpServletRequest req, HttpServletResponse resp) {
var path = req.getPathInfo(); var path = Util.getPath(req);
if (path == null) return redirectTo(INDEX,resp); var user = Util.getUser(req);
var o = req.getSession().getAttribute("user");
User user = o instanceof User ? (User) o : null;
var data = new HashMap<String,Object>(); var data = new HashMap<String,Object>();
var list = Util.getMailingList(req);
if (user != null) data.put(USER,user.safeMap()); 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()); if (list != null) data.put(LIST,list.minimalMap());
String notes = null;
switch (path){ switch (path){
case ARCHIVE: case ARCHIVE:
return archive(req,resp); return archive(req,resp);
@ -200,13 +198,14 @@ public class Web extends TemplateServlet {
loadTemplates(); loadTemplates();
data.put(NOTES,t("Vorlagen wurden neu geladen")); data.put(NOTES,t("Vorlagen wurden neu geladen"));
path = INDEX; path = INDEX;
case "css":
case INDEX:
case UNSUBSCRIBE: case UNSUBSCRIBE:
data.put(LIST,list.email());
case CSS:
case INDEX:
return loadTemplate(path,data,resp); return loadTemplate(path,data,resp);
case SUBSCRIBE: case SUBSCRIBE:
if (list.isOpenFor(user)) { if (list.isOpenFor(user)) {
data.put(LIST,listEmail); data.put(LIST,list.email());
return loadTemplate(path, data, resp); return loadTemplate(path, data, resp);
} }
return t("Es ist ihnen nicht gestattet, '{}' zu abonnieren!",list.email()); return t("Es ist ihnen nicht gestattet, '{}' zu abonnieren!",list.email());
@ -258,9 +257,7 @@ public class Web extends TemplateServlet {
} }
private String handlePost(HttpServletRequest req, HttpServletResponse resp) { private String handlePost(HttpServletRequest req, HttpServletResponse resp) {
final var user = Util.getUser(req);
final var path = Util.getPath(req); final var path = Util.getPath(req);
final var list = Util.getMailingList(req);
switch (path){ switch (path){
case ADD_LIST: case ADD_LIST:
@ -382,14 +379,13 @@ public class Web extends TemplateServlet {
var name = req.getParameter(NAME); var name = req.getParameter(NAME);
var email = req.getParameter(EMAIL); var email = req.getParameter(EMAIL);
var pass = req.getParameter(PASSWORD); var pass = req.getParameter(PASSWORD);
var listEmail = req.getParameter(LIST); var list = Util.getMailingList(req);
var data = new HashMap<String,Object>(); var data = new HashMap<String,Object>();
data.put(NAME,name); data.put(NAME,name);
data.put(EMAIL,email); data.put(EMAIL,email);
data.put(LIST,listEmail); if (list != null) data.put(LIST,list.email());
var skipConfirmation = false; var skipConfirmation = false;
var list = MailingList.load(listEmail);
if (list == null){ if (list == null){
data.put(ERROR,"Formular-Daten enthalten keine Liste!"); data.put(ERROR,"Formular-Daten enthalten keine Liste!");
@ -454,24 +450,19 @@ public class Web extends TemplateServlet {
var data = new HashMap<String,Object>(); var data = new HashMap<String,Object>();
var user = getSessionUser(req); var user = getSessionUser(req);
var email = req.getParameter(EMAIL); var email = req.getParameter(EMAIL);
var pass = req.getParameter(PASSWORD); var list = Util.getMailingList(req);
var listEmail = req.getParameter(LIST);
data.put(EMAIL,email); data.put(EMAIL,email);
data.put(LIST,listEmail);
var list = MailingList.load(listEmail);
if (user != null) data.put(USER,user.safeMap()); if (user != null) data.put(USER,user.safeMap());
if (list == null){ if (list == null){
data.put(ERROR,"Keine Mailin-Liste in den Formular-Daten übermittelt!!"); data.put(ERROR,"Keine Mailin-Liste in den Formular-Daten übermittelt!!");
return loadTemplate(UNSUBSCRIBE,data,resp); return loadTemplate(UNSUBSCRIBE,data,resp);
} else data.put(LIST,list.email());
}
if (user == null) { if (user == null) {
if (email == null || email.isBlank()) { if (email == null || email.isBlank()) {
data.put(ERROR, "Für das Abbestellen ist eine E-Mail-Adresse erforderlich!"); data.put(ERROR, "Für das Abbestellen ist eine E-Mail-Adresse erforderlich!");
return loadTemplate(UNSUBSCRIBE, data, resp); return loadTemplate(UNSUBSCRIBE, data, resp);
} }
var pass = req.getParameter(PASSWORD);
if (pass != null && pass.isBlank()) pass = null; if (pass != null && pass.isBlank()) pass = null;
try { try {

3
static/templates/css.st

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

19
static/templates/js.st

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

2
static/templates/listlist.st

@ -3,7 +3,7 @@
<table id="listlist"> <table id="listlist">
<tr> <tr>
<th>Listen-Name</th> <th>Listen-Name</th>
<th colspan="3">Listen-Adresse</th> <th>Listen-Adresse</th>
<th>Status</th> <th>Status</th>
<th>Aktionen</th> <th>Aktionen</th>
</tr> </tr>

2
static/templates/subscribe.st

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

3
static/templates/unsubscribe.st

@ -6,13 +6,12 @@
<script src="js"></script> <script src="js"></script>
<link rel="stylesheet" href="css" /> <link rel="stylesheet" href="css" />
</head> </head>
<body> <body id="subscribe">
«navigation()» «navigation()»
«userinfo()» «userinfo()»
«messages()» «messages()»
<h1>Widerhall Abonnieren</h1> <h1>Widerhall Abonnieren</h1>
<form method="POST"> <form method="POST">
<input type="hidden" name="list" value="«data.list»" />
<fieldset> <fieldset>
<legend>"«data.list»" abbestellen</legend> <legend>"«data.list»" abbestellen</legend>
<label> <label>

Loading…
Cancel
Save