コード例 #1
0
        public async Task <bool> Handle(ForgotPasswordQuery request, CancellationToken cancellationToken)
        {
            var user = await _userManager.FindByEmailAsync(request.Email);

            if (user == null)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            var resetPasswordConfirmationCode = await _userManager.GeneratePasswordResetTokenAsync(user);

            var resetPasswordEmail =
                _emailBuilder.ResetPasswordEmail(user.FirstName, user.Id, resetPasswordConfirmationCode);

            var emailToSend = new Email
            {
                FirstName        = user.FirstName,
                HtmlContent      = resetPasswordEmail,
                PlainTextContent = null,
                Subject          = EmailSubjects.ResetPassword,
                To     = user.Email,
                UserId = user.Id
            };

            _eventBus.Publish(new SendEmailEvent(emailToSend));
            _eventBus.Publish(new ResetPasswordRequestEvent(user.Id));

            return(await Task.FromResult(true));
        }