コード例 #1
0
ファイル: AlbumList.ascx.cs プロジェクト: DaoCalendar/YAFNET
        /// <summary>
        /// Binds the album list data.
        /// </summary>
        private void BindData()
        {
            this.PagerTop.PageSize = this.Get <YafBoardSettings>().AlbumsPerPage;

            // set the Datatable
            var albumListDT = LegacyDb.album_list(this.UserID, null);

            if ((albumListDT == null) || (albumListDT.Rows.Count <= 0))
            {
                return;
            }

            this.PagerTop.Count = albumListDT.Rows.Count;

            // create paged data source for the albumlist
            var pds = new PagedDataSource
            {
                DataSource       = albumListDT.DefaultView,
                AllowPaging      = true,
                CurrentPageIndex = this.PagerTop.CurrentPageIndex,
                PageSize         = this.PagerTop.PageSize
            };

            this.Albums.DataSource = pds;
            this.DataBind();
        }
コード例 #2
0
        /// <summary>
        /// A method to get album path string.
        /// </summary>
        /// <param name="forumPageAttributes">
        /// A page query string cleared from page name.
        /// </param>
        /// <returns>
        /// The string
        /// </returns>
        private string Album([NotNull] string forumPageAttributes)
        {
            string outstring = string.Empty;
            string userID    = forumPageAttributes.Substring(forumPageAttributes.IndexOf("u=") + 2).Trim();

            if (userID.Contains("&"))
            {
                userID = userID.Substring(0, userID.IndexOf("&")).Trim();
            }

            string albumID = forumPageAttributes.Substring(forumPageAttributes.IndexOf("a=") + 2);

            albumID = albumID.Contains("&")
                          ? albumID.Substring(0, albumID.IndexOf("&")).Trim()
                          : albumID.Substring(0).Trim();

            if (ValidationHelper.IsValidInt(userID) && ValidationHelper.IsValidInt(albumID))
            {
                // The DataRow should not be missing in the case
                DataRow dr = LegacyDb.album_list(null, albumID.Trim().ToType <int>()).Rows[0];

                // If album doesn't have a Title, use his ID.
                string albumName = !string.IsNullOrEmpty(dr["Title"].ToString())
                                       ? dr["Title"].ToString()
                                       : dr["AlbumID"].ToString();

                // Render
                if (userID.ToType <int>() != this.UserID)
                {
                    outstring += this.GetText("ACTIVELOCATION", "ALBUM").FormatWith();
                    outstring +=
                        @"<a href=""{0}"" id=""uiseralbumid_{1}"" runat=""server""> {2} </a>".FormatWith(
                            YafBuildLink.GetLink(ForumPages.album, "a={0}", albumID),
                            userID + this.PageContext.PageUserID,
                            HttpUtility.HtmlEncode(albumName));
                    outstring += this.GetText("ACTIVELOCATION", "ALBUM_OFUSER").FormatWith();
                    outstring +=
                        @"<a href=""{0}"" id=""albumuserid_{1}"" runat=""server""> {2} </a>".FormatWith(
                            YafBuildLink.GetLink(ForumPages.profile, "u={0}", userID),
                            userID,
                            HttpUtility.HtmlEncode(UserMembershipHelper.GetUserNameFromID(userID.ToType <long>())));
                }
                else
                {
                    outstring += this.GetText("ACTIVELOCATION", "ALBUM_OWN").FormatWith();
                    outstring +=
                        @"<a href=""{0}"" id=""uiseralbumid_{1}"" runat=""server""> {2} </a>".FormatWith(
                            YafBuildLink.GetLink(ForumPages.album, "a={0}", albumID),
                            userID + this.PageContext.PageUserID,
                            HttpUtility.HtmlEncode(albumName));
                }
            }
            else
            {
                outstring += this.GetText("ACTIVELOCATION", "ALBUM").FormatWith();
            }

            return(outstring);
        }
コード例 #3
0
ファイル: UserMembershipHelper.cs プロジェクト: zghlx/YAFNET
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// The ItemCommand method for the cover buttons. Sets/Removes cover image.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
        protected void AlbumImages_ItemCommand([NotNull] object sender, [NotNull] CommandEventArgs e)
        {
            using (var dt = LegacyDb.album_list(null, this.AlbumID))
            {
                if (dt.Rows[0]["CoverImageID"].ToString() == e.CommandArgument.ToString())
                {
                    LegacyDb.album_save(this.AlbumID, null, null, 0);
                }
                else
                {
                    LegacyDb.album_save(dt.Rows[0]["AlbumID"], null, null, e.CommandArgument);
                }
            }

            this.BindData();
        }
コード例 #5
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            this.PagerTop.PageSize = this.Get <YafBoardSettings>().AlbumImagesPerPage;
            string albumTitle = LegacyDb.album_gettitle(this.AlbumID);

            // if (UserID == PageContext.PageUserID)
            // ltrTitle.Visible = false;
            this.ltrTitleOnly.Text = this.HtmlEncode(albumTitle);
            this.ltrTitle.Text     = albumTitle == string.Empty
                                     ? this.GetText("ALBUM_CHANGE_TITLE")
                                     : this.HtmlEncode(albumTitle);

            // set the Datatable
            var dtAlbumImageList = LegacyDb.album_image_list(this.AlbumID, null);
            var dtAlbum          = LegacyDb.album_list(null, this.AlbumID);

            // Does this album has a cover?
            this._coverImageID = dtAlbum.Rows[0]["CoverImageID"] == DBNull.Value
                                     ? string.Empty
                                     : dtAlbum.Rows[0]["CoverImageID"].ToString();

            if ((dtAlbumImageList == null) || (dtAlbumImageList.Rows.Count <= 0))
            {
                return;
            }

            this.PagerTop.Count = dtAlbumImageList.Rows.Count;

            // Create paged data source for the album image list
            var pds = new PagedDataSource
            {
                DataSource       = dtAlbumImageList.DefaultView,
                AllowPaging      = true,
                CurrentPageIndex = this.PagerTop.CurrentPageIndex,
                PageSize         = this.PagerTop.PageSize
            };

            this.AlbumImages.DataSource = pds;
            this.DataBind();
        }
コード例 #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
        /// <summary>
        /// the page load event.
        /// </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 Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.Get <YafBoardSettings>().EnableAlbum)
            {
                YafBuildLink.AccessDenied();
            }

            if (this.IsPostBack)
            {
                return;
            }

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

            var usrAlbumsAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbums", null);

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

            switch (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"))
            {
            // A new album is being created. check the permissions.
            case "new":

                // Is album feature enabled?
                if (!this.Get <YafBoardSettings>().EnableAlbum)
                {
                    YafBuildLink.AccessDenied();
                }

                // Has the user created maximum number of albums?
                if (usrAlbumsAllowed.HasValue && usrAlbumsAllowed > 0)
                {
                    // Albums count. If we reached limit then we go to info page.
                    if (usrAlbumsAllowed > 0 && (albumSize[0] >= usrAlbumsAllowed))
                    {
                        YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                    }
                }

                /* if (this.Get<YafBoardSettings>().AlbumsMax > 0 &&
                 *                  albumSize[0] > this.Get<YafBoardSettings>().AlbumsMax - 1)
                 *        {
                 *            YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                 *        }*/
                userID = this.PageContext.PageUserID;
                break;

            default:
                userID =
                    LegacyDb.album_list(
                        null, Security.StringToLongOrRedirect(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a")))
                    .Rows[0]["UserID"].ToType <int>();

                if (userID != this.PageContext.PageUserID)
                {
                    YafBuildLink.AccessDenied();
                }

                break;
            }

            var displayName = YafContext.Current.Get <YafBoardSettings>().EnableDisplayName
                                  ? UserMembershipHelper.GetDisplayNameFromID(userID)
                                  : UserMembershipHelper.GetUserNameFromID(userID);

            // Add the page links.
            this.PageLinks.AddRoot();
            this.PageLinks.AddLink(
                displayName,
                YafBuildLink.GetLink(ForumPages.profile, "u={0}&name={1}", userID.ToString(), displayName));
            this.PageLinks.AddLink(
                this.GetText("ALBUMS"), YafBuildLink.GetLink(ForumPages.albums, "u={0}", userID.ToString()));
            this.PageLinks.AddLink(this.GetText("TITLE"), string.Empty);

            this.Back.Text   = this.GetText("BACK");
            this.Upload.Text = this.GetText("UPLOAD");

            this.BindData();

            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;
            }
        }
コード例 #8
0
ファイル: UserMembershipHelper.cs プロジェクト: zghlx/YAFNET
        /// <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);
        }