예제 #1
0
        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            HttpRequest request = context.Request;

            string act = Request("act").ToLower();

            switch (act.ToLower())
            {
            case "login":
                LoginSystem(context);
                break;

            case "add":
                AddUser(context);
                break;

            case "list":
                ListUser(context);
                break;

            default:
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("未指定具体接口!")));
                return;
            }
        }
예제 #2
0
        public void EditUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";
            string token = Request("token");

            string loginName = Request("loginName");
            string password  = Request("password");
            string mobile    = Request("mobile");
            string province  = Request("province");

            if (string.IsNullOrEmpty(token))
            {
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("登录已失效!")));
                return;
            }

            if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("账号和密码不能为空!")));
                return;
            }

            context.Response.Write(js.Serialize(BaseModels.OK("修改成功!")));
            return;
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public void GetUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";
            string token = Request("token");

            string id = Request("id");


            if (string.IsNullOrEmpty(token))
            {
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("登录已失效!")));
                return;
            }

            if (string.IsNullOrEmpty(id))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("编码不能为空!")));
                return;
            }

            Hashtable ht = new Hashtable();

            ht["Id"]        = id;
            ht["loginName"] = "张双";
            ht["password"]  = "******";
            ht["mobile"]    = "15888888888";
            ht["province"]  = "杭州";

            context.Response.Write(js.Serialize(BaseModels.OK("查询成功!", ht)));
            return;
        }
예제 #4
0
        public void DelUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";
            string token = Request("token");

            string id = Request("id");


            if (string.IsNullOrEmpty(token))
            {
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("登录已失效!")));
                return;
            }

            if (string.IsNullOrEmpty(id))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("编码不能为空!")));
                return;
            }

            context.Response.Write(js.Serialize(BaseModels.OK("删除成功!")));
            return;
        }
예제 #5
0
        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/Json";
            HttpRequest          request = context.Request;
            JavaScriptSerializer js      = new JavaScriptSerializer();

            ReturnData rd = new ReturnData();

            string   token = Request("token");
            UR_USERS user  = GetUser(token);

            int userId = user.USER_ID.ToInt();

            if (userId == 0)
            {
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("请先登录!")));
                return;
            }

            string timestamp = Request("timestamp").Trim();

            if (string.IsNullOrEmpty(timestamp) || timestamp == "0")
            {
                timestamp = DateTime.Now.ToTimeStamp().ToString();
            }

            string isfile = Request("isfile"); // 如果是上传文件或者没有上传base64字符串

            if (isfile == "file" || Request("base64") == "")
            {
                rd = UploadFile(context, timestamp);
                context.Response.Write(js.Serialize(rd));
                return;
            }
            string filetype = Request("filetype");

            if (string.IsNullOrEmpty(filetype))
            {
                filetype = "image/jpeg";
            }
            string base64 = Request("base64");

            if (string.IsNullOrEmpty(base64))
            {
                rd = BaseModels.Error("请传入base64格式的图片字符串");
                context.Response.Write(js.Serialize(rd));
                return;
            }
            else
            {
                if (base64.IndexOf(',') >= 0)
                {
                    filetype = base64.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ElementAt(0);
                    if (filetype.IndexOf("jpg") >= 0 || filetype.IndexOf("jpeg") >= 0)
                    {
                        filetype = "image/jpeg";
                    }
                    base64 = base64.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ElementAt(1);
                }
            }

            string msg    = "";
            bool   result = StoreFile(base64, userId, filetype, out msg, "trademark", timestamp);

            rd = new Models.ReturnData()
            {
                data        = new { filename = result ? msg : "" },
                message     = result ? "" : msg,
                status_code = result ? "0" : "1"
            };

            context.Response.Write(js.Serialize(rd));
            return;
        }