Пример #1
0
        /// <summary>
        /// Deletes the album and all the images in it.
        /// </summary>
        /// <param name="sender">
        /// the sender.
        /// </param>
        /// <param name="e">
        /// the e.
        /// </param>
        protected void DeleteAlbum_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            string sUpDir = this.Request.MapPath(
                String.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));

            YafAlbum.Album_Image_Delete(
                sUpDir, this.Request.QueryString.GetFirstOrDefault("a"), this.PageContext.PageUserID, null);
            YafBuildLink.Redirect(ForumPages.albums, "u={0}", this.PageContext.PageUserID);
        }
Пример #2
0
        /// <summary>
        /// Deletes the user.
        /// </summary>
        /// <param name="userID">The user id.</param>
        /// <param name="isBotAutoDelete">if set to <c>true</c> [is bot automatic delete].</param>
        /// <returns>
        /// Returns if Deleting was successfully
        /// </returns>
        public static bool DeleteUser(int userID, bool isBotAutoDelete = false)
        {
            var userName = GetUserNameFromID(userID);

            if (userName.IsNotSet())
            {
                return(false);
            }

            // Delete the images/albums both from database and physically.
            var uploadFolderPath =
                HttpContext.Current.Server.MapPath(
                    string.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));

            using (DataTable dt = LegacyDb.album_list(userID, null))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    YafAlbum.Album_Image_Delete(uploadFolderPath, dr["AlbumID"], userID, null);
                }
            }

            // Check if there are any avatar images in the uploads folder
            if (!YafContext.Current.Get <YafBoardSettings>().UseFileTable &&
                YafContext.Current.Get <YafBoardSettings>().AvatarUpload)
            {
                string[] imageExtensions = { "jpg", "jpeg", "gif", "png", "bmp" };

                foreach (var extension in imageExtensions)
                {
                    if (File.Exists(Path.Combine(uploadFolderPath, "{0}.{1}".FormatWith(userID, extension))))
                    {
                        File.Delete(Path.Combine(uploadFolderPath, "{0}.{1}".FormatWith(userID, extension)));
                    }
                }
            }

            YafContext.Current.Get <MembershipProvider>().DeleteUser(userName, true);
            LegacyDb.user_delete(userID);
            YafContext.Current.Get <ILogger>()
            .Log(
                YafContext.Current.PageUserID,
                "UserMembershipHelper.DeleteUser",
                "User {0} was deleted by {1}.".FormatWith(
                    userName,
                    isBotAutoDelete ? "the automatic spam check system" : YafContext.Current.PageUserName),
                EventLogTypes.UserDeleted);

            // clear the cache
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.UsersOnlineStatus);
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.BoardUserStats);
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.UsersDisplayNameCollection);

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Deletes the album and all the images in it.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void DeleteAlbum_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            string sUpDir =
                this.Get <HttpRequestBase>().MapPath(
                    string.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));

            YafAlbum.Album_Image_Delete(
                sUpDir, this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"), this.PageContext.PageUserID, null);

            // clear the cache for this user to update albums|images stats...
            this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.PageContext.PageUserID));

            YafBuildLink.Redirect(ForumPages.albums, "u={0}", this.PageContext.PageUserID);
        }
Пример #4
0
        /// <summary>
        /// The repater Item command event responsible for handling deletion of uploaded files.
        /// </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>
        protected void List_ItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "delete":
                string sUpDir =
                    this.Get <HttpRequestBase>().MapPath(
                        String.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));

                YafAlbum.Album_Image_Delete(sUpDir, null, this.PageContext.PageUserID, e.CommandArgument.ToType <int>());

                // If the user is trying to edit an existing album, initialize the repeater.
                this.BindVariousControls(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a").Equals("new"));

                DataTable sigData = LegacyDb.user_getalbumsdata(this.PageContext.PageUserID, YafContext.Current.PageBoardID);

                //int[] albumSize = LegacyDb.album_getstats(this.PageContext.PageUserID, null);

                var usrAlbumImagesAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbumImages", null);

                // Has the user uploaded maximum number of images?
                // vzrus: changed for DB check The default number of album images is 0. In the case albums are disabled.
                if (usrAlbumImagesAllowed.HasValue && usrAlbumImagesAllowed > 0)
                {
                    if (this.List.Items.Count >= usrAlbumImagesAllowed)
                    {
                        this.uploadtitletr.Visible = false;
                        this.selectfiletr.Visible  = false;
                    }
                    else
                    {
                        this.uploadtitletr.Visible = true;
                        this.selectfiletr.Visible  = true;
                    }

                    this.imagesInfo.Text = this.GetTextFormatted(
                        "IMAGES_INFO", this.List.Items.Count, usrAlbumImagesAllowed, this.Get <YafBoardSettings>().AlbumImagesSizeMax / 1024);
                }
                else
                {
                    this.uploadtitletr.Visible = false;
                    this.selectfiletr.Visible  = false;
                }

                break;
            }
        }
Пример #5
0
        /// <summary>
        /// The repater Item command event responsible for handling deletion of uploaded files.
        /// </summary>
        /// <param name="source">
        /// the source.
        /// </param>
        /// <param name="e">
        /// the e.
        /// </param>
        protected void List_ItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "delete":
                string sUpDir =
                    this.Request.MapPath(String.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));
                YafAlbum.Album_Image_Delete(sUpDir, null, this.PageContext.PageUserID,
                                            Convert.ToInt32(e.CommandArgument));

                this.BindData();

                DataTable sigData = DB.user_getalbumsdata(this.PageContext.PageUserID, YafContext.Current.PageBoardID);


                int[] albumSize = DB.album_getstats(this.PageContext.PageUserID, null);

                var usrAlbumImagesAllowed =
                    sigData.GetFirstRowColumnAsValue <int?>(
                        "UsrAlbumImages", null);
                // Has the user uploaded maximum number of images?
                // vzrus: changed for DB check The default number of album images is 0. In the case albums are disabled.
                if (usrAlbumImagesAllowed.HasValue && usrAlbumImagesAllowed > 0)
                {
                    if (List.Items.Count >= usrAlbumImagesAllowed)
                    {
                        this.uploadtitletr.Visible = false;
                        this.selectfiletr.Visible  = false;
                    }
                    else
                    {
                        this.uploadtitletr.Visible = true;
                        this.selectfiletr.Visible  = true;
                    }

                    this.imagesInfo.Text = this.PageContext.Localization.GetTextFormatted("IMAGES_INFO",
                                                                                          List.Items.Count, usrAlbumImagesAllowed);
                }
                else
                {
                    this.uploadtitletr.Visible = false;
                    this.selectfiletr.Visible  = false;
                }

                break;
            }
        }
Пример #6
0
        /// <summary>
        /// Deletes the user.
        /// </summary>
        /// <param name="userID">The user id.</param>
        /// <returns>
        /// Returns if Deleting was successfully
        /// </returns>
        public static bool DeleteUser(int userID)
        {
            string userName = GetUserNameFromID(userID);

            if (userName.IsNotSet())
            {
                return(false);
            }

            // Delete the images/albums both from database and physically.
            string sUpDir =
                HttpContext.Current.Server.MapPath(
                    string.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));

            using (DataTable dt = LegacyDb.album_list(userID, null))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    YafAlbum.Album_Image_Delete(sUpDir, dr["AlbumID"], userID, null);
                }
            }

            YafContext.Current.Get <MembershipProvider>().DeleteUser(userName, true);
            LegacyDb.user_delete(userID);
            YafContext.Current.Get <ILogger>()
            .Log(
                YafContext.Current.PageUserID,
                "UserMembershipHelper.DeleteUser",
                "User {0} was deleted by user id {1}.".FormatWith(userName, YafContext.Current.PageUserID),
                EventLogTypes.UserDeleted);

            // clear the cache
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.UsersOnlineStatus);
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.BoardUserStats);
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.UsersDisplayNameCollection);

            return(true);
        }
Пример #7
0
 public YafAlbum.ReturnClass ChangeImageCaption(int imageID, [NotNull] string newCaption)
 {
     return(YafAlbum.ChangeImageCaption(imageID, newCaption));
 }
Пример #8
0
 public YafAlbum.ReturnClass ChangeAlbumTitle(int albumID, [NotNull] string newTitle)
 {
     return(YafAlbum.ChangeAlbumTitle(albumID, newTitle));
 }
Пример #9
0
        /// <summary>
        /// Deletes and ban's the user.
        /// </summary>
        /// <param name="userID">The user id.</param>
        /// <param name="user">The MemberShip User.</param>
        /// <param name="userIpAddress">The user's IP address.</param>
        /// <returns>
        /// Returns if Deleting was successfully
        /// </returns>
        public static bool DeleteAndBanUser(int userID, MembershipUser user, string userIpAddress)
        {
            // Ban IP ?
            if (YafContext.Current.Get <YafBoardSettings>().BanBotIpOnDetection)
            {
                YafContext.Current.GetRepository <BannedIP>()
                .Save(
                    null,
                    userIpAddress,
                    "A spam Bot who was trying to register was banned by IP {0}".FormatWith(userIpAddress),
                    userID);

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

                if (YafContext.Current.Get <YafBoardSettings>().LogBannedIP)
                {
                    YafContext.Current.Get <ILogger>()
                    .Log(
                        userID,
                        "IP BAN of Bot",
                        "A spam Bot who was banned by IP {0}".FormatWith(userIpAddress),
                        EventLogTypes.IpBanSet);
                }
            }

            // Ban Name ?
            YafContext.Current.GetRepository <BannedName>()
            .Save(null, user.UserName, "Name was reported by the automatic spam system.");

            // Ban User Email?
            YafContext.Current.GetRepository <BannedEmail>()
            .Save(null, user.Email, "Email was reported by the automatic spam system.");

            // Delete the images/albums both from database and physically.
            var uploadDir =
                HttpContext.Current.Server.MapPath(
                    string.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads));

            using (DataTable dt = LegacyDb.album_list(userID, null))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    YafAlbum.Album_Image_Delete(uploadDir, dr["AlbumID"], userID, null);
                }
            }

            // delete posts...
            var messageIds =
                (from m in LegacyDb.post_alluser_simple(
                     YafContext.Current.PageBoardID,
                     userID).AsEnumerable()
                 select m.Field <int>("MessageID")).Distinct().ToList();

            messageIds.ForEach(x => LegacyDb.message_delete(x, true, string.Empty, 1, true));

            YafContext.Current.Get <MembershipProvider>().DeleteUser(user.UserName, true);
            LegacyDb.user_delete(userID);
            YafContext.Current.Get <ILogger>()
            .Log(
                YafContext.Current.PageUserID,
                "UserMembershipHelper.DeleteUser",
                "User {0} was deleted by the automatic spam check system.".FormatWith(user.UserName),
                EventLogTypes.UserDeleted);

            // clear the cache
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.UsersOnlineStatus);
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.BoardUserStats);
            YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.UsersDisplayNameCollection);

            return(true);
        }