working on confirmed subscription
This commit is contained in:
@@ -7,12 +7,14 @@ import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -29,8 +31,10 @@ public class Rest extends HttpServlet {
|
||||
private static final String LIST_HIDE = "list/hide";
|
||||
private static final String LIST_MEMBERS = "list/members";
|
||||
private static final String LIST_SHOW = "list/show";
|
||||
private static final String LIST_TEST = "list/test";
|
||||
private static final String USER_LIST = "user/list";
|
||||
private static final String MEMBERS = "members";
|
||||
private static final String SUCCESS = "success";
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
@@ -113,6 +117,9 @@ public class Rest extends HttpServlet {
|
||||
case LIST_SHOW:
|
||||
json.putAll(hideList(listEmail,user,false));
|
||||
break;
|
||||
case LIST_TEST:
|
||||
json.putAll(testList(listEmail,user));
|
||||
break;
|
||||
default:
|
||||
json.put(ERROR,t("No handler for path '{}'!",path));
|
||||
break;
|
||||
@@ -154,7 +161,7 @@ public class Rest extends HttpServlet {
|
||||
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)){
|
||||
try {
|
||||
MailingList.enable(listEmail,enable);
|
||||
return Map.of("success",t("Mailing list '{}' was {}!",listEmail,enable ? "enabled" : "disabled"));
|
||||
return Map.of(SUCCESS,t("Mailing list '{}' was {}!",listEmail,enable ? "enabled" : "disabled"));
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to enable/disable mailing list: ",e);
|
||||
return Map.of("error",t("Failed to update list '{}'",listEmail));
|
||||
@@ -167,15 +174,23 @@ public class Rest extends HttpServlet {
|
||||
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)){
|
||||
try {
|
||||
MailingList.hide(listEmail,hide);
|
||||
return Map.of("success",t("Mailing list '{}' was {}!",listEmail,hide ? "hidden" : "made public"));
|
||||
return Map.of(SUCCESS,t("Mailing list '{}' was {}!",listEmail,hide ? "hidden" : "made public"));
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to (un)hide mailing list: ",e);
|
||||
return Map.of("error",t("Failed to update list '{}'",listEmail));
|
||||
}
|
||||
|
||||
} else {
|
||||
return Map.of("error",t("You are not allowed to edit '{}'",listEmail));
|
||||
}
|
||||
return Map.of("error",t("You are not allowed to edit '{}'",listEmail));
|
||||
}
|
||||
|
||||
private Map testList(String listEmail, User user) {
|
||||
try {
|
||||
MailingList.load(listEmail).test(user);
|
||||
return Map.of(SUCCESS,t("Sent test email to {}",user.email()));
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Failed to send test email",e);
|
||||
return Map.of(ERROR,t("Failed to send test email to {}",user.email()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STRawGroupDir;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -360,7 +361,7 @@ public class Web extends HttpServlet {
|
||||
data.put(USER,user.safeMap());
|
||||
|
||||
try {
|
||||
ListMember.create(list,user,ListMember.STATE_SUBSCRIBER);
|
||||
list.requestSubscription(user);
|
||||
data.put(NOTES,t("Successfully subscribed '{}' to '{}'.",user.email(),list.email()));
|
||||
return loadTemplate(INDEX,data,resp);
|
||||
} catch (SQLException sqle) {
|
||||
@@ -371,6 +372,10 @@ public class Web extends HttpServlet {
|
||||
data.put(ERROR,t("You already are member of this list!",sqle.getMessage()));
|
||||
} else data.put(ERROR,t("Subscription failed: {}",sqle.getMessage()));
|
||||
return loadTemplate(SUBSCRIBE,data,resp);
|
||||
} catch (MessagingException e) {
|
||||
LOG.warn("Failed to send request confirmation email:",e);
|
||||
data.put(ERROR,t("Failed to send request confirmation email: {}",e.getMessage()));
|
||||
return loadTemplate(SUBSCRIBE,data,resp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user