Exemple #1
0
        /// <summary>
        /// Check if the user needs to be un-suspended or redirected to the info page
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _preLoadPage_HandleEvent(
            [NotNull] object sender,
            [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // check for suspension if enabled...
            if (!this.PageContext.Globals.IsSuspendCheckEnabled)
            {
                return;
            }

            if (!this.PageContext.IsSuspended)
            {
                return;
            }

            if (this.Get <IDateTime>().GetUserDateTime(this.PageContext.SuspendedUntil)
                <= this.Get <IDateTime>().GetUserDateTime(DateTime.UtcNow))
            {
                this.GetRepository <User>().Suspend(this.PageContext.PageUserID);

                this.Get <ISendNotification>().SendUserSuspensionEndedNotification(
                    this.PageContext.CurrentUser.Email,
                    this.Get <IUserDisplayName>().GetName(this.PageContext.CurrentUser));

                this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.PageContext.PageUserID));
            }
            else
            {
                BuildLink.RedirectInfoPage(InfoMessage.Suspended);
            }
        }
Exemple #2
0
        /// <summary>
        /// Check if the user needs to be unsuspended or redirected to the info page
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _preLoadPage_HandleEvent(
            [NotNull] object sender,
            [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // check for suspension if enabled...
            if (!this.PageContext.Globals.IsSuspendCheckEnabled)
            {
                return;
            }

            if (!this.PageContext.IsSuspended)
            {
                return;
            }

            if (this.Get <IDateTime>().GetUserDateTime(this.PageContext.SuspendedUntil)
                <= this.Get <IDateTime>().GetUserDateTime(DateTime.UtcNow))
            {
                LegacyDb.user_suspend(this.PageContext.PageUserID, null);

                this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.PageContext.PageUserID));
            }
            else
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Suspended);
            }
        }
        /// <summary>
        /// The page pre load_ handle event.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void PagePreLoad_HandleEvent([NotNull] object sender, [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // no security features for login/logout pages
            if (this.ForumPageType == ForumPages.login || this.ForumPageType == ForumPages.approve ||
                this.ForumPageType == ForumPages.logout || this.ForumPageType == ForumPages.recoverpassword)
            {
                return;
            }

            // check if login is required
            if (this.PageContext.BoardSettings.RequireLogin && this.PageContext.IsGuest && this.CurrentForumPage.IsProtected)
            {
                // redirect to login page if login is required
                this.CurrentForumPage.RedirectNoAccess();
            }

            // check if it's a "registered user only page" and check permissions.
            if (this.CurrentForumPage.IsRegisteredPage && this.CurrentForumPage.User == null)
            {
                this.CurrentForumPage.RedirectNoAccess();
            }

            // not totally necessary... but provides another layer of protection...
            if (this.CurrentForumPage.IsAdminPage && !this.PageContext.IsAdmin)
            {
                YafBuildLink.AccessDenied();
                return;
            }

            // handle security features...
            if (this.ForumPageType == ForumPages.register && this.PageContext.BoardSettings.DisableRegistrations)
            {
                YafBuildLink.AccessDenied();
            }
        }
        /// <summary>
        /// Check if the user needs to be unsuspended or redirected to the info page
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _preLoadPage_HandleEvent(
            [NotNull] object sender,
            [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // check for suspension if enabled...
            if (!this.PageContext.Globals.IsSuspendCheckEnabled)
            {
                return;
            }

            if (!this.PageContext.IsSuspended)
            {
                return;
            }

            if (this.Get <IDateTime>().GetUserDateTime(dateTime: this.PageContext.SuspendedUntil)
                <= this.Get <IDateTime>().GetUserDateTime(dateTime: DateTime.UtcNow))
            {
                this.GetRepository <User>().Suspend(userId: this.PageContext.PageUserID);

                this.Get <ISendNotification>()
                .SendUserSuspensionEndedNotification(
                    email: this.PageContext.CurrentUserData.Email,
                    userName: this.PageContext.BoardSettings.EnableDisplayName
                            ? this.PageContext.CurrentUserData.DisplayName
                            : this.PageContext.CurrentUserData.UserName);

                this.Get <IRaiseEvent>().Raise(eventObject: new UpdateUserEvent(userId: this.PageContext.PageUserID));
            }
            else
            {
                YafBuildLink.RedirectInfoPage(infoMessage: InfoMessage.Suspended);
            }
        }
        /// <summary>
        /// _pages the pre load_ handle event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _pagePreLoad_HandleEvent([NotNull] object sender, [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // no security features for login/logout pages
            if (this.ForumPageType == ForumPages.search || this.ForumPageType == ForumPages.posts)
            {
                return;
            }

            // clear out any search data in the session.... just in case...
            this.Get <IYafSession>().SearchData = null;
        }