Esempio n. 1
0
        public void UserInfo(HttpListenerContext context)
        {
            var request  = context.Request;
            var response = context.Response;

            string token = request.QueryString["token"];

            Dictionary <string, object> result = new Dictionary <string, object>();
            string uid = UserHandler.GetUidByToken(token);

            if (uid != null)
            {
                User user = UserService.GetUserByID(int.Parse(uid));
                if (user != null)
                {
                    result.Add("code", 0);
                    result.Add("data", user.ToJson());
                }
                else
                {
                    result.Add("code", -1);
                    result.Add("data", "user not found!");
                }
            }
            else
            {
                result.Add("code", -1);
                result.Add("data", "operate fail");
            }
            Response(context, result);
        }
Esempio n. 2
0
        public void AddRoom(HttpListenerContext context)
        {
            var request  = context.Request;
            var response = context.Response;

            string title       = request.QueryString["title"];
            string description = request.QueryString["description"];
            string time        = request.QueryString["time"];
            string attendance  = request.QueryString["attendance"];

            // 验证token
            string token = request.QueryString["token"];

            if (!UserHandler.ValidateToken(token))
            {
                ResponseTokenInvalid(context);
                return;
            }
            if (title == null || description == null || time == null || attendance == null)
            {
                ResponseParameterInvalid(context);
                return;
            }
            title       = Encoding.GetEncoding("utf-8").GetString(request.ContentEncoding.GetBytes(title));
            description = Encoding.GetEncoding("utf-8").GetString(request.ContentEncoding.GetBytes(description));
            string uid = UserHandler.GetUidByToken(token);

            Dictionary <string, object> result = new Dictionary <string, object>();
            Room room = RoomService.AddRoom(int.Parse(uid), title, description, int.Parse(time), int.Parse(attendance));

            if (room != null)
            {
                result.Add("code", 0);
                result.Add("data", room.ToJson());
            }
            else
            {
                result.Add("code", -1);
                result.Add("msg", "operate fail");
            }

            Response(context, result);
        }