//---------------------------------------------2.0 登陆权限 等系统操作-------------------- #region 2.0 管理员登录方法 + bool LoginAdmin(Model.ViewModel.LoginUser usrPara) /// <summary> /// 管理员登录方法 /// </summary> /// <param name="usrPara"></param> public bool LoginAdmin(Model.ViewModel.LoginUser usrPara) { //到业务成查询 Model.UserDB usr = BLLSession.IUserDBBLL.Login(usrPara.LoginName, usrPara.Pwd); if (usr != null) { //2.1 保存 用户数据(Session or Cookie) Usr = usr; //如果选择了复选框,则要使用cookie保存数据 if (usrPara.IsAlways) { //2.1.2将用户id加密成字符串 string strCookieValue = Common.SecurityHelper.EncryptUserDB(usr.UserID.ToString()); //2.1.3创建cookie HttpCookie cookie = new HttpCookie(Admin_InfoKey, strCookieValue); cookie.Expires = DateTime.Now.AddDays(1); cookie.Path = Admin_CookiePath; Response.Cookies.Add(cookie); } //2.2 查询当前用户的 权限,并将权限 存入 Session 中 UsrPermission = GetUserPermission(usr.UserID); return(true); } return(false); }
/// <summary> /// 判断当前用户是否登陆 而且 /// </summary> /// <returns></returns> public bool IsLogin() { //1.验证用户是否登陆(Session && Cookie) if (Session[Admin_InfoKey] == null) { if (Request.Cookies[Admin_InfoKey] == null) { //重新登陆,内部已经调用了 Response.End(),后面的代码都不执行了! (注意:如果Ajax请求,此处不合适!) //filterContext.HttpContext.Response.Redirect("/admin/admin/login"); return(false); } else//如果有cookie则从cookie中获取用户id并查询相关数据存入 Session { string strUserInfo = Request.Cookies[Admin_InfoKey].Value; strUserInfo = Common.SecurityHelper.DecryptUserDB(strUserInfo); int userId = int.Parse(strUserInfo); Model.UserDB usr = BLLSession.IUserDBBLL.GetListBy(u => u.UserID == userId).First(); Usr = usr; UsrPermission = OperateContext.Current.GetUserPermission(usr.UserID); } } return(true); }