Search in sources :

Example 1 with ForgotPasswordSecurityTokenImpl

use of org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityTokenImpl in project BroadleafCommerce by BroadleafCommerce.

the class AdminSecurityServiceImpl method sendResetPasswordNotification.

@Override
@Transactional("blTransactionManager")
public GenericResponse sendResetPasswordNotification(String username) {
    GenericResponse response = new GenericResponse();
    AdminUser user = null;
    if (username != null) {
        user = adminUserDao.readAdminUserByUserName(username);
    }
    checkUser(user, response);
    if (!response.getHasErrors()) {
        String token = PasswordUtils.generateSecurePassword(TEMP_PASSWORD_LENGTH);
        token = token.toLowerCase();
        ForgotPasswordSecurityToken fpst = new ForgotPasswordSecurityTokenImpl();
        fpst.setAdminUserId(user.getId());
        fpst.setToken(encodePassword(token, null));
        fpst.setCreateDate(SystemTime.asDate());
        forgotPasswordSecurityTokenDao.saveToken(fpst);
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("token", token);
        String resetPasswordUrl = getResetPasswordURL();
        if (!StringUtils.isEmpty(resetPasswordUrl)) {
            if (resetPasswordUrl.contains("?")) {
                resetPasswordUrl = resetPasswordUrl + "&token=" + token;
            } else {
                resetPasswordUrl = resetPasswordUrl + "?token=" + token;
            }
        }
        vars.put("resetPasswordUrl", resetPasswordUrl);
        emailService.sendTemplateEmail(user.getEmail(), getResetPasswordEmailInfo(), vars);
    }
    return response;
}
Also used : ForgotPasswordSecurityToken(org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityToken) GenericResponse(org.broadleafcommerce.common.service.GenericResponse) ForgotPasswordSecurityTokenImpl(org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityTokenImpl) HashMap(java.util.HashMap) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

HashMap (java.util.HashMap)1 GenericResponse (org.broadleafcommerce.common.service.GenericResponse)1 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)1 ForgotPasswordSecurityToken (org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityToken)1 ForgotPasswordSecurityTokenImpl (org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityTokenImpl)1 Transactional (org.springframework.transaction.annotation.Transactional)1