Exemple #1
0
        public List <V_Admin_RoleMenu> GetUserPowerList(Tb_Admin_UserInfo userinfo)
        {
            List <Tb_Admin_UserRole> urlist    = GetUserRoleList(userinfo.UserID);
            List <V_Admin_RoleMenu>  powerlist = new List <V_Admin_RoleMenu>();

            if (urlist != null && urlist.Count > 0)
            {
                foreach (Tb_Admin_UserRole ur in urlist)
                {
                    List <V_Admin_RoleMenu> plist = GetAdminPower(ur.RoleID);
                    if (plist != null)
                    {
                        var tmplist = from p in plist where !(from pp in powerlist select pp.MenuID).Contains(p.MenuID) select p;
                        if (tmplist != null)
                        {
                            foreach (var p in tmplist)
                            {
                                powerlist.Add(p);
                            }
                        }
                    }
                }
            }
            return(powerlist);
        }
Exemple #2
0
        public LightsResponse AdminLogin(string userName, string passWord)
        {
            passWord = StringHelper.GetMD5(passWord);
            Tb_Admin_UserInfo userinfo = manager.Get <Tb_Admin_UserInfo>(it => it.UserName == userName && it.PassWord == passWord);

            if (userinfo != null)
            {
                return(LightsResponse.GetResponse(userinfo));
            }
            else
            {
                return(LightsResponse.GetErrorResponse("用户名或者密码不正确"));
            }
        }
Exemple #3
0
        //public override void OnAuthorization(AuthorizationContext filterContext)
        //{
        //    if (IsAuth)
        //    {
        //        Tb_Admin_UserInfo userinfo = (Tb_Admin_UserInfo)filterContext.HttpContext.Session["UserInfo"];
        //        if (userinfo == null)
        //        {
        //            // filterContext.Result = new RedirectResult("/Admin/Login/Login?Redirect=" + filterContext.HttpContext.Request.Url.Fragment);

        //        }
        //    }
        //    filterContext.HttpContext.Response.Write(IsAuth);
        //    //base.OnAuthorization(filterContext);
        //}
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (IsAuth)
            {
                base.OnActionExecuting(filterContext);
                if (filterContext.HttpContext.Session["UserInfo"] != null && filterContext.HttpContext.Session["UserPower"] != null && filterContext.HttpContext.Session["UserMenu"] != null)
                {
                    filterContext.HttpContext.Session["UserInfo"] = filterContext.HttpContext.Session["UserInfo"];
                    filterContext.HttpContext.Session["UserPower"] = filterContext.HttpContext.Session["UserPower"];
                    filterContext.HttpContext.Session.Timeout = 20;
                }
                else
                {
                    HttpCookie cookieName = System.Web.HttpContext.Current.Request.Cookies.Get("lginfo");
                    if (cookieName != null)
                    {
                        //filterContext.HttpContext.Session["UserInfo"] = filterContext.HttpContext.Session["UserInfo"];
                        //filterContext.HttpContext.Session["UserPower"] = filterContext.HttpContext.Session["UserPower"];
                        string userid = cookieName["uid"];
                        userid = StringHelper.Decrypt(userid);
                        int adminid = 0;
                        if (int.TryParse(userid, out adminid))
                        {
                            IloginService service = new Admin.Service.LoginService();
                            Tb_Admin_UserInfo admininfo = service.GetUserInfoByID(adminid);
                            if (admininfo != null)
                            {
                                List<V_Admin_RoleMenu> powerlist = service.GetUserPowerList(admininfo);
                                filterContext.HttpContext.Session["UserInfo"] = admininfo;
                                filterContext.HttpContext.Session["UserPower"] = powerlist;
                                filterContext.HttpContext.Session["UserMenu"] = service.GetAdminMenu(powerlist, 0);
                            }
                            else
                            {
                                Redirect(filterContext);
                            }
                        }
                        else
                        {
                            Redirect(filterContext);
                        }
                    }
                }
            }
        }
Exemple #4
0
        public JsonResult Login(string username, string password, string rememberMe)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(Json(LightsResponse.GetErrorResponse("请输入用户名和密码")));
            }
            if (password.StartsWith("enc_"))
            {
                password = password.Replace("enc_", "");
                password = StringHelper.Decrypt(password);
            }
            Admin.IService.IloginService loginservice = new Admin.Service.LoginService();
            LightsResponse result = loginservice.AdminLogin(username, password);

            if (result.Success)
            {
                if (!string.IsNullOrEmpty(rememberMe) && rememberMe == "on")
                {
                    HttpCookie cookie = new HttpCookie("qmvc");
                    cookie["un"]   = username;
                    cookie["pw"]   = "enc_" + StringHelper.Encrypt(password);
                    cookie.Expires = DateTime.Now.AddDays(7);
                    Response.Cookies.Add(cookie);
                }
                Tb_Admin_UserInfo       userinfo  = (Tb_Admin_UserInfo)result.Data;
                List <V_Admin_RoleMenu> powerlist = loginservice.GetUserPowerList(userinfo);
                Session["UserInfo"]  = userinfo;
                Session["UserPower"] = powerlist;
                Session["UserMenu"]  = loginservice.GetAdminMenu(powerlist, 0);

                HttpCookie cookielogin = new HttpCookie("lginfo");
                cookielogin["uname"] = username;
                cookielogin["uid"]   = StringHelper.Encrypt(userinfo.UserID.ToString());;
                cookielogin.Expires  = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookielogin);
            }
            return(Json(result));
        }
Exemple #5
0
        public Tb_Admin_UserInfo GetUserInfoByID(int userid)
        {
            Tb_Admin_UserInfo userinfo = manager.Get <Tb_Admin_UserInfo>(it => it.UserID == userid);

            return(userinfo);
        }