예제 #1
0
        public async Task ChangePassword_With_ResetToken()
        {
            ApplicationUser applicationUser = await _applicationUserRepository.FindByNameOrEmailAsync("admin");

            Assert.IsNotNull(applicationUser);

            string passwordResetToken =
                await _applicationUserRepository.GeneratePasswordResetTokenAsync(applicationUser);

            Assert.IsNotNull(passwordResetToken);

            IdentityResult result = await _applicationUserRepository.ResetPasswordAsync(applicationUser,
                                                                                        passwordResetToken, "ThisIsMyResetPassword321*");

            Assert.IsTrue(result.Succeeded);
        }
예제 #2
0
        public async Task <ActionResult <bool> > ForgottenPassword([FromQuery] string usernameOrEmail)
        {
            ApplicationUser user = await _userRepository.FindByNameOrEmailAsync(usernameOrEmail);

            if (user is null)
            {
                return(BadRequest(
                           $"No existe un usuario identificado con el nombre de usuario o email {usernameOrEmail}."));
            }

            string token = await _userRepository.GeneratePasswordResetTokenAsync(user);

            UriBuilder uriBuilder = new UriBuilder(KaizenHttpContext.BaseUrl)
            {
                Path  = "user/ResetPassword",
                Query = $"token={token.Base64ForUrlEncode()}&email={user.Email}"
            };
            string resetPasswordLink = uriBuilder.Uri.ToString();

            return(await _userRepository.SendPasswordResetTokenAsync(user, resetPasswordLink));
        }