Ejemplo n.º 1
0
        public async Task <IActionResult> RequestPassword(RequestPasswordDTO requestPasswordDto)
        {
            var result = await authService.RequestPassword(requestPasswordDto);

            if (result.Succeeded)
            {
                return(Ok(new { result.Data, Description = "Reset Token should be sent via Email. Token in response - just for testing purpose." }));
            }

            return(BadRequest());
        }
        public async Task <AuthResult <string> > RequestPassword(RequestPasswordDTO requestPasswordDto)
        {
            if (requestPasswordDto == null ||
                string.IsNullOrEmpty(requestPasswordDto.Email))
            {
                return(AuthResult <string> .UnvalidatedResult);
            }

            var user = await userManager.FindByEmailAsync(requestPasswordDto.Email);

            if (user != null && user.Id > 0 && !user.IsDeleted)
            {
                var passwordResetToken = await userManager.GeneratePasswordResetTokenAsync(user.Id);

                return(AuthResult <string> .TokenResult(passwordResetToken));
            }

            return(AuthResult <string> .UnvalidatedResult);
        }