Example #1
0
        public IActionResult Login([FromBody] Users model)
        {
            string token  = string.Empty;
            Users  result = new Users();

            try
            {
                ServiceAction action = new ServiceAction(Configuration);
                action.CheckUser(out result, model.Username);
                if (result == null)
                {
                    return(NotFound());
                }
                if (!Crypto.VerifyHashedPassword(result.Password, model.Password))
                {
                    return(Unauthorized());
                }

                //set jwt
                token = action.BuildToken(result);
                return(Ok(new { token = token, message = "login successfully" }));
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to execute POST");
                return(StatusCode(500, new { result = "", message = ex.Message }));
            }
        }