Ejemplo n.º 1
0
        public HttpResponseMessage Post(UserDTO user)
        {
            AuthModel           auth = new AuthModel();
            HttpResponseMessage responseMessage;
            string response = auth.Authenticate(user.Username, user.Password);

            if (response != null)
            {
                string       role = auth.GetRole(user.Username);
                TokenMessage msg  = new TokenMessage(response, role);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, msg);
            }
            else
            {
                ErrorMessage msg = new ErrorMessage("Invalid username or password");
                responseMessage = Request.CreateResponse(HttpStatusCode.Forbidden, msg);
            }

            return(responseMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Primire username si parola de la client
        /// </summary>
        /// <param name="user">obiect care contine username si parola</param>
        /// <returns>token</returns>
        public HttpResponseMessage Post(UserDTO user)
        {
            var auth = new AuthModel();
            HttpResponseMessage responseMessage;
            var response = auth.Authenticate(user.Username, user.Password);

            if (response != null)
            {
                // Username si parola valide
                var role = auth.GetRole(user.Username);
                var msg  = new TokenMessage(response, role);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, msg);
            }
            else
            {
                //invalid username and password
                var msg = new JSendMessage("fail", "Invalid username or password");
                responseMessage = Request.CreateResponse(HttpStatusCode.Forbidden, msg);
            }

            return(responseMessage);
        }