Esempio n. 1
0
        /// <summary>
        /// Sends Notifications to Moderators that Message Needs Approval
        /// </summary>
        /// <param name="forumId">The forum id.</param>
        /// <param name="newMessageId">The new message id.</param>
        /// <param name="isSpamMessage">if set to <c>true</c> [is spam message].</param>
        public void ToModeratorsThatMessageNeedsApproval(int forumId, int newMessageId, bool isSpamMessage)
        {
            var moderatorsFiltered = this.Get <DataBroker>().GetAllModerators().Where(f => f.ForumID.Equals(forumId));
            var moderatorUserNames = new List <string>();

            moderatorsFiltered.ForEach(
                moderator =>
            {
                if (moderator.IsGroup)
                {
                    moderatorUserNames.AddRange(AspNetRolesHelper.GetUsersInRole(moderator.Name).Select(u => u.UserName));
                }
                else
                {
                    moderatorUserNames.Add(moderator.Name);
                }
            });

            var themeCss =
                $"{this.Get<BoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}";

            var forumLink = BoardInfo.ForumURL;

            var adminLink = BuildLink.GetLinkNotEscaped(ForumPages.Moderate_UnapprovedPosts, true, "f={0}", forumId);

            var currentContext = HttpContext.Current;

            // send each message...
            moderatorUserNames.Distinct().AsParallel().ForAll(
                userName =>
            {
                HttpContext.Current = currentContext;

                try
                {
                    // add each member of the group
                    var membershipUser = this.Get <IAspNetUsersHelper>().GetUserByName(userName);
                    var userId         =
                        this.Get <IAspNetUsersHelper>().GetUserIDFromProviderUserKey(membershipUser.Id);

                    var languageFile = UserHelper.GetUserLanguageFile(userId);

                    var subject = string.Format(
                        this.Get <ILocalization>().GetText(
                            "COMMON",
                            isSpamMessage
                                        ? "NOTIFICATION_ON_MODERATOR_SPAMMESSAGE_APPROVAL"
                                        : "NOTIFICATION_ON_MODERATOR_MESSAGE_APPROVAL",
                            languageFile),
                        this.BoardSettings.Name);

                    var notifyModerators =
                        new TemplateEmail(
                            isSpamMessage
                                        ? "NOTIFICATION_ON_MODERATOR_SPAMMESSAGE_APPROVAL"
                                        : "NOTIFICATION_ON_MODERATOR_MESSAGE_APPROVAL")
                    {
                        TemplateLanguageFile = languageFile,
                        TemplateParams       =
                        {
                            ["{user}"]      = userName,
                            ["{adminlink}"] = adminLink,
                            ["{themecss}"]  = themeCss,
                            ["{forumlink}"] = forumLink
                        }
                    };

                    notifyModerators.SendEmail(
                        new MailAddress(membershipUser.Email, membershipUser.UserName),
                        subject);
                }
                finally
                {
                    HttpContext.Current = null;
                }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Sends Notifications to Moderators that a Message was Reported
        /// </summary>
        /// <param name="pageForumID">
        /// The page Forum ID.
        /// </param>
        /// <param name="reportedMessageId">
        /// The reported message id.
        /// </param>
        /// <param name="reporter">
        /// The reporter.
        /// </param>
        /// <param name="reportText">
        /// The report Text.
        /// </param>
        public void ToModeratorsThatMessageWasReported(
            int pageForumID,
            int reportedMessageId,
            int reporter,
            string reportText)
        {
            try
            {
                var moderatorsFiltered =
                    this.Get <DataBroker>().GetAllModerators().Where(f => f.ForumID.Equals(pageForumID));
                var moderatorUserNames = new List <string>();

                moderatorsFiltered.ForEach(
                    moderator =>
                {
                    if (moderator.IsGroup)
                    {
                        moderatorUserNames.AddRange(
                            AspNetRolesHelper.GetUsersInRole(moderator.Name).Select(u => u.UserName));
                    }
                    else
                    {
                        moderatorUserNames.Add(moderator.Name);
                    }
                });

                var currentContext = HttpContext.Current;

                // send each message...
                moderatorUserNames.Distinct().AsParallel().ForAll(
                    userName =>
                {
                    HttpContext.Current = currentContext;

                    try
                    {
                        // add each member of the group
                        var membershipUser = this.Get <IAspNetUsersHelper>().GetUserByName(userName);
                        var userId         =
                            this.Get <IAspNetUsersHelper>().GetUserIDFromProviderUserKey(membershipUser.Id);

                        var languageFile = UserHelper.GetUserLanguageFile(userId);

                        var subject = string.Format(
                            this.Get <ILocalization>().GetText(
                                "COMMON",
                                "NOTIFICATION_ON_MODERATOR_REPORTED_MESSAGE",
                                languageFile),
                            this.BoardSettings.Name);

                        var notifyModerators = new TemplateEmail("NOTIFICATION_ON_MODERATOR_REPORTED_MESSAGE")
                        {
                            // get the user localization...
                            TemplateLanguageFile = languageFile,
                            TemplateParams       =
                            {
                                ["{user}"]     = userName,
                                ["{reason}"]   = reportText,
                                ["{reporter}"] =
                                    this.Get <IUserDisplayName>()
                                    .GetName(reporter),
                                ["{adminlink}"] = BuildLink.GetLinkNotEscaped(
                                    ForumPages.Moderate_ReportedPosts,
                                    true,
                                    "f={0}",
                                    pageForumID)
                            }
                        };

                        notifyModerators.SendEmail(
                            new MailAddress(membershipUser.Email, membershipUser.UserName),
                            subject);
                    }
                    finally
                    {
                        HttpContext.Current = null;
                    }
                });
            }
            catch (Exception x)
            {
                // report exception to the forum's event log
                this.Get <ILogger>().Error(
                    x,
                    $"Send Message Report Notification Error for UserID {BoardContext.Current.PageUserID}");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_VALID_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_INTEGER"), MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_ALBUM_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_SIG_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_TOTAL_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            // Role
            long roleId = 0;

            // get role ID from page's parameter
            if (this.Get <HttpRequestBase>().QueryString.Exists("i"))
            {
                roleId = long.Parse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("i"));
            }

            // get new and old name
            var roleName    = this.Name.Text.Trim();
            var oldRoleName = string.Empty;

            // if we are editing existing role, get it's original name
            if (roleId != 0)
            {
                // get the current role name in the DB
                var groups = this.GetRepository <Group>().List(boardId: this.PageContext.PageBoardID);

                groups.ForEach(group => oldRoleName = group.Name);
            }

            // save role and get its ID if it's new (if it's old role, we get it anyway)
            roleId = this.GetRepository <Group>().Save(
                roleId,
                this.PageContext.PageBoardID,
                roleName,
                this.IsAdminX.Checked,
                this.IsGuestX.Checked,
                this.IsStartX.Checked,
                this.IsModeratorX.Checked,
                this.AccessMaskID.SelectedValue,
                this.PMLimit.Text.Trim(),
                this.StyleTextBox.Text.Trim(),
                this.Priority.Text.Trim(),
                this.Description.Text,
                this.UsrSigChars.Text,
                this.UsrSigBBCodes.Text,
                this.UsrSigHTMLTags.Text,
                this.UsrAlbums.Text.Trim(),
                this.UsrAlbumImages.Text.Trim());

            // empty out access table(s)
            this.GetRepository <Active>().DeleteAll();
            this.GetRepository <ActiveAccess>().DeleteAll();

            // see if need to rename an existing role...
            if (oldRoleName.IsSet() && roleName != oldRoleName && AspNetRolesHelper.RoleExists(oldRoleName) &&
                !AspNetRolesHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // transfer users in addition to changing the name of the role...
                var users = AspNetRolesHelper.GetUsersInRole(oldRoleName);

                // delete the old role...
                AspNetRolesHelper.DeleteRole(oldRoleName);

                // create new role...
                AspNetRolesHelper.CreateRole(roleName);

                if (users.Any())
                {
                    // put users into new role...
                    users.ForEach(user => AspNetRolesHelper.AddUserToRole(user, roleName));
                }
            }
            else if (!AspNetRolesHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // if role doesn't exist in provider's data source, create it

                // simply create it
                AspNetRolesHelper.CreateRole(roleName);
            }

            // Access masks for a newly created or an existing role
            if (this.Get <HttpRequestBase>().QueryString.Exists("i"))
            {
                // go through all forums
                for (var i = 0; i < this.AccessList.Items.Count; i++)
                {
                    // get current repeater item
                    var item = this.AccessList.Items[i];

                    // get forum ID
                    var forumId = int.Parse(item.FindControlAs <HiddenField>("ForumID").Value);

                    // save forum access masks for this role
                    this.GetRepository <ForumAccess>().Save(
                        forumId,
                        roleId.ToType <int>(),
                        item.FindControlAs <DropDownList>("AccessmaskID").SelectedValue.ToType <int>());
                }

                BuildLink.Redirect(ForumPages.Admin_Groups);
            }

            // remove caching in case something got updated...
            this.Get <IDataCache>().Remove(Constants.Cache.ForumModerators);

            // Clearing cache with old permissions data...
            this.Get <IDataCache>().Remove(
                k => k.StartsWith(string.Format(Constants.Cache.ActiveUserLazyData, string.Empty)));

            // Clear Styling Caching
            this.Get <IDataCache>().Remove(Constants.Cache.GroupRankStyles);

            // Done, redirect to role editing page
            BuildLink.Redirect(ForumPages.Admin_EditGroup, "i={0}", roleId);
        }