public bool ValidateUserLogin() { bool result = false; HttpContext current = HttpContext.Current; if (current.Session["userInfo"] != null) { result = true; } else { if (current.Request.Cookies["cp1"] != null && current.Request.Cookies["cp2"] != null) { string userName = current.Request.Cookies["cp1"].Value; string userPwd = current.Request.Cookies["cp2"].Value; Model.UsersModel userInfo = GetModel(userName); if (userInfo != null) { if (userPwd == Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(userInfo.LoginPwd))) { current.Session["userInfo"] = userInfo; result = true; } } else { current.Response.Cookies["cp1"].Expires = DateTime.Now.AddDays(-1); current.Response.Cookies["cp2"].Expires = DateTime.Now.AddDays(-1); } } } return(result); }
private void userLogin() { string userName = Request["txtLoginId"]; string txtLoginPwd = Request["txtLoginPwd"]; Model.UsersModel userInfo = new Model.UsersModel(); string msg = string.Empty; if (UserManager.CheckUserInfo(userName, txtLoginPwd, out msg, out userInfo)) { Session["userInfo"] = userInfo; //用户是否选择了自动登陆 if (!string.IsNullOrEmpty(Request["cbAutoLogin"])) { HttpCookie cookie1 = new HttpCookie("cp1", userName); HttpCookie cookie2 = new HttpCookie("cp2", Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(txtLoginPwd))); cookie1.Expires = DateTime.Now.AddDays(7); cookie2.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); } if (string.IsNullOrEmpty(Request["hiddenReturnUrl"])) { Response.Redirect("/Default.aspx"); } else { Response.Redirect(Request["hiddenReturnUrl"]); } } else { Msg = msg; } }
/// <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.UsersModel 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); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; Model.UsersModel usersModel = new Model.UsersModel(); usersModel.LoginId = context.Request["txtName"]; usersModel.LoginPwd = context.Request["txtPwd"]; usersModel.Name = context.Request["txtRealName"]; usersModel.Mail = context.Request["txtEmail"]; usersModel.Address = context.Request["txtAddress"]; usersModel.Phone = context.Request["txtPhone"]; usersModel.UserStateId = Convert.ToInt32(UsersStateEnum.NormalState); BLL.UsersBLL usersBLL = new BLL.UsersBLL(); string msg = string.Empty; if (usersBLL.Add(usersModel, out msg) > 0) { context.Session["userInfo"] = usersModel; context.Response.Write("ok:" + msg); } else { context.Response.Write("no:" + msg); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string userName = context.Request["name"]; string userMail = context.Request["mail"]; BLL.UsersBLL userManager = new BLL.UsersBLL(); Model.UsersModel userInfo = userManager.GetModel(userName); if (userInfo != null) { if (userMail == userInfo.Mail) { userManager.FindUserPwd(userInfo); context.Response.Write("找回密码邮件已发送,请查收."); } else { context.Response.Write("找回密码邮箱不正确,请重新填写"); } } else { context.Response.Write("无此用户"); } }
protected void AddUserInfo() { Model.UsersModel usersModel = new Model.UsersModel(); usersModel.LoginId = Request["txtName"]; usersModel.LoginPwd = Request["txtPwd"]; usersModel.Name = Request["txtRealName"]; usersModel.Mail = Request["txtEmail"]; usersModel.Address = Request["txtAddress"]; usersModel.Phone = Request["txtPhone"]; usersModel.UserStateId = Convert.ToInt32(UsersStateEnum.NormalState); BLL.UsersBLL usersBLL = new BLL.UsersBLL(); string msg = string.Empty; if (usersBLL.Add(usersModel, out msg) > 0) { Session["userInfo"] = usersModel; string returnUrl = Request["returnUrl"]; if (string.IsNullOrEmpty(returnUrl)) { Response.Redirect("/Default.aspx"); } else { Response.Redirect(returnUrl); } } else { Response.Redirect("/ShowMsg.aspx?msg=" + msg + "&txt=首页" + "&redirect=/Default.aspx"); } }
/// <summary> /// 找回用户密码 /// </summary> /// <param name="userInfo"></param> public void FindUserPwd(Model.UsersModel userInfo) { BLL.SettingsBLL settingBLL = new SettingsBLL(); //1.系统产生一个新的密码,然后更新数据库,再将新的密码发送到用户的邮箱中 string newPwd = Guid.NewGuid().ToString().Substring(0, 4); userInfo.LoginPwd = newPwd;//一定要将系统产生的系密码加密后更新到数据库,但是发送到用户邮箱的密码一定是明文的 dal.Update(userInfo); MailMessage mailMsg = new MailMessage(); mailMsg.From = new MailAddress(settingBLL.GetValue("SysMailAddress"), "苏鹏"); mailMsg.To.Add(new MailAddress(userInfo.Mail, "新浪收件人supeng")); mailMsg.Subject = "在商城网站中的用户"; StringBuilder sb = new StringBuilder(); sb.Append("用户名是:" + userInfo.LoginId); sb.Append("新密码是:" + userInfo.LoginPwd); mailMsg.Body = sb.ToString(); SmtpClient client = new SmtpClient(settingBLL.GetValue("SysMailSMTP"), int.Parse(settingBLL.GetValue("SysMailSMTPPort"))); client.Credentials = new NetworkCredential(settingBLL.GetValue("SysMailUserName"), settingBLL.GetValue("SysMailUserPass")); client.Send(mailMsg);//短时间内发送大量邮件时容易阻塞,所以可以将要发送的邮件先发送到队列中 }
public void ProcessRequest(HttpContext context) { BLL.UsersBLL UserManager = new BLL.UsersBLL(); context.Response.ContentType = "text/plain"; string userName = context.Request["txtLoginId"]; string txtLoginPwd = context.Request["txtLoginPwd"]; Model.UsersModel userInfo = new Model.UsersModel(); string msg = string.Empty; if (UserManager.CheckUserInfo(userName, txtLoginPwd, out msg, out userInfo)) { context.Session["userInfo"] = userInfo; //用户是否选择了自动登陆 if (!string.IsNullOrEmpty(context.Request["cbAutoLogin"])) { HttpCookie cookie1 = new HttpCookie("cp1", userName); HttpCookie cookie2 = new HttpCookie("cp2", Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(txtLoginPwd))); cookie1.Expires = DateTime.Now.AddDays(7); cookie2.Expires = DateTime.Now.AddDays(7); context.Response.Cookies.Add(cookie1); context.Response.Cookies.Add(cookie2); } if (string.IsNullOrEmpty(context.Request["hiddenReturnUrl"])) { context.Response.Write("{\"action\":\"pass\",\"message\":\"/Default.aspx\"}"); } else { context.Response.Write("{\"action\":\"pass\",\"message\":\"" + context.Request["hiddenReturnUrl"] + "\"}"); } } else { context.Response.Write("{\"action\":\"notThrough\",\"message\":\"" + msg + "\"}"); } }
/// <summary> /// 校验用户信息并返回消息和user对象 /// </summary> /// <param name="userName"></param> /// <param name="userPwd"></param> /// <param name="msg"></param> /// <param name="user"></param> /// <returns></returns> public bool CheckUserInfo(string userName, string userPwd, out string msg, out Model.UsersModel user) { bool isSuccess = false; user = dal.GetModel(userName); if (user != null) { if (userPwd == user.LoginPwd) { msg = "Login success"; isSuccess = true; } else { msg = "Password is eror"; } } else { msg = "The user does not exist"; } return(isSuccess); }