Пример #1
0
        public void UserList_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":
                YAF.Classes.Utils.YafBuildLink.Redirect(YAF.Classes.Utils.ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "delete":
                UserMembershipHelper.DeleteUser(Convert.ToInt32(e.CommandArgument));
                BindData();
                break;

            case "approve":
                UserMembershipHelper.ApproveUser(Convert.ToInt32(e.CommandArgument));
                BindData();
                break;

            case "deleteall":
                UserMembershipHelper.DeleteAllUnapproved(DateTime.Now.AddDays(-14));
                //YAF.Classes.Data.DB.user_deleteold( PageContext.PageBoardID );
                BindData();
                break;

            case "approveall":
                UserMembershipHelper.ApproveAll();
                //YAF.Classes.Data.DB.user_approveall( PageContext.PageBoardID );
                BindData();
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// The user list_ item command.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        public void UserList_ItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":

                // we are going to edit user - redirect to edit page
                YafBuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "delete":

                // we are deleting user
                if (this.PageContext.PageUserID == int.Parse(e.CommandArgument.ToString()))
                {
                    // deleting yourself isn't an option
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_USERS", "MSG_SELF_DELETE"));
                    return;
                }

                // get user(s) we are about to delete
                using (
                    DataTable dt = LegacyDb.user_list(this.PageContext.PageBoardID, e.CommandArgument, DBNull.Value))
                {
                    // examine each if he's possible to delete
                    foreach (DataRow row in dt.Rows)
                    {
                        if (row["IsGuest"].ToType <int>() > 0)
                        {
                            // we cannot detele guest
                            this.PageContext.AddLoadMessage(this.GetText("ADMIN_USERS", "MSG_DELETE_GUEST"));
                            return;
                        }

                        if ((row["IsAdmin"] == DBNull.Value || row["IsAdmin"].ToType <int>() <= 0) &&
                            (row["IsHostAdmin"] == DBNull.Value || row["IsHostAdmin"].ToType <int>() <= 0))
                        {
                            continue;
                        }

                        // admin are not deletable either
                        this.PageContext.AddLoadMessage(this.GetText("ADMIN_USERS", "MSG_DELETE_ADMIN"));
                        return;
                    }
                }

                // all is good, user can be deleted
                UserMembershipHelper.DeleteUser(e.CommandArgument.ToType <int>());

                // rebind data
                this.BindData();

                // quit case
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// The user list_ item command.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        public void UserList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":
                YafBuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "delete":
                string daysValue = ControlHelper.FindControlRecursiveAs <TextBox>(PageContext.CurrentForumPage, "DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValue))
                {
                    this.PageContext.AddLoadMessage("You should enter a valid integer value for days.");
                    return;
                }
                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteUser(Convert.ToInt32(e.CommandArgument));
                }

                YAF.Classes.Data.DB.user_delete(e.CommandArgument);
                BindData();
                break;

            case "approve":
                UserMembershipHelper.ApproveUser(Convert.ToInt32(e.CommandArgument));
                BindData();
                break;

            case "deleteall":
                // vzrus: Should not delete the whole providers portal data? Under investigation.
                string daysValueAll = ControlHelper.FindControlRecursiveAs <TextBox>(PageContext.CurrentForumPage, "DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValueAll))
                {
                    this.PageContext.AddLoadMessage("You should enter a valid integer value for days.");
                    return;
                }
                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteAllUnapproved(DateTime.UtcNow.AddDays(-Convert.ToInt32(daysValueAll)));
                }

                YAF.Classes.Data.DB.user_deleteold(PageContext.PageBoardID, Convert.ToInt32(daysValueAll));
                BindData();
                break;

            case "approveall":
                UserMembershipHelper.ApproveAll();
                // vzrus: Should delete users from send email list
                YAF.Classes.Data.DB.user_approveall(PageContext.PageBoardID);
                BindData();
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// The user list_ item command.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        public void UserList_ItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":

                // we are going to edit user - redirect to edit page
                YafBuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "delete":

                // we are deleting user
                if (this.PageContext.PageUserID == int.Parse(e.CommandArgument.ToString()))
                {
                    // deleting yourself isn't an option
                    this.PageContext.AddLoadMessage("You can't delete yourself.");
                    return;
                }

                // get user(s) we are about to delete
                using (DataTable dt = DB.user_list(this.PageContext.PageBoardID, e.CommandArgument, DBNull.Value))
                {
                    // examine each if he's possible to delete
                    foreach (DataRow row in dt.Rows)
                    {
                        if (SqlDataLayerConverter.VerifyInt32(row["IsGuest"]) > 0)
                        {
                            // we cannot detele guest
                            this.PageContext.AddLoadMessage("You can't delete the Guest.");
                            return;
                        }

                        if ((row["IsAdmin"] != DBNull.Value && SqlDataLayerConverter.VerifyInt32(row["IsAdmin"]) > 0) ||
                            (row["IsHostAdmin"] != DBNull.Value && Convert.ToInt32(row["IsHostAdmin"]) > 0))
                        {
                            // admin are not deletable either
                            this.PageContext.AddLoadMessage("You can't delete the Admin.");
                            return;
                        }
                    }
                }

                // all is good, user can be deleted
                UserMembershipHelper.DeleteUser(Convert.ToInt32(e.CommandArgument));

                // rebind data
                this.BindData();

                // quit case
                break;
            }
        }
Пример #5
0
        public void UserList_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":
                YAF.Classes.Utils.YafBuildLink.Redirect(YAF.Classes.Utils.ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "delete":
                if (PageContext.PageUserID == int.Parse(e.CommandArgument.ToString()))
                {
                    PageContext.AddLoadMessage("You can't delete yourself.");
                    return;
                }
                string userName = string.Empty;
                using (DataTable dt = YAF.Classes.Data.DB.user_list(PageContext.PageBoardID, e.CommandArgument, DBNull.Value))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        userName = ( string )row ["Name"];
                        if (SqlDataLayerConverter.VerifyInt32(row ["IsGuest"]) > 0)
                        {
                            PageContext.AddLoadMessage("You can't delete the Guest.");
                            return;
                        }
                        if ((row["IsAdmin"] != DBNull.Value && SqlDataLayerConverter.VerifyInt32(row["IsAdmin"]) > 0) || (row["IsHostAdmin"] != DBNull.Value && Convert.ToInt32(row["IsHostAdmin"]) > 0))
                        {
                            PageContext.AddLoadMessage("You can't delete the Admin.");
                            return;
                        }
                    }
                }
                UserMembershipHelper.DeleteUser(Convert.ToInt32(e.CommandArgument));
                BindData();
                break;
            }
        }
Пример #6
0
        /// <summary>
        /// Handles the ItemCommand event of the UserList control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        public void UserListItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":
                YafBuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "resendEmail":
                var commandArgument = e.CommandArgument.ToString().Split(';');

                var checkMail = this.GetRepository <CheckEmail>().ListTyped(commandArgument[0]).FirstOrDefault();

                if (checkMail != null)
                {
                    var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

                    var subject = this.Get <ILocalization>()
                                  .GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", this.Get <YafBoardSettings>().Name);

                    verifyEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                        ForumPages.approve,
                        true,
                        "k={0}",
                        checkMail.Hash);
                    verifyEmail.TemplateParams["{key}"]       = checkMail.Hash;
                    verifyEmail.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
                    verifyEmail.TemplateParams["{forumlink}"] = YafForumInfo.ForumURL;

                    verifyEmail.SendEmail(new MailAddress(checkMail.Email, commandArgument[1]), subject, true);

                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_MESSAGE_SEND"));
                }
                else
                {
                    var userFound = this.Get <IUserDisplayName>().Find(commandArgument[1]).FirstOrDefault();

                    var user = this.Get <MembershipProvider>().GetUser(userFound.Value, false);

                    this.Get <ISendNotification>().SendVerificationEmail(user, commandArgument[0], userFound.Key);
                }

                break;

            case "delete":
                var daysValue =
                    this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValue))
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"));
                    return;
                }

                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteUser(e.CommandArgument.ToType <int>());
                }

                this.GetRepository <User>().Delete(e.CommandArgument.ToType <int>());

                this.BindData();
                break;

            case "approve":
                UserMembershipHelper.ApproveUser(e.CommandArgument.ToType <int>());
                this.BindData();
                break;

            case "deleteall":

                // vzrus: Should not delete the whole providers portal data? Under investigation.
                var daysValueAll =
                    this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValueAll))
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"));
                    return;
                }

                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteAllUnapproved(DateTime.UtcNow.AddDays(-daysValueAll.ToType <int>()));
                }

                this.GetRepository <User>().DeleteOld(this.PageContext.PageBoardID, daysValueAll.ToType <int>());
                this.BindData();
                break;

            case "approveall":
                UserMembershipHelper.ApproveAll();

                // vzrus: Should delete users from send email list
                this.GetRepository <User>().ApproveAll(this.PageContext.PageBoardID);
                this.BindData();
                break;
            }
        }
Пример #7
0
        /// <summary>
        /// Kills the User
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Kill_OnClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserId);

            // Ban User Email?
            if (this.BanEmail.Checked)
            {
                this.GetRepository <BannedEmail>().Save(
                    null,
                    user.Email,
                    $"Email was reported by: {(this.Get<YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName)}");
            }

            // Ban User IP?
            if (this.BanIps.Checked && this.IPAddresses.Any())
            {
                this.BanUserIps();
            }

            // Ban User IP?
            if (this.BanName.Checked)
            {
                this.GetRepository <BannedName>().Save(
                    null,
                    user.UserName,
                    $"Name was reported by: {(this.Get<YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName)}");
            }

            this.DeleteAllUserMessages();

            if (this.ReportUser.Checked && this.Get <YafBoardSettings>().StopForumSpamApiKey.IsSet() &&
                this.IPAddresses.Any())
            {
                try
                {
                    var stopForumSpam = new StopForumSpam();

                    if (stopForumSpam.ReportUserAsBot(this.IPAddresses.FirstOrDefault(), user.Email, user.UserName))
                    {
                        this.GetRepository <Registry>().IncrementReportedSpammers();

                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "User Reported to StopForumSpam.com",
                            $"User (Name:{user.UserName}/ID:{this.CurrentUserId}/IP:{this.IPAddresses.FirstOrDefault()}/Email:{user.Email}) Reported to StopForumSpam.com by {(this.Get<YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName)}",
                            EventLogTypes.SpamBotReported);
                    }
                }
                catch (Exception exception)
                {
                    this.PageContext.AddLoadMessage(
                        this.GetText("ADMIN_EDITUSER", "BOT_REPORTED_FAILED"),
                        MessageTypes.danger);

                    this.Logger.Log(
                        this.PageContext.PageUserID,
                        $"User (Name{user.UserName}/ID:{this.CurrentUserId}) Report to StopForumSpam.com Failed",
                        exception);
                }
            }

            switch (this.SuspendOrDelete.SelectedValue)
            {
            case "delete":
                if (this.CurrentUserId > 0)
                {
                    // we are deleting user
                    if (this.PageContext.PageUserID == this.CurrentUserId)
                    {
                        // deleting yourself isn't an option
                        this.PageContext.AddLoadMessage(
                            this.GetText("ADMIN_USERS", "MSG_SELF_DELETE"),
                            MessageTypes.danger);
                        return;
                    }

                    // get user(s) we are about to delete
                    using (var dt = this.GetRepository <User>().ListAsDataTable(
                               this.PageContext.PageBoardID,
                               this.CurrentUserId,
                               DBNull.Value))
                    {
                        // examine each if he's possible to delete
                        foreach (DataRow row in dt.Rows)
                        {
                            if (row["IsGuest"].ToType <int>() > 0)
                            {
                                // we cannot delete guest
                                this.PageContext.AddLoadMessage(
                                    this.GetText("ADMIN_USERS", "MSG_DELETE_GUEST"),
                                    MessageTypes.danger);
                                return;
                            }

                            if ((row["IsAdmin"] == DBNull.Value || row["IsAdmin"].ToType <int>() <= 0) &&
                                (row["IsHostAdmin"] == DBNull.Value || row["IsHostAdmin"].ToType <int>() <= 0))
                            {
                                continue;
                            }

                            // admin are not deletable either
                            this.PageContext.AddLoadMessage(
                                this.GetText("ADMIN_USERS", "MSG_DELETE_ADMIN"),
                                MessageTypes.danger);
                            return;
                        }
                    }

                    // all is good, user can be deleted
                    UserMembershipHelper.DeleteUser(this.CurrentUserId.ToType <int>());

                    YafBuildLink.Redirect(ForumPages.admin_users);
                }

                break;

            case "suspend":
                if (this.CurrentUserId > 0)
                {
                    this.GetRepository <User>().Suspend(
                        this.CurrentUserId.ToType <int>(),
                        DateTime.UtcNow.AddYears(5));
                }

                break;
            }

            this.PageContext.AddLoadMessage(
                this.GetTextFormatted("MSG_USER_KILLED", user.UserName),
                MessageTypes.success);

            // update the displayed data...
            this.BindData();
        }
Пример #8
0
        /// <summary>
        /// Handles the ItemCommand event of the UserList control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        public void UserList_ItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":
                YafBuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "delete":
                string daysValue =
                    this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValue))
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"));
                    return;
                }

                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteUser(e.CommandArgument.ToType <int>());
                }

                LegacyDb.user_delete(e.CommandArgument);
                this.Get <ILogger>()
                .Log(
                    this.PageContext.PageUserID,
                    "YAF.Pages.Admin.admin",
                    "User {0} was deleted by {1}.".FormatWith(e.CommandArgument.ToType <int>(), this.PageContext.PageUserID),
                    EventLogTypes.UserDeleted);
                this.BindData();
                break;

            case "approve":
                UserMembershipHelper.ApproveUser(e.CommandArgument.ToType <int>());
                this.BindData();
                break;

            case "deleteall":

                // vzrus: Should not delete the whole providers portal data? Under investigation.
                string daysValueAll =
                    this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValueAll))
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"));
                    return;
                }

                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteAllUnapproved(DateTime.UtcNow.AddDays(-daysValueAll.ToType <int>()));
                }

                LegacyDb.user_deleteold(this.PageContext.PageBoardID, daysValueAll.ToType <int>());
                this.BindData();
                break;

            case "approveall":
                UserMembershipHelper.ApproveAll();

                // vzrus: Should delete users from send email list
                LegacyDb.user_approveall(this.PageContext.PageBoardID);
                this.BindData();
                break;
            }
        }
Пример #9
0
        /// <summary>
        /// Setups the user profile.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="userId">The user identifier.</param>
        private void SetupUserProfile(MembershipUser user, int userId)
        {
            // this is the "Profile Information" step. Save the data to their profile (+ defaults).
            var timeZones       = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("TimeZones");
            var country         = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("Country");
            var locationTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Location");
            var homepageTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Homepage");
            var dstUser         = (CheckBox)this.CreateUserWizard1.FindWizardControlRecursive("DSTUser");

            // setup/save the profile
            YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName);

            if (country.SelectedValue != null)
            {
                userProfile.Country = country.SelectedValue;
            }

            string result;

            if (this.Get <ISpamWordCheck>().CheckForSpamWord(homepageTextBox.Text.Trim(), out result))
            {
                this.IsPossibleSpamBotInternalCheck = true;

                var userIpAddress = this.Get <HttpRequestBase>().GetUserRealIPAddress();

                if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1))
                {
                    // Flag user as spam bot
                    this.IsPossibleSpamBot = true;

                    this.SendSpamBotNotificationToAdmins(user, userId);
                }
                else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2))
                {
                    // Kill user
                    UserMembershipHelper.DeleteUser(userId, true);

                    this.PageContext.AddLoadMessage(this.GetText("BOT_MESSAGE"), MessageTypes.Error);

                    if (this.Get <YafBoardSettings>().BanBotIpOnDetection)
                    {
                        this.GetRepository <BannedIP>()
                        .Save(
                            null,
                            userIpAddress,
                            "A spam Bot who was trying to register was banned by IP {0}".FormatWith(userIpAddress),
                            this.PageContext.PageUserID);

                        // Clear cache
                        this.Get <IDataCache>().Remove(Constants.Cache.BannedIP);

                        if (YafContext.Current.Get <YafBoardSettings>().LogBannedIP)
                        {
                            this.Get <ILogger>()
                            .Log(
                                this.PageContext.PageUserID,
                                "IP BAN of Bot During Registration",
                                "A spam Bot who was trying to register was banned by IP {0}".FormatWith(
                                    userIpAddress),
                                EventLogTypes.IpBanSet);
                        }
                    }
                }

                this.Logger.Log(
                    null,
                    "Bot Detected",
                    "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', email : '{1}', ip: '{2}') reason word: {3}"
                    .FormatWith(user.UserName, this.CreateUserWizard1.Email, userIpAddress, homepageTextBox.Text.Trim()),
                    EventLogTypes.SpamBotDetected);
            }

            if (!this.IsPossibleSpamBotInternalCheck)
            {
                return;
            }

            userProfile.Location = locationTextBox.Text.Trim();
            userProfile.Homepage = homepageTextBox.Text.Trim();

            userProfile.Save();

            // save the time zone...
            LegacyDb.user_save(
                userID: userId,
                boardID: this.PageContext.PageBoardID,
                userName: null,
                displayName: null,
                email: null,
                timeZone: timeZones.SelectedValue.ToType <int>(),
                languageFile: null,
                culture: null,
                themeFile: null,
                textEditor: null,
                useMobileTheme: null,
                approved: null,
                pmNotification: null,
                autoWatchTopics: null,
                dSTUser: dstUser.Checked,
                hideUser: null,
                notificationType: null);

            bool autoWatchTopicsEnabled = this.Get <YafBoardSettings>().DefaultNotificationSetting
                                          == UserNotificationSetting.TopicsIPostToOrSubscribeTo;

            // save the settings...
            LegacyDb.user_savenotification(
                userId,
                true,
                autoWatchTopicsEnabled,
                this.Get <YafBoardSettings>().DefaultNotificationSetting,
                this.Get <YafBoardSettings>().DefaultSendDigestEmail);
        }