Ejemplo n.º 1
0
        public async Task <IActionResult> Authenticate(AuthenticateRequest model)
        {
            AuthenticateResponse response;

            try
            {
                response = await _userService.Authenticate(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (response is null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }
            return(Ok(response.Token));
        }
Ejemplo n.º 2
0
        private async Task <User> AuthenticateUser(AuthenticateRequest model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user is null)
            {
                return(null);
            }

            var validators = _userManager.PasswordValidators
                             .Select(x => x.ValidateAsync(_userManager, user, model.Password));

            var results = await Task.WhenAll(validators);

            if (!results.Any(x => x.Succeeded))
            {
                return(null);
            }

            return(user);
        }