Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var sendResetPasswordResult = await resetPasswordManager.GenerateResetPasswordToken(Input.Email);

            if (sendResetPasswordResult == null)
            {
                Alertify.Push("Account does not exist", AlertType.Error);
                return(Page());
            }

            var emailSent = await emailSender.Send(Constants.ResetPasswordEmail(sendResetPasswordResult.Email, sendResetPasswordResult.Username,
                                                                                $"{Configuration.GetValue<string>(AppSettingsKeys.ServerAddress)}Auth/ResetPassword?userId={sendResetPasswordResult.UserId}&code={sendResetPasswordResult.Code}"));

            if (emailSent)
            {
                Alertify.Push($"Reset password token was sent to: {sendResetPasswordResult.Email}");
                return(Page());
            }

            Alertify.Push("There was a problem during sending reset password token");
            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <SendResetPasswordResponse> Handle(SendResetPasswordRequest request, CancellationToken cancellationToken)
        {
            var sendResetPasswordResult = await resetPasswordManager.GenerateResetPasswordToken(request.Email) ?? throw new TokenException("Error occurred during generating reset password token", ErrorCodes.CannotGenerateToken);

            return(await emailSender.Send(EmailMessages.ResetPasswordEmail(sendResetPasswordResult.Email, sendResetPasswordResult.Username,
                                                                           $"{Configuration.GetValue<string>(AppSettingsKeys.ClientAddress)}account/resetPassword?userId={sendResetPasswordResult.UserId}&token={sendResetPasswordResult.Token}"))
            ? new SendResetPasswordResponse()
            : throw new TokenException("Error occurred during generating reset password token", ErrorCodes.CannotGenerateToken));
        }