⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 users.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 3 页
字号:
        //  AddModeratedForumForUser
        //
        /// <summary>
        /// Adds a forum to the user's list of moderated forums.
        /// </summary>
        /// <param name="forum">A ModeratedForum object containing information on the forum to add.</param>
        /// 
        // ********************************************************************/
        public static void AddModeratedForumForUser(ModeratedForum forum) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.AddModeratedForumForUser(forum);			
        }


        // *********************************************************************
        //  RemoveModeratedForumForUser
        //
        /// <summary>
        /// Removes a forum from the user's list of moderated forums.
        /// </summary>
        /// <param name="forum">A ModeratedForum object specifying the forum to remove.</param>
        /// 
        // ********************************************************************/
        public static void RemoveModeratedForumForUser(ModeratedForum forum) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.RemoveModeratedForumForUser(forum);			
        }


        // *********************************************************************
        //  ValidUser
        //
        /// <summary>
        /// Determines if the user is a valid user.
        /// </summary>
        /// <param name="user">The user to check.  Note that the Username and Password properties of the
        /// User object must be set.</param>
        /// <returns>A boolean: true if the user's Username/password are valid; false if they are not,
        /// or if the user has been banned.</returns>
        /// 
        // ********************************************************************/
        public static bool ValidUser(User user) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.ValidUser(user);
        }


        // *********************************************************************
        //  CreateNewUser
        //
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="user">A User object containing information about the user to create.  Only the
        /// Username and Email properties are used here.</param>
        /// <returns></returns>
        /// <remarks>This method chooses a random password for the user and emails the user his new Username/password.
        /// From that point on, the user can configure their settings.</remarks>
        /// 
        // ********************************************************************/
        public static CreateUserStatus CreateNewUser(User user, bool needToSendEmail) {

            // Make sure the username begins with an alpha character
            if (!Regex.IsMatch(user.Username, "^[A-Za-z].*"))
                return CreateUserStatus.InvalidFirstCharacter;

            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            // do we have a password?
            if (user.Password == String.Empty) {
                // assign a temporary password
                const int passwordLength = 10;
                user.Password = Globals.CreateTemporaryPassword(passwordLength);

                needToSendEmail = true;
            }

            CreateUserStatus status = dp.CreateNewUser(user);			// create the user account

            if (status == CreateUserStatus.Created && needToSendEmail)
                // send an email to the user with their new logon info
                Emails.SendEmail(user.Username, EmailTypeEnum.NewUserAccountCreated);

            return status;
        }

        // *********************************************************************
        //  IsTop25User
        //
        /// <summary>
        /// Determines whether the user is part of the top 25 posters.
        /// </summary>
        /// <returns>true if the user is, false if not</returns>
        /// 
        // ********************************************************************/
        public static bool IsTop25User(string username) {
            UserCollection users;
            ArrayList top25Users = new ArrayList();

            // Attempt to read from the Cache
            if (HttpContext.Current.Cache["Top25Users"] == null) {
                users = GetAllUsers(0, 25, SortUsersBy.Posts, 1, null);

                // Add Username values in collection to string array
                foreach (User u in users) {
                    top25Users.Add(u.Username);
                }

                // Add to the Cache
                HttpContext.Current.Cache.Insert("Top25Users", top25Users, null, DateTime.Now.AddHours(6), TimeSpan.Zero);
            }

            top25Users = (ArrayList) HttpContext.Current.Cache["Top25Users"];

            // Is the user in the top 25?
            if (top25Users.Contains(username)) 
                return true;
            else
                return false;
        }

        // *********************************************************************
        //  IsTop50User
        //
        /// <summary>
        /// Determines whether the user is part of the top 26-50 posters.
        /// </summary>
        /// <returns>true if the user is, false if not</returns>
        /// 
        // ********************************************************************/
        public static bool IsTop50User(string username) {
            UserCollection users;
            ArrayList top50Users = new ArrayList();

            // Attempt to read from the Cache
            if (HttpContext.Current.Cache["Top50Users"] == null) {
                users = GetAllUsers(1, 25, SortUsersBy.Posts, 1, null);

                // Add Username values in collection to string array
                foreach (User u in users) {
                    top50Users.Add(u.Username);
                }

                // Add to the Cache
                HttpContext.Current.Cache.Insert("Top50Users", top50Users, null, DateTime.Now.AddHours(3), TimeSpan.Zero);
            }

            top50Users = (ArrayList) HttpContext.Current.Cache["Top50Users"];

            // Is the user in the top 50?
            if (top50Users.Contains(username)) 
                return true;
            else
                return false;
        }


        // *********************************************************************
        //  IsTop100User
        //
        /// <summary>
        /// Determines whether the user is part of the top 51-100 posters.
        /// </summary>
        /// <returns>true if the user is, false if not</returns>
        /// 
        // ********************************************************************/
        public static bool IsTop100User(string username) {
            UserCollection users;
            ArrayList top100Users = new ArrayList();

            // Attempt to read from the Cache
            if (HttpContext.Current.Cache["Top100Users"] == null) {
                users = GetAllUsers(1, 50, SortUsersBy.Posts, 1, null);

                // Add Username values in collection to string array
                foreach (User u in users) {
                    top100Users.Add(u.Username);
                }

                // Add to the Cache
                HttpContext.Current.Cache.Insert("Top100Users", top100Users, null, DateTime.Now.AddHours(3), TimeSpan.Zero);
            }

            top100Users = (ArrayList) HttpContext.Current.Cache["Top100Users"];

            // Is the user in the top 100?
            if (top100Users.Contains(username)) 
                return true;
            else
                return false;
        }

        // *********************************************************************
        //  TotalNumberOfUserAccounts
        //
        /// <summary>
        /// Calculates and returns the total number of user accounts.
        /// </summary>
        /// <returns>The total number of user accounts created.</returns>
        /// 
        // ********************************************************************/
        public static int TotalNumberOfUserAccounts() {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.TotalNumberOfUserAccounts(null, null);
        }

        // *********************************************************************
        //  TotalNumberOfUserAccounts
        //
        /// <summary>
        /// Calculates and returns the total number of user accounts.
        /// </summary>
        /// <returns>The total number of user accounts created.</returns>
        /// 
        // ********************************************************************/
        public static int TotalNumberOfUserAccounts(string usernameBeginsWith, string usernameToFind) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.TotalNumberOfUserAccounts(usernameBeginsWith, usernameToFind);
        }

        // *********************************************************************
        //  SortUsersBy
        //
        /// <summary>
        /// Enum for control how user's are sorted - Note the sort is performed
        /// in the database.
        /// </summary>
        /// 
        // ********************************************************************/
        public enum SortUsersBy {
            JoinedDate = 0,
            Username = 1,
            Website = 2,
            LastActiveDate = 3,
            Posts = 4
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -