/// <summary> /// 校验Cookie的值 /// </summary> private void CheckCookieInfo() { if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null) { string userName = Request.Cookies["cp1"].Value; string userPwd = Request.Cookies["cp2"].Value; Model.User userInfo = UserManager.GetModel(userName); if (userInfo != null) { if (userPwd == Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(userInfo.LoginPwd))) { Session["userInfo"] = userInfo; if (!string.IsNullOrEmpty(Request["returnUrl"])) { Response.Redirect(Request["returnUrl"]); } else { Response.Redirect("/Default.aspx"); } } } Response.Cookies["cp1"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["cp2"].Expires = DateTime.Now.AddDays(-1); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "resetpwd") { int id = Convert.ToInt32(e.CommandArgument); Model.User resetUser = userManager.GetModel(id); if (resetUser != null) { resetUser.LoginPwd = common.WebComm.CreateMd5("123456"); userManager.Update(resetUser); } else { } } }
private void CheckUserCookie() { if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null) { string userCookieName = Request.Cookies["cp1"].Value; string userCookiePass = Request.Cookies["cp2"].Value; BLL.UserManager um = new BLL.UserManager(); MODEL.User user = um.GetModel(userCookieName); if (user != null) { string pwd = Common.WebCommon.GetStringMd5(user.PassWord); if (pwd == userCookiePass) { Session["userInfo"] = user; GoToPage(user); } } else { //TODO:情况cookie } } }
private void CheckUserCookie() { if(Request.Cookies["cp1"]!=null&&Request.Cookies["cp2"]!=null) { string userCookieName = Request.Cookies["cp1"].Value; string userCookiePass = Request.Cookies["cp2"].Value; BLL.UserManager um = new BLL.UserManager(); MODEL.User user = um.GetModel(userCookieName); if(user!=null) { string pwd = Common.WebCommon.GetStringMd5(user.PassWord); if(pwd==userCookiePass) { Session["userInfo"] = user; GoToPage(user); } } else { //TODO:情况cookie } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string name = context.Request["name"]; string mail = context.Request["mail"]; BLL.UserManager UserInfoManager = new BLL.UserManager(); Model.User userInfo = UserInfoManager.GetModel(name); if (userInfo != null) { if (userInfo.Mail == mail) { UserInfoManager.FindUserPwd(userInfo);//找回用户的密码 } else { context.Response.Write("邮箱错误!!"); } } else { context.Response.Write("查无此人!!"); } }
public void ProcessRequest(HttpContext context) { ; context.Response.ContentType = "text/plain"; BLL.UserManager bll = new BLL.UserManager(); string action = context.Request["action"]; // 获得分页 if (action == "get") { int pageIndex, pageSize; try { pageIndex = Convert.ToInt32(context.Request["pageIndex"]); pageSize = Convert.ToInt32(context.Request["pageSize"]); } catch { return; } pageIndex = pageIndex < 1 ? 1 : pageIndex; pageSize = pageSize <= 0 || pageSize > 10 ? 10 : pageSize; int pageCount = (int)Math.Ceiling((double)bll.GetModelCount() / (double)pageSize); List <Model.User> list = bll.GetPageList(pageIndex, pageSize); object obj = new { pageIndex, pageSize, pageCount, data = list, }; JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write(js.Serialize(obj)); } // 获得一个 else if (action == "getById") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } var user = bll.GetModel(id); if (user == null) { context.Response.Write("no:该用户不存在"); return; } JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write("ok:" + js.Serialize(user)); } // 删除 else if (action == "delete") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } if (bll.Delete(id)) { context.Response.Write("ok:删除成功"); } else { context.Response.Write("no:删除失败"); } } // 修改 else if (action == "edit") { int id; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } Model.User user = bll.GetModel(id); if (user == null) { context.Response.Write("no:该用户不存在"); return; } user.UserName = context.Request["userName"] == null ? user.UserName : context.Request["userName"]; user.Nickname = context.Request["nickname"] == null ? user.UserName : context.Request["nickname"]; user.Pwd = context.Request["pwd"] == null ? user.UserName : context.Request["pwd"]; user.Sex = Convert.ToChar(context.Request["sex"] == null ? user.UserName : context.Request["sex"]); user.Phone = context.Request["phone"] == null ? user.UserName : context.Request["phone"]; user.Address = context.Request["address"] == null ? user.UserName : context.Request["address"]; if (string.IsNullOrWhiteSpace(user.Pwd)) { context.Response.Write("no:密码不能为空"); } if (bll.Update(user)) { context.Response.Write("ok:修改成功"); } else { context.Response.Write("no:修改失败"); } } // 添加 else if (action == "add") { string username = context.Request["userName"]; string pwd = context.Request["pwd"]; char sex = Convert.ToChar(context.Request["sex"] == null?"\0": context.Request["sex"]); if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(pwd) || (sex) == '\0') { context.Response.Write("no:参数错误"); return; } Model.User user = new Model.User(); user.UserName = username; user.Nickname = context.Request["nickname"] == null? user.UserName : context.Request["nickname"]; user.Pwd = Common.MD5Helper.GetMD5String(pwd); user.Sex = sex; user.Phone = context.Request["phone"] == null?string.Empty: context.Request["phone"]; user.Address = context.Request["address"] == null ? string.Empty : context.Request["address"]; user.Url = context.Request["userUrl"] == null ? string.Empty : context.Request["userUrl"]; user.Description = context.Request["description"] == null ? string.Empty : context.Request["description"]; user.UserPic = context.Request["userPic"] == null ? string.Empty : context.Request["userPic"]; if (bll.Add(user)) { context.Response.Write("ok:添加成功"); } else { context.Response.Write("no:添加失败"); } } else { context.Response.Write("error:非法的action"); } }