Exemplo n.º 1
0
        public static IEnumerable <sys_menu> Filter(this IEnumerable <sys_menu> sysMenus)
        {
            var privileges = UserPrivilegesCache.GetUserPrivileges(UserIdentityUtil.GetCurrentUserId()).Where(item => item.object_type == nameof(sys_menu));

            return(sysMenus.Where(item =>
            {
                var data = privileges.FirstOrDefault(e => e.objectid == item.sys_menuId);
                return data != null && data.privilege > 0;
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 是否需要填充信息
        /// </summary>
        /// <returns></returns>
        public bool InfoFilled()
        {
            var user = Broker.Retrieve <user_info>(UserIdentityUtil.GetCurrentUserId());

            AssertUtil.CheckNull <SpException>(user, "未查询到用户", "BE999374-F0CF-4274-8D9D-1E436FBA6935");
            if (user.Id == UserIdentityUtil.ADMIN_ID)
            {
                return(false);
            }
            return(!user.gender.HasValue || AssertUtil.CheckEmpty(user.mailbox, user.cellphone, user.realname));
        }
Exemplo n.º 3
0
        public bool AllowCreateOrUpdateRole(string roleid)
        {
            var currentRoleId = Broker.Retrieve <user_info>(UserIdentityUtil.GetCurrentUserId())?.roleid;

            if (string.IsNullOrEmpty(currentRoleId))
            {
                return(false);
            }
            var toRoleId = roleid;

            return(Convert.ToInt32(toRoleId.FirstOrDefault().ToString()) >= Convert.ToInt32(currentRoleId.FirstOrDefault().ToString()));
        }
Exemplo n.º 4
0
        public bool IsUp(string objectid)
        {
            var sql  = @"
SELECT * FROM upvote
WHERE objectid = @objectid AND createdby = @ownerid";
            var data = Broker.Retrieve <upvote>(sql, new Dictionary <string, object>()
            {
                { "@objectid", objectid }, { "@ownerid", UserIdentityUtil.GetCurrentUserId() }
            });

            return(data != null);
        }
Exemplo n.º 5
0
 public FriendBlogProfile()
 {
     CreateMap <Jobs.SyncBlogJob.BlogDetail, FriendBlog.friend_blog>()
     .ForMember(dest => dest.Id, opt => opt.MapFrom(item => item.id))
     .ForMember(dest => dest.name, opt => opt.MapFrom(item => item.title))
     .ForMember(dest => dest.content, opt => opt.MapFrom(item => item.content))
     .ForMember(dest => dest.description, opt => opt.MapFrom(item => item.description))
     .ForMember(dest => dest.createdOn, opt => opt.MapFrom(item => item.createTime.ToDateTime()))
     .ForMember(dest => dest.createdBy, opt => opt.MapFrom(item => UserIdentityUtil.GetCurrentUserId()))
     .ForMember(dest => dest.createdByName, opt => opt.MapFrom(item => UserIdentityUtil.GetCurrentUser().Name))
     .ForMember(dest => dest.modifiedOn, opt => opt.MapFrom(item => item.updateTime.ToDateTime()))
     .ForMember(dest => dest.modifiedBy, opt => opt.MapFrom(item => UserIdentityUtil.GetCurrentUserId()))
     .ForMember(dest => dest.modifiedByName, opt => opt.MapFrom(item => UserIdentityUtil.GetCurrentUser().Name))
     .ForMember(dest => dest.first_picture, opt => opt.MapFrom(item => item.firstPicture));
 }
Exemplo n.º 6
0
        public IEnumerable <SelectOption> GetBasicRole()
        {
            var sql           = @"
select sys_roleid as Value, name as Name  from sys_role
where is_basic = 1 
";
            var dataList      = Broker.Query <SelectOption>(sql);
            var currentRoleId = Broker.Retrieve <user_info>(UserIdentityUtil.GetCurrentUserId())?.roleid;

            if (string.IsNullOrEmpty(currentRoleId))
            {
                return(new List <SelectOption>());
            }

            return(dataList.Where(item => UserIdentityUtil.IsOwner(currentRoleId, item.Value)));
        }
Exemplo n.º 7
0
        public override IList <message_remind> GetDataList(IList <SearchCondition> searchList, string orderBy, string viewId = "", string searchValue = "")
        {
            if (searchList.IsEmpty())
            {
                searchList = new List <SearchCondition>();
            }
            searchList.Add(new SearchCondition()
            {
                Name = "receiverid", Type = SearchType.Equals, Value = UserIdentityUtil.GetCurrentUserId()
            });
            var model = base.GetDataList(searchList, orderBy, viewId, searchValue);
            var ids   = model.Where(item => !item.is_read).Select(item => item.Id);

            ReadMessage(ids);
            return(model);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取用户对实体的权限
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public EntityPrivilegeResponse GetPrivilege()
        {
            var sql       = @"
SELECT * FROM sys_role_privilege
WHERE sys_roleid = @id and object_type = 'sys_entity'
and objectid = @entityid";
            var user      = Broker.Retrieve <user_info>(UserIdentityUtil.GetCurrentUserId());
            var paramList = new Dictionary <string, object>()
            {
                { "@id", user.roleid }, { "@entityid", EntityCache.GetEntity(new T().EntityName)?.Id }
            };
            var data = Broker.Retrieve <sys_role_privilege>(sql, paramList);

            return(new EntityPrivilegeResponse()
            {
                read = data.privilege >= 1,
                create = data.privilege >= 3,
                delete = data.privilege >= 7
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// 是否有进入后台权限
        /// </summary>
        /// <returns></returns>
        public bool GetShowAdmin()
        {
            var userId = UserIdentityUtil.GetCurrentUserId();

            if (string.IsNullOrEmpty(userId))
            {
                return(false);
            }

            var user = Broker.Retrieve <user_info>(userId);

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

            if (user.roleid != UserIdentityUtil.ANONYMOUS_ID)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取未读消息数量
        /// </summary>
        /// <returns></returns>
        public object GetUnReadMessageCount()
        {
            var userid    = UserIdentityUtil.GetCurrentUserId();
            var paramList = new Dictionary <string, object>()
            {
                { "@id", userid }
            };
            var sql     = @"
SELECT COUNT(1)
FROM message_remind
WHERE receiverid = @id AND is_read = 0";
            var total   = Broker.ExecuteScalar(sql, paramList);
            var upvote  = Broker.ExecuteScalar($"{sql} AND message_type = 'upvote'", paramList);
            var comment = Broker.ExecuteScalar($"{sql} AND message_type IN ('comment', 'reply')", paramList);
            var system  = Broker.ExecuteScalar($"{sql} AND message_type = 'system'", paramList);

            return(new
            {
                total = Convert.ToInt32(total),
                upvote = Convert.ToInt32(upvote),
                comment = Convert.ToInt32(comment),
                system = Convert.ToInt32(system)
            });
        }
 /// <summary>
 /// 获取权限条件
 /// </summary>
 /// <param name="broker"></param>
 /// <returns></returns>
 public static string GetFilteredSql(this IPersistBroker broker, string ownerName = "createdBy")
 {
     AssertUtil.CheckIsNullOrEmpty <SpException>(UserIdentityUtil.GetCurrentUserId(), "无法获取当前用户", "11F1C19C-D69E-4A46-BAB6-BAE84E32F7B2");
     return(" AND {0}." + ownerName + $" = '{UserIdentityUtil.GetCurrentUserId()}'");
 }
Exemplo n.º 12
0
 public user_info GetData()
 {
     return(Broker.Retrieve <user_info>(UserIdentityUtil.GetCurrentUserId()));
 }