Browse Source

working on confirmed subscription

drop_old_mail
Stephan Richter 3 years ago
parent
commit
6361cec7bc
  1. 6
      src/main/java/de/srsoftware/widerhall/data/MailingList.java
  2. 4
      src/main/java/de/srsoftware/widerhall/web/Web.java

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

@ -225,8 +225,10 @@ public class MailingList {
return String.join(", ", states); return String.join(", ", states);
} }
public void requestSubscription(User user) throws SQLException, MessagingException { public void requestSubscription(User user, boolean skipConfirmation) throws SQLException, MessagingException {
var member = ListMember.create(this,user,ListMember.STATE_AWAITING_CONFIRMATION); var state = skipConfirmation ? ListMember.STATE_SUBSCRIBER : ListMember.STATE_AWAITING_CONFIRMATION;
var member = ListMember.create(this,user,state);
if (skipConfirmation) return;
var token = member.token(); var token = member.token();
try { try {
sendConfirmationRequest(user, token); sendConfirmationRequest(user, token);

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

@ -329,6 +329,7 @@ public class Web extends HttpServlet {
data.put(NAME,name); data.put(NAME,name);
data.put(EMAIL,email); data.put(EMAIL,email);
data.put(LIST,listEmail); data.put(LIST,listEmail);
var skipConfirmation = false;
var list = MailingList.load(listEmail); var list = MailingList.load(listEmail);
@ -351,6 +352,7 @@ public class Web extends HttpServlet {
int code = cause.getErrorCode(); int code = cause.getErrorCode();
if (code == PRIMARY_KEY_CONSTRAINT) try {// user already exists if (code == PRIMARY_KEY_CONSTRAINT) try {// user already exists
user = User.loadUser(email,pass); user = User.loadUser(email,pass);
skipConfirmation = pass != null; // subscription with email address already known to database
// success → subscribe // success → subscribe
} catch (InvalidKeyException | SQLException e) { } catch (InvalidKeyException | SQLException e) {
// invalid credentials // invalid credentials
@ -361,7 +363,7 @@ public class Web extends HttpServlet {
data.put(USER,user.safeMap()); data.put(USER,user.safeMap());
try { try {
list.requestSubscription(user); list.requestSubscription(user,skipConfirmation);
data.put(NOTES,t("Successfully subscribed '{}' to '{}'.",user.email(),list.email())); data.put(NOTES,t("Successfully subscribed '{}' to '{}'.",user.email(),list.email()));
return loadTemplate(INDEX,data,resp); return loadTemplate(INDEX,data,resp);
} catch (SQLException sqle) { } catch (SQLException sqle) {

Loading…
Cancel
Save