예제 #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;
        }
예제 #2
0
        public HttpResponseMessage Post(UserRegistrationDTO user)
        {
            UsersModel userModel = new UsersModel();
            bool add = userModel.AddUser(user);
            HttpResponseMessage response;

            if (add)
            {
                SuccessMessage msg = new SuccessMessage("Registration successful!");

                response = Request.CreateResponse(HttpStatusCode.OK, msg);
                return response;

            }
            else
            {
                ErrorMessage msg = new ErrorMessage("Registration failed! Username or email already exists");

                response = Request.CreateResponse(HttpStatusCode.Forbidden, msg);
                return response;

            }
        }