use of com.axelor.apps.message.service.TemplateMessageService in project axelor-open-suite by axelor.
the class UserServiceImpl method processChangedPassword.
@Override
@Transactional(rollbackOn = { Exception.class })
public void processChangedPassword(User user) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, AxelorException, JSONException {
Preconditions.checkNotNull(user, I18n.get("User cannot be null."));
try {
if (!user.getSendEmailUponPasswordChange()) {
return;
}
if (user.equals(AuthUtils.getUser())) {
logger.debug("User {} changed own password.", user.getCode());
return;
}
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
Template template = appBase.getPasswordChangedTemplate();
if (template == null) {
throw new AxelorException(appBase, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get("Template for changed password is missing."));
}
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
templateMessageService.generateAndSendMessage(user, template);
} finally {
user.setTransientPassword(null);
}
}
Aggregations