Exemplo n.º 1
0
        public async Task <IActionResult> Login([FromBody] User user)
        {
            try
            {
                var dbUser = await _userBusinessLogic.GetUserAsync(user.Username);

                if (dbUser == null)
                {
                    return(NotFound("User not found."));
                }

                var isValid = BCrypt.Net.BCrypt.Verify(user.Password, dbUser.Password);

                if (!isValid)
                {
                    return(BadRequest("Could not authenticate user."));
                }

                var token = _tokenBuilder.BuildToken(user.Username);

                return(Ok(token));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message + "  " + ex.StackTrace));
            }
        }