Esempio n. 1
0
        public async Task <Unit> Handle(RecoveryPasswordCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"El usuario {request.Email} va a recuperar el email.");

            var user = await _userManager.FindByEmailAsync(request.Email);

            if (user is null)
            {
                _logger.LogWarning($"El email {request.Email} no existe en la base de datos");
                throw new NotFoundException(nameof(ApplicationUser), nameof(ApplicationUser.Email));
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var recoveryPasswordViewModel = new RecoveryPasswordDto
            {
                UserName = user.UserName, CallBack = GenerateCallBack(user.Id, code)
            };

            await SendEmailNotificationAsync(user, recoveryPasswordViewModel);

            _logger.LogInformation($"Se a enviado un email a {request.Email} para recuperar la contraseña");

            return(Unit.Value);
        }
Esempio n. 2
0
 private async Task SendEmailNotificationAsync(
     ApplicationUser applicationUser,
     RecoveryPasswordDto recoveryPasswordDto)
 {
     _emailService.Subject = _localizer["Confirmación de cambio de email en {0}", _webApiConfig.SiteName];
     _emailService.To.Add(new MailAddress(applicationUser.Email));
     _emailService.IsHtml = true;
     await _emailService.SendEmailAsync(EmailTemplates.RecoveryPassword, recoveryPasswordDto);
 }