private string MatchUserBoxGroups([NotNull] string userBox, [NotNull] DataTable roleStyleTable) { const string StyledNick = @"<span class=""YafGroup_{0}"" style=""{1}"">{0}</span>"; string filler = string.Empty; Regex rx = this.GetRegex(Constants.UserBox.Groups); if (this.Get <YafBoardSettings>().ShowGroups) { var groupsText = new StringBuilder(500); bool bFirst = true; string roleStyle = null; foreach (string role in RoleMembershipHelper.GetRolesForUser(this.DataRow["UserName"].ToString())) { string role1 = role; foreach (DataRow drow in roleStyleTable.Rows.Cast <DataRow>().Where(drow => drow["LegendID"].ToType <int>() == 1 && drow["Style"] != null && drow["Name"].ToString() == role1)) { roleStyle = this.TransformStyle.DecodeStyleByString(drow["Style"].ToString(), true); break; } if (bFirst) { groupsText.AppendLine( this.Get <YafBoardSettings>().UseStyledNicks ? StyledNick.FormatWith(role, roleStyle) : role); bFirst = false; } else { if (this.Get <YafBoardSettings>().UseStyledNicks) { groupsText.AppendLine((@", " + StyledNick).FormatWith(role, roleStyle)); } else { groupsText.AppendFormat(", {0}", role); } } roleStyle = null; } filler = this.Get <YafBoardSettings>().UserBoxGroups.FormatWith( this.GetText("groups"), groupsText); // mddubs : 02/21/2009 // Remove the space before the first comma when multiple groups exist. filler = filler.Replace("\r\n,", ","); } // replaces template placeholder with actual groups userBox = rx.Replace(userBox, filler); return(userBox); }
/// <summary> /// The page context_ page pre load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void CurrentPageLoad([NotNull] object sender, [NotNull] EventArgs e) { var user = UserMembershipHelper.GetUser(false); if (user != null && HttpContext.Current.Session["UserSharePointSynced"] == null) { // sync roles with Sharepoint... this.SyncUserToGroups(user.UserName, RoleMembershipHelper.GetRolesForUser(user.UserName)); // don't need to do this again for the remainder of the session... HttpContext.Current.Session["UserSharePointSynced"] = user.UserName; } else if (user == null && HttpContext.Current.Session["UserSharePointSynced"] != null) { HttpContext.Current.Session.Remove("UserSharePointSynced"); } }
/// <summary> /// The bind data. /// </summary> private void BindData() { MembershipUser user = UserMembershipHelper.GetMembershipUserById(this.UserId); if (user == null || user.ProviderUserKey.ToString() == "0") { // No such user exists or this is an nntp user ("0") YafBuildLink.AccessDenied(); } var userData = new CombinedUserDataHelper(user, this.UserId); // populate user information controls... // Is BuddyList feature enabled? if (this.Get <YafBoardSettings>().EnableBuddyList) { this.SetupBuddyList(this.UserId, userData); } else { // BuddyList feature is disabled. don't show any link. this.lnkBuddy.Visible = false; this.ltrApproval.Visible = false; } // Is album feature enabled? if (this.Get <YafBoardSettings>().EnableAlbum) { this.AlbumList1.UserID = this.UserId; } else { this.AlbumList1.Dispose(); } var userNameOrDisplayName = this.Get <YafBoardSettings>().EnableDisplayName ? userData.DisplayName : userData.UserName; this.SetupUserProfileInfo(this.UserId, user, userData, userNameOrDisplayName); this.AddPageLinks(userNameOrDisplayName); this.SetupUserStatistics(userData); this.SetupUserLinks(userData, userNameOrDisplayName); this.SetupAvatar(this.UserId, userData); this.Groups.DataSource = RoleMembershipHelper.GetRolesForUser(userData.UserName); // EmailRow.Visible = PageContext.IsAdmin; this.ModerateTab.Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator; this.ModerateLi.Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator; this.AdminUserButton.Visible = this.PageContext.IsAdmin; if (this.LastPosts.Visible) { this.LastPosts.DataSource = LegacyDb.post_alluser(this.PageContext.PageBoardID, this.UserId, this.PageContext.PageUserID, 10) .AsEnumerable(); this.SearchUser.NavigateUrl = YafBuildLink.GetLinkNotEscaped( ForumPages.search, "postedby={0}", this.Get <YafBoardSettings>().EnableDisplayName ? userData.DisplayName : userData.UserName); } this.DataBind(); }
/// <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 (RoleMembershipHelper.GetRolesForUser( BoardContext.Current.User.UserName).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.CurrentUserData.UserID) { shownContentGuest = hiddenContent; } writer.Write(shownContentGuest); }
private string MatchUserBoxGroups([NotNull] string userBox, [NotNull] DataTable roleStyleTable) { const string StyledNick = @"<span class=""YafGroup_{0}"" style=""{1}"">{0}</span>"; string filler = string.Empty; Regex rx = this.GetRegex(Constants.UserBox.Groups); if (this.Get <YafBoardSettings>().ShowGroups) { var groupsText = new StringBuilder(500); bool bFirst = true; bool hasRole = false; string roleStyle = null; var userName = this.DataRow["IsGuest"].ToType <bool>() ? UserMembershipHelper.GuestUserName : this.DataRow["UserName"].ToString(); foreach (string role in RoleMembershipHelper.GetRolesForUser(userName)) { string role1 = role; foreach (DataRow drow in roleStyleTable.Rows.Cast <DataRow>().Where( drow => drow["LegendID"].ToType <int>() == 1 && drow["Style"] != null && drow["Name"].ToString() == role1)) { roleStyle = this.TransformStyle.DecodeStyleByString(drow["Style"].ToString(), true); break; } if (bFirst) { groupsText.AppendLine( this.Get <YafBoardSettings>().UseStyledNicks ? StyledNick.FormatWith(role, roleStyle) : role); bFirst = false; } else { if (this.Get <YafBoardSettings>().UseStyledNicks) { groupsText.AppendLine((@", " + StyledNick).FormatWith(role, roleStyle)); } else { groupsText.AppendFormat(", {0}", role); } } roleStyle = null; hasRole = true; } // vzrus: Only a guest normally has no role if (!hasRole) { DataTable dt = this.Get <IDataCache>().GetOrSet( Constants.Cache.GuestGroupsCache, () => LegacyDb.group_member(PageContext.PageBoardID, this.DataRow["UserID"]), TimeSpan.FromMinutes(60)); foreach (string guestRole in dt.Rows.Cast <DataRow>().Where(role => role["Member"].ToType <int>() > 0).Select( role => role["Name"].ToString())) { foreach (DataRow drow in roleStyleTable.Rows.Cast <DataRow>().Where( drow => drow["LegendID"].ToType <int>() == 1 && drow["Style"] != null && drow["Name"].ToString() == guestRole)) { roleStyle = this.TransformStyle.DecodeStyleByString(drow["Style"].ToString(), true); break; } groupsText.AppendLine( this.Get <YafBoardSettings>().UseStyledNicks ? StyledNick.FormatWith(guestRole, roleStyle) : guestRole); break; } } filler = this.Get <YafBoardSettings>().UserBoxGroups.FormatWith(this.GetText("groups"), groupsText); // mddubs : 02/21/2009 // Remove the space before the first comma when multiple groups exist. filler = filler.Replace("\r\n,", ","); } // replaces template placeholder with actual groups userBox = rx.Replace(userBox, filler); return(userBox); }
/// <summary> /// Get the User Groups /// </summary> /// <returns> /// The <see cref="string"/>. /// </returns> protected string GetUserRoles() { var filler = string.Empty; if (!this.Get <BoardSettings>().ShowGroups) { return(filler); } const string StyledNick = @"<span class=""YafGroup_{0}"" style=""{1}"">{0}</span>"; var groupsText = new StringBuilder(500); var first = true; var hasRole = false; string roleStyle = null; var userName = this.DataRow["IsGuest"].ToType <bool>() ? UserMembershipHelper.GuestUserName : this.DataRow["UserName"].ToString(); RoleMembershipHelper.GetRolesForUser(userName).ForEach( role => { var role1 = role; foreach (var dataRow in this.roleRankStyleTable.Rows.Cast <DataRow>().Where( row => row["LegendID"].ToType <int>() == 1 && row["Style"] != null && row["Name"].ToString() == role1)) { roleStyle = this.TransformStyle.DecodeStyleByString(dataRow["Style"].ToString(), true); break; } if (first) { groupsText.AppendLine( this.Get <BoardSettings>().UseStyledNicks ? string.Format(StyledNick, role, roleStyle) : role); first = false; } else { if (this.Get <BoardSettings>().UseStyledNicks) { groupsText.AppendFormat(", " + StyledNick, role, roleStyle); } else { groupsText.AppendFormat(", {0}", role); } } roleStyle = null; hasRole = true; }); // vzrus: Only a guest normally has no role if (!hasRole) { var dt = this.Get <IDataCache>().GetOrSet( Constants.Cache.GuestGroupsCache, () => this.GetRepository <Group>().MemberAsDataTable( this.PageContext.PageBoardID, this.DataRow["UserID"]), TimeSpan.FromMinutes(60)); foreach (var guestRole in dt.Rows.Cast <DataRow>().Where(role => role["Member"].ToType <int>() > 0) .Select(role => role["Name"].ToString())) { foreach (var dataRow in this.roleRankStyleTable.Rows.Cast <DataRow>().Where( row => row["LegendID"].ToType <int>() == 1 && row["Style"] != null && row["Name"].ToString() == guestRole)) { roleStyle = this.TransformStyle.DecodeStyleByString(dataRow["Style"].ToString(), true); break; } groupsText.AppendLine( this.Get <BoardSettings>().UseStyledNicks ? string.Format(StyledNick, guestRole, roleStyle) : guestRole); break; } } filler = $"<strong>{this.GetText("GROUPS")}:</strong> {groupsText}"; // Remove the space before the first comma when multiple groups exist. filler = filler.Replace("\r\n,", ","); return(filler); }
/// <summary> /// The bind data. /// </summary> private void BindData() { MembershipUser user = UserMembershipHelper.GetMembershipUserById(this.UserId); if (user == null || user.ProviderUserKey.ToString() == "0") { YafBuildLink.AccessDenied(/*No such user exists or this is an nntp user ("0") */); } var userData = new CombinedUserDataHelper(user, this.UserId); // populate user information controls... // Is BuddyList feature enabled? if (YafContext.Current.BoardSettings.EnableBuddyList) { this.SetupBuddyList(this.UserId, userData); } else { // BuddyList feature is disabled. don't show any link. this.lnkBuddy.Visible = false; this.ltrApproval.Visible = false; } // Is album feature enabled? if (YafContext.Current.BoardSettings.EnableAlbum) { this.AlbumList1.UserID = this.UserId; } else { this.AlbumList1.Dispose(); } string userDisplayName = this.PageContext.UserDisplayName.GetName(this.UserId); this.SetupUserProfileInfo(this.UserId, user, userData, userDisplayName); this.AddPageLinks(userDisplayName); this.SetupUserStatistics(userData); // private messages this.SetupUserLinks(userData); // localize tab titles... this.LocalizeTabTitles(this.UserId); this.SetupAvatar(this.UserId, userData); this.Groups.DataSource = RoleMembershipHelper.GetRolesForUser(UserMembershipHelper.GetUserNameFromID(this.UserId)); // EmailRow.Visible = PageContext.IsAdmin; this.ProfileTabs.Views["ModerateTab"].Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator; this.ProfileTabs.Views["ModerateTab"].Text = this.GetText("MODERATION"); this.AdminUserButton.Visible = this.PageContext.IsAdmin; if (this.LastPosts.Visible) { this.LastPosts.DataSource = DB.post_alluser(this.PageContext.PageBoardID, this.UserId, this.PageContext.PageUserID, 10).AsEnumerable(); this.SearchUser.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.search, "postedby={0}", userDisplayName); } this.DataBind(); }