i18n password changed.

This commit is contained in:
Paulo Gustavo Veiga
2022-03-27 14:29:29 -03:00
parent 8989914eb3
commit ff2b37f4cf
9 changed files with 162 additions and 138 deletions

View File

@@ -23,7 +23,6 @@ import com.wisemapping.model.Collaboration;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import com.wisemapping.rest.model.RestLogItem;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -33,6 +32,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
@@ -43,8 +43,6 @@ import java.util.stream.Collectors;
final public class NotificationService {
final private static Logger logger = Logger.getLogger(Mailer.class);
final private static String DEFAULT_WISE_URL = "http://localhost:8080/wisemapping";
private ResourceBundleMessageSource messageSource;
@Autowired
@@ -83,22 +81,22 @@ final public class NotificationService {
}
public void resetPassword(@NotNull User user, @NotNull String temporalPassword) {
final String mailSubject = "[WiseMapping] Your new password";
final String messageTitle = "Your new password has been generated";
final String messageBody =
"<p>Someone, most likely you, requested a new password for your WiseMapping account. </p>\n" +
"<p><strong>Here is your new password: " + temporalPassword + "</strong></p>\n" +
"<p>You can login clicking <a href=\"" + getBaseUrl() + "/c/login\">here</a>. We strongly encourage you to change the password as soon as possible.</p>";
final Locale locale = LocaleContextHolder.getLocale();
final String mailSubject = messageSource.getMessage("CHANGE_PASSWORD.EMAIL_SUBJECT", null, locale);
final String messageTitle = messageSource.getMessage("CHANGE_PASSWORD.EMAIL_TITLE", null, locale);
final String messageBody = messageSource.getMessage("CHANGE_PASSWORD.EMAIL_BODY", new Object[]{temporalPassword, getBaseUrl()}, locale);
sendTemplateMail(user, mailSubject, messageTitle, messageBody);
}
public void passwordChanged(@NotNull User user) {
final String mailSubject = "[WiseMapping] Your password has been changed";
final String messageTitle = "Your password has been changed successfully";
final String messageBody =
"<p>This is only an notification that your password has been changed. No further action is required.</p>";
final Locale locale = LocaleContextHolder.getLocale();
final String mailSubject = messageSource.getMessage("PASSWORD_CHANGED.EMAIL_SUBJECT", null, locale);
final String messageTitle = messageSource.getMessage("PASSWORD_CHANGED.EMAIL_TITLE", null, locale);
final String messageBody = messageSource.getMessage("PASSWORD_CHANGED.EMAIL_BODY", null, locale);
sendTemplateMail(user, mailSubject, messageTitle, messageBody);
}
@@ -122,6 +120,7 @@ final public class NotificationService {
model.put("baseUrl", getBaseUrl());
model.put("supportEmail", mailer.getSupportEmail());
logger.debug("Email properties->" + model);
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), mailSubject, model, "baseLayout.vm");
} catch (Exception e) {
handleException(e);
@@ -205,26 +204,19 @@ final public class NotificationService {
}
public String stackTraceToString(@NotNull Throwable e) {
String retValue;
StringWriter sw = null;
PrintWriter pw = null;
try {
sw = new StringWriter();
pw = new PrintWriter(sw);
String retValue = "";
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try (sw; pw) {
e.printStackTrace(pw);
retValue = sw.toString();
} finally {
IOUtils.closeQuietly(pw);
IOUtils.closeQuietly(sw);
} catch (IOException ioException) {
ioException.printStackTrace();
}
return retValue;
}
public String getBaseUrl() {
if ("${site.baseurl}".equals(baseUrl)) {
baseUrl = DEFAULT_WISE_URL;
System.err.println("Warning: site.baseurl has not being configured. Mail site references could be not properly sent. Using :" + baseUrl);
}
return baseUrl;
}