Exemplo n.º 1
0
        public HttpResponseMessage Login([FromBody] LoginInfo login)
        {
            var token = AuthenticationUtility.AuthenticateUser(login.Username, login.Password, out int userID);

            if (token != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { token, userID }));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Login([FromBody] LoginInfo login)
        {
            var token = AuthenticationUtility.AuthenticateUser(login.Username, login.Password, out string role, out int userID);

            if (token != null)
            {
                if (role.Equals("admin"))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new { token, userID })));
                }
                else
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden)));
                }
            }
            else
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized)));
            }
        }