MSC1915. Add unbind email notification.

This commit is contained in:
Anatoly Sablin
2019-07-31 00:13:44 +03:00
parent a1f64f5159
commit 5aad4fb81e
7 changed files with 14 additions and 109 deletions

View File

@@ -31,7 +31,6 @@ public class EmailTemplateConfig extends GenericTemplateConfig {
setInvite("classpath:/threepids/email/invite-template.eml");
getGeneric().put("matrixId", "classpath:/threepids/email/mxid-template.eml");
getSession().setValidation("classpath:/threepids/email/validate-template.eml");
getSession().getUnbind().setValidation("classpath:/threepids/email/unbind-template.eml");
getSession().getUnbind().setNotification("classpath:/threepids/email/unbind-notification.eml");
}
@@ -41,7 +40,6 @@ public class EmailTemplateConfig extends GenericTemplateConfig {
log.info("Session:");
log.info(" Validation: {}", getSession().getValidation());
log.info(" Unbind:");
log.info(" Validation: {}", getSession().getUnbind().getValidation());
log.info(" Notification: {}", getSession().getUnbind().getNotification());
return this;

View File

@@ -212,6 +212,10 @@ public class SessionManager {
String secret = GsonUtil.getStringOrNull(reqData, "client_secret");
ThreePid tpid = GsonUtil.get().fromJson(GsonUtil.getObj(reqData, "threepid"), ThreePid.class);
if (tpid == null || StringUtils.isBlank(tpid.getAddress()) || StringUtils.isBlank(tpid.getMedium())) {
throw new BadRequestException("Missing required 3PID");
}
if (StringUtils.isNotBlank(sid) && StringUtils.isNotBlank(secret)) {
checkSession(sid, secret, tpid, mxid);
} else if (StringUtils.isNotBlank(auth)) {
@@ -220,7 +224,8 @@ public class SessionManager {
throw new NotAllowedException("Unable to validate request");
}
// TODO make invalid all 3PID with specified medium and address.
log.info("Unbinding of {} {} to {} is accepted", tpid.getMedium(), tpid.getAddress(), mxid.getId());
notifMgr.sendForUnbind(tpid);
}
private void checkAuthorization(String auth, JsonObject reqData) {

View File

@@ -115,7 +115,7 @@ public class EmailSmtpConnector implements EmailConnector {
msg.setRecipients(Message.RecipientType.TO, recipient);
msg.saveChanges();
log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
log.info("Sending email to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
if (cfg.getTls() < 3) {
@@ -134,12 +134,12 @@ public class EmailSmtpConnector implements EmailConnector {
try {
transport.sendMessage(msg, InternetAddress.parse(recipient));
log.info("Invite to {} was sent", recipient);
log.info("Email to {} was sent", recipient);
} finally {
transport.close();
}
} catch (UnsupportedEncodingException | MessagingException e) {
throw new RuntimeException("Unable to send e-mail invite to " + recipient, e);
throw new RuntimeException("Unable to send e-mail to " + recipient, e);
}
}