Ejemplo n.º 1
0
        /// <summary>
        /// The bind data.
        /// </summary>
        private void BindData()
        {
            var user = this.GetRepository <User>().GetBoardUser(this.UserId);

            if (user == null || user.Item1.ID == 0)
            {
                // No such user exists or this is an nntp user ("0")
                BuildLink.AccessDenied();
            }

            // populate user information controls...
            // Is BuddyList feature enabled?
            if (this.Get <BoardSettings>().EnableBuddyList)
            {
                this.SetupBuddyList(this.UserId, user);
            }
            else
            {
                // BuddyList feature is disabled. don't show any link.
                this.lnkBuddy.Visible  = false;
                this.BuddyCard.Visible = false;
            }

            var userNameOrDisplayName = this.HtmlEncode(
                this.Get <BoardSettings>().EnableDisplayName ? user.Item1.DisplayName : user.Item1.Name);

            this.SetupUserProfileInfo(user);

            this.AddPageLinks(userNameOrDisplayName);

            this.SetupUserStatistics(user);

            this.SetupUserLinks(user, userNameOrDisplayName);

            this.SetupAvatar(user.Item1);

            this.Groups.DataSource = AspNetRolesHelper.GetRolesForUser(user.Item2);

            this.ModerateTab.Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator;

            this.AdminUserButton.Visible = this.PageContext.IsAdmin;

            if (this.LastPosts.Visible)
            {
                this.LastPosts.DataSource = this.GetRepository <Message>().AllUserAsDataTable(
                    this.PageContext.PageBoardID,
                    this.UserId,
                    this.PageContext.PageUserID,
                    10).AsEnumerable();

                this.SearchUser.NavigateUrl = BuildLink.GetLink(
                    ForumPages.Search,
                    "postedby={0}",
                    userNameOrDisplayName);
            }

            this.DataBind();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The render.
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        protected override void Render(HtmlTextWriter writer)
        {
            var hiddenContent = this.Parameters["inner"];

            var groupString = this.Parameters["group"];

            if (hiddenContent.IsNotSet())
            {
                return;
            }

            var descriptionGuest = this.LocalizedString(
                "HIDDENMOD_GUEST",
                "This board requires you to be registered and logged-in before you can view hidden messages.");

            var shownContentGuest = $"<div class=\"alert alert-danger\" role=\"alert\">{descriptionGuest}</div>";

            if (groupString.IsNotSet())
            {
                // Hide from Guests only
                if (BoardContext.Current.IsGuest)
                {
                    writer.Write(shownContentGuest);
                    return;
                }
            }
            else
            {
                if (BoardContext.Current.IsGuest)
                {
                    writer.Write(shownContentGuest);
                    return;
                }

                descriptionGuest = this.LocalizedString(
                    "HIDDENMOD_GROUP",
                    "You dont´t have the right to see the Hidden Content.");

                shownContentGuest = $"<div class=\"alert alert-danger\" role=\"alert\">{descriptionGuest}</div>";

                var groups = groupString.Split(';');

                /*List<string> groups = new List<string>();
                 * List<string> ranks = new List<string>();
                 *
                 * foreach (string group in groupsAndRanks)
                 * {
                 *  if (group.StartsWith("group."))
                 *  {
                 *      groups.Add(group.Substring(group.IndexOf(".") + 1));
                 *  }
                 *  else if (group.StartsWith("rank."))
                 *  {
                 *      ranks.Add(group.Substring(group.IndexOf(".") + 1));
                 *  }
                 *  else
                 *  {
                 *      groups.Add(group);
                 *  }
                 * }*/

                // Check For Role Hiding
                if (AspNetRolesHelper.GetRolesForUser(
                        BoardContext.Current.MembershipUser).Any(role => !groups.Any(role.Equals)))
                {
                    shownContentGuest = hiddenContent;
                }

                // TODO : Check for Rank Hiding

                /*if (ranks.Any())
                 * {
                 *  var yafUserData = new CombinedUserDataHelper(BoardContext.Current.CurrentUserData.PageUserID);
                 *
                 *  if (!ranks.Where(rank => yafUserData.RankName.Equals(rank)).Any())
                 *  {
                 *      shownContentGuest = hiddenContent;
                 *  }
                 * }*/
            }

            // Override Admin, or User is Post Author
            if (BoardContext.Current.IsAdmin || this.DisplayUserID == BoardContext.Current.PageUserID)
            {
                shownContentGuest = hiddenContent;
            }

            writer.Write(shownContentGuest);
        }