Exemplo n.º 1
0
        /// <summary>
        /// 验证用户是否登陆
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            //检查Cookies["User"]是否存在
            if (httpContext.Request.Cookies["User"] == null)
            {
                return(false);
            }
            //验证用户名密码是否正确
            HttpCookie _cookie   = httpContext.Request.Cookies["User"];
            string     _userName = _cookie["UserName"];
            string     _password = _cookie["Password"];

            httpContext.Response.Write("用户名:" + _userName);
            if (_userName == "" || _password == "")
            {
                return(false);
            }
            T_UserInfo model = bll.GetAllList().Where(m => m.UserName == _userName).Where(m => m.PassWord == BaseSecurity.Base64Encode(_password)).SingleOrDefault();

            if (model == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 用户列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(int page = 1)
        {
            var result = new List <UserViewModel>();
            var list   = userbll.GetAllList().ToList();

            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    result.Add(new UserViewModel {
                        Id         = item.id,
                        UserName   = item.UserName,
                        Password   = item.PassWord,
                        RoleName   = rolebll.GetById(item.Role) == null ?"": rolebll.GetById(item.Role).RoleName,
                        TrueName   = item.TrueName,
                        Role       = item.Role,
                        CreateDate = Convert.ToDateTime(item.CreateDate)
                    });
                }
            }
            return(View(result.ToPagedList(page, 2)));
        }