コード例 #1
0
ファイル: OperationBLL.cs プロジェクト: liuying0525/lyprotal
        //Create By 唐万祯 at 2014/08/04
        /// <summary>
        /// 获取某个用户所有的操作
        /// </summary>
        /// <param name="accout">用户名</param>
        /// <returns></returns>
        public List <Operation> GetUserOperation(string accout)
        {
            var operations = new List <Operation>();

            var user = new DZAFCPortal.Authorization.DAL.UserService().GenericService.FirstOrDefault(p => p.Account == accout);

            if (user == null)
            {
                return(null);
            }

            var roleUsers = new DZAFCPortal.Authorization.DAL.RoleUserService().GenericService.GetAll(p => p.UserID == user.ID);

            foreach (var roleUser in roleUsers)
            {
                var temp = GetRoleOperation(roleUser.RoleID);
                if (temp != null && temp.Count > 0)
                {
                    operations.AddRange(temp);
                }
            }

            //去除重复项目
            var tempOp = new List <Operation>();

            foreach (var item in operations)
            {
                if (tempOp.Find(p => p.ID == item.ID) == null)
                {
                    tempOp.Add(item);
                }
            }

            return(tempOp);
        }
コード例 #2
0
        /// <summary>
        /// 通过操作,获取拥有这些操作的用户列表
        /// </summary>
        /// <param name="ops">操作集合</param>
        /// <returns></returns>
        public List <User> GetUsersByOpration(IEnumerable <string> ops)
        {
            if (ops != null)
            {
                //通过操作获取角色
                var roleIds = new DZAFCPortal.Authorization.DAL.RoleOperationService().GenericService.GetAll(p => ops.Contains(p.OperationID)).Select(p => p.RoleID);

                if (roleIds != null)
                {
                    //通过角色获取用户
                    var userIds = new DZAFCPortal.Authorization.DAL.RoleUserService().GenericService.GetAll(p => roleIds.Contains(p.RoleID)).Select(p => p.UserID);
                    //获取用户实体

                    if (userIds != null)
                    {
                        var users = new DZAFCPortal.Authorization.DAL.UserService().GenericService.GetAll(p => userIds.Contains(p.ID)).ToList();
                        if (users != null)
                        {
                            return(users);
                        }
                    }
                }
            }

            return(new List <User>());
        }
コード例 #3
0
ファイル: AuthrizedBase.cs プロジェクト: liuying0525/lyprotal
        protected void Page_Init(object sender, EventArgs e)
        {
            var navId = Request["CurNavId"];

            if (navId == null)
            {
                //return;
                Response.Write("缺少CurNavId参数,或参数不为指定的值");
                Response.End();
            }

            try
            {
                var nav = new DZAFCPortal.Service.NavigateService().GenericService.GetModel(navId);
                if (nav == null)
                {
                    throw new Exception(string.Format("系统中无法检索[ID]为{0}的记录。", navId));
                }

                var curUserId = Utils.CurrentUser.ID;
                var roleIds   = new DZAFCPortal.Authorization.DAL.RoleUserService().GenericService.GetAll(r => r.UserID == curUserId).Select(r => r.RoleID).ToArray();

                if (
                    !DZAFCPortal.Config.AppSettings.DefaultAccounts.Contains(Utils.CurrentUser.Account)
                    &&
                    !string.IsNullOrEmpty(nav.ApplyRoles)
                    &&
                    !NavigatorGeneration.IsNavVisible(nav.ApplyRoles.Split(','), roleIds)
                    )
                {
                    throw new Exception(string.Format("您没有权限访问该页面。", navId));
                }
            }
            catch (Exception ex)
            {
                Response.Write("<h2>" + ex.Message + "</h2>");
                Response.End();
            }
        }