Search in sources :

Example 1 with TemplateMessageService

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);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) AppBase(com.axelor.apps.base.db.AppBase) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Aggregations

AppBase (com.axelor.apps.base.db.AppBase)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 Template (com.axelor.apps.message.db.Template)1 TemplateMessageService (com.axelor.apps.message.service.TemplateMessageService)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1