private static void user_list(HttpContext context) { context.Response.ContentType = "application/json"; var pageIndex = Convert.ToInt32(context.Request["page"]); var pageSize = Convert.ToInt32(context.Request["pageSize"]); if (pageIndex <= 0) { pageIndex = 1; } if (pageSize <= 0) { pageSize = 10; } var bll = new BLL.Account.User(); var list = bll.GetUserList(pageIndex, pageSize).Select(o => new { id = o.user_id, name = o.user_admin, pwd = o.user_psw, tel = o.user_tel, date = $"{o.user_date:yyyy-MM-dd}" }).ToList(); var data = new { rows = list, total = list.Count }; // TODO: 增加json序列化方法,将data序列化后再输出 context.Response.Write(SerializerHelper.ToJson(data)); context.Response.End(); }
/// <summary> /// 用户登录 /// </summary> /// <param name="context"></param> private static void user_login(HttpContext context) { context.Response.ContentType = "application/json"; var bll = new BLL.Account.User(); var username = context.Request["username"]; var password = context.Request["password"]; var vcode = context.Request["vcode"]; var turl = HttpContext.Current.Session["ReturnUrl"] == null ? "/login.aspx" : HttpContext.Current.Session["ReturnUrl"].ToString(); if (string.IsNullOrEmpty(username)) { context.Response.Write("{\"status\":\"error\",\"msg\":\"用户名不能为空!\"}"); return; } if (string.IsNullOrEmpty(password)) { context.Response.Write("{\"status\":\"error\",\"msg\":\"密码不能为空!\"}"); return; } if (string.IsNullOrEmpty(vcode)) { context.Response.Write("{\"status\":\"error\",\"msg\":\"验证码不能为空!\"}"); return; } if (HttpContext.Current.Session["ValidateNum"] == null || !string.Equals(vcode, HttpContext.Current.Session["ValidateNum"].ToString(), StringComparison.CurrentCultureIgnoreCase)) { context.Response.Write("{\"status\":\"error\",\"msg\":\"验证码错误!\"}"); return; } var result = bll.Login(username, password); if (!result) { context.Response.Write("{\"status\":\"error\",\"msg\":\"用户名或密码不正确!\"}"); return; } if (string.IsNullOrEmpty(turl)) { turl = "/"; } HttpContext.Current.Session["UserName"] = username; context.Response.Write("{\"status\":\"success\",\"msg\":\"登录成功!\",\"turl\":\"" + turl + "\"}"); context.Response.End(); }