made urls for password reset configurable
This commit is contained in:
@ -164,7 +164,7 @@ public class AccountControl {
|
||||
account.setPasswordResetOngoing(true);
|
||||
account.setPasswordResetValidTo(validTo);
|
||||
|
||||
mailService.sendPasswortResetStartEmail(account, randomString);
|
||||
mailService.sendPasswortResetStartEmail(account,randomString);
|
||||
|
||||
em.merge(account);
|
||||
return true;
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
package de.muehlencord.shared.account.business.mail;
|
||||
|
||||
import de.muehlencord.shared.account.configuration.AccountConfigurationKey;
|
||||
import de.muehlencord.shared.account.entity.AccountEntity;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
@ -21,6 +19,7 @@ import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import de.muehlencord.shared.account.configuration.AccountConfigurationValue;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -34,6 +33,15 @@ public class MailService {
|
||||
@EJB
|
||||
private MailTemplateService mailTemplateService;
|
||||
|
||||
@Inject
|
||||
@AccountConfigurationValue(key = AccountConfigurationKey.BaseUrl)
|
||||
private String baseUrl;
|
||||
|
||||
@Inject
|
||||
@AccountConfigurationValue(key = AccountConfigurationKey.PasswordResetUrl)
|
||||
private String passwordResetUrl;
|
||||
|
||||
// TODO make this configurable by injection from the application it uses it, fall back to defaul mail setup if not available
|
||||
@Resource(lookup = "java:jboss/mail/ssgMail")
|
||||
private Session mailSession;
|
||||
|
||||
@ -97,7 +105,8 @@ public class MailService {
|
||||
public String sendPasswortResetStartEmail(AccountEntity account, String token) throws MailException {
|
||||
MailDatamodel model = new MailDatamodel(account);
|
||||
|
||||
try {
|
||||
/* old aproach via FacesContext - add this back as fallback if injection point if not configured
|
||||
try {
|
||||
// String absoluteWebPath = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
|
||||
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
|
||||
String resetPage = "/login.xhtml?token=" + token;
|
||||
@ -113,7 +122,13 @@ public class MailService {
|
||||
} catch (MalformedURLException ex) {
|
||||
throw new MailException("Error while sending email.", ex);
|
||||
}
|
||||
String baseUrl = configService.getConfigValue(configKey);
|
||||
String resetUrlWithToken = baseUrl + "/login.xhtml?token=" + token;
|
||||
*/
|
||||
|
||||
String resetUrlWithToken = passwordResetUrl + "?token=" + token;
|
||||
model.addParameter("url", baseUrl);
|
||||
model.addParameter("resetUrl", resetUrlWithToken);
|
||||
return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html");
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
public enum AccountConfigurationKey {
|
||||
// the base path of the application
|
||||
BaseUrl,
|
||||
// the full pass to the reset password page
|
||||
PasswordResetUrl,
|
||||
// injection handler
|
||||
Producer;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.configuration;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.enterprise.util.Nonbinding;
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Qualifier
|
||||
public @interface AccountConfigurationValue {
|
||||
|
||||
@Nonbinding
|
||||
AccountConfigurationKey key();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user