protected void Session_End(object sender, EventArgs e) { var user = new UsersEntity(); if (Session["User"] != null) { user = Session["User"] as UsersEntity; } UsersBLL uBll = new UsersBLL(); if (user != null) { user.IsOnline = 0; uBll.Update(user, null); } }
public ActionResult DoLogin(LoginModel users) { try { var loginName = WebHelper.GetFormString("loginName", string.Empty); var password = WebHelper.GetFormString("password", string.Empty); UsersBLL bll = new UsersBLL(); var user = new UsersEntity(); //首先判断是邮箱还是电话: if (ValidateHelper.IsEmail(loginName)) { user = bll.GetUsersEntityByEmail1(loginName, null).TData; } else { if (ValidateHelper.IsPhone(loginName)) { user = bll.GetUsersEntityByMobile1(loginName, null).TData; } else { return Content("<script>alert('请输入正确的邮箱或者电话号码!!');location.href = '/shop/admin/login';</script>"); } } if (user != null && user.Password.Equals(SecurityUtil.HashPassword(password))) { //统一存cookie ShopUtils.SetUserCookie(user, 2); Session["User"] = user; user.IsOnline = 1; bll.Update(user, null); return Content("<script>location.href = '/shop/admin/pass';</script>"); } else return Content("<script>alert('用户名或密码不正确!!');location.href = '/shop/admin/login';</script>"); } catch (Exception ex) { return Content("<script>alert('登陆出错!!');location.href = '/shop/admin/login';</script>"); throw; } }
public ActionResult LoginOut(string uid) { var guid = new Guid(uid); UsersBLL uBll=new UsersBLL(); var user = uBll.GetPartUserByUidAndPwd(guid); if (user != null) { user.IsOnline = 0; uBll.Update(user, null); } return Content(""); }
public ActionResult Login() { try { var loginName = WebHelper.GetFormString("loginName", string.Empty); var password = WebHelper.GetFormString("password", string.Empty); UsersBLL bll = new UsersBLL(); var user = new UsersEntity(); //首先判断是邮箱还是电话: if (ValidateHelper.IsEmail(loginName)) { user = bll.GetUsersEntityByEmail(loginName, null).TData; } else { if (ValidateHelper.IsPhone(loginName)) { user = bll.GetUsersEntityByMobile(loginName, null).TData; } else { return AjaxResult("valicationErr", "请输入正确的邮箱或者电话号码!!", false); } } if (user != null && user.Password.Equals(SecurityUtil.HashPassword(password))) { //统一存cookie ShopUtils.SetUserCookie(user, 2); Session["User"] = user; user.IsOnline = 1; bll.Update(user,null); return AjaxResult("success", "登录成功!!", false); } else return AjaxResult("error", "用户名或密码不正确!!", false); } catch (Exception ex) { return AjaxResult("error", ex.ToString(), false); throw; } }
/// <summary> /// 退出 /// </summary> public ActionResult Logout() { if (!WorkContext.Uid.Equals(Guid.Empty)) { WebHelper.DeleteCookie("bsp"); if (Session["User"] != null) { UsersBLL userBLL = new UsersBLL(); var user = Session["User"] as UsersEntity; if (user != null) { user.IsOnline = 0; userBLL.Update(user, null); } } Session["User"] = null; Session.Abandon(); // Sessions.RemoverSession(WorkContext.Sid); // OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } return Redirect("/"); }