Пример #1
0
        public async Task <Unit> Handle(ChangeEmailCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"El usuario {request.Id} va a cambiar de email");
            var user = await _userManager.FindByIdAsync(request.Id);

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

            var code = await _userManager.GenerateChangeEmailTokenAsync(user, request.NewEmail);

            var changeEmailViewModel = new ChangeEmailDto
            {
                Id       = user.Id,
                UserName = user.UserName,
                OldEmail = user.Email,
                NewEmail = request.NewEmail,
                CallBack = GenerateCallBack(user.Id, code, request.NewEmail)
            };

            await SendEmailNotificationAsync(user, changeEmailViewModel);

            _logger.LogInformation($"El usuario {request.Id} ha cambiado el email con éxito");

            return(Unit.Value);
        }
Пример #2
0
 private async Task SendEmailNotificationAsync(
     ApplicationUser applicationUser,
     ChangeEmailDto registerDto)
 {
     _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.ChangeEmailConfirmation, registerDto);
 }