Beispiel #1
0
        public IActionResult Login([FromBody] Authenticate login)
        {
            _log4net.Info(" Http Post request");
            if (login == null)
            {
                return(BadRequest());
            }
            try
            {
                IActionResult response = Unauthorized();
                Authenticate  user     = ap.AuthenticateUser(login);

                if (user != null)
                {
                    var tokenString = ap.GenerateJSONWebToken(user, config);
                    response = Ok(tokenString);
                }

                return(response);
            }
            catch (Exception e)
            {
                _log4net.Error("Exception Occured " + e.Message);
                return(StatusCode(500));
            }
        }
        public IActionResult Login([FromBody] Authenticate loginCredentials)
        {
            _log4net.Info(" Http Post request" + nameof(TokenController));
            if (loginCredentials == null)
            {
                return(BadRequest());
            }
            try
            {
                IActionResult response        = Unauthorized();
                Authenticate  userCredentials = objProvider.AuthenticateUser(loginCredentials);

                if (userCredentials != null)
                {
                    string tokenString = objProvider.GenerateJSONWebToken(userCredentials, config);
                    response = Ok(tokenString);
                    return(response);
                }

                return(Unauthorized("Invalid Credentials"));
            }
            catch (Exception e)
            {
                _log4net.Error("Exception Occured " + e.Message + " from " + nameof(TokenController));
                return(StatusCode(500));
            }
        }