confirmation mail now template based.
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package de.srsoftware.widerhall.data;
|
||||
|
||||
import de.srsoftware.widerhall.Configuration;
|
||||
import de.srsoftware.widerhall.Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.stringtemplate.v4.ST;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
@@ -87,7 +91,7 @@ public class ListMember {
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static User confirm(String token) throws SQLException {
|
||||
public static ListMember confirm(String token) throws SQLException {
|
||||
var rs = Database.open().select(TABLE_NAME).where(TOKEN,token).compile().exec();
|
||||
if (rs.next()){
|
||||
var lm = ListMember.from(rs);
|
||||
@@ -103,12 +107,25 @@ public class ListMember {
|
||||
.compile()
|
||||
.run();
|
||||
}
|
||||
return lm.user;
|
||||
return lm;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void sendConfirmationMail(ST template) throws SQLException, MessagingException {
|
||||
var subject = t("[{}] Subscription complete!",list.name());
|
||||
var data = new HashMap<String,Object>();
|
||||
data.put(USER,user.safeMap());
|
||||
data.put(LIST,list.minimalMap());
|
||||
data.put(URL,Configuration.instance().baseUrl()+"/web/index");
|
||||
if (list.isOpenForSubscribers()) data.put("open_list",true);
|
||||
var text = template.add("data",data).render();
|
||||
try {
|
||||
list.smtp().send(list.email(),list.name(),user.email(),subject,text);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOG.warn("Failed to send list subscription confirmation!",e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create a new list member entry in the database.
|
||||
* If the member has the state AWAITING_CONFIRMATION, a token is assigned with the member, too.
|
||||
|
||||
Reference in New Issue
Block a user