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

📄 users.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 3 页
字号:
                IWebForumsDataProviderBase dp = DataProvider.Instance();

                userId = Guid.NewGuid().ToString();
        
                HttpContext.Current.Response.Cookies[cookieName].Expires = DateTime.Now.AddMinutes(15);
                HttpContext.Current.Response.Cookies[cookieName].Value = userId;

                // If it's a new user only...
                dp.TrackAnonymousUsers(userId);
            }
        }

        // *********************************************************************
        //  GetAnonymousUsersOnline
        //
        /// <summary>
        /// Returns total number of anonymous users currently online.
        /// </summary>
        /// <returns>A numerical value of for the number online</returns>
        /// 
        // ********************************************************************/
        public static int GetAnonymousUsersOnline() {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.TotalAnonymousUsersOnline();
        }

        // *********************************************************************
        //  GetMostActiveUsers
        //
        /// <summary>
        /// Returns a list of the users that have added the most posts
        /// </summary>
        /// <returns>A UserCollection</returns>
        /// 
        // ********************************************************************/
        public static UserCollection GetMostActiveUsers() {
            UserCollection users;

            // Only update once every 24 hours
            if (HttpContext.Current.Cache["MostActiveUsers"] == null) {
                // Create Instance of the IWebForumsDataProviderBase
                IWebForumsDataProviderBase dp = DataProvider.Instance();

                // Get the collection
                users = dp.GetMostActiveUsers();

                // add to the cache
                HttpContext.Current.Cache.Insert("MostActiveUsers", users, null, DateTime.Now.AddDays(1), TimeSpan.Zero);

            }

            return (UserCollection) HttpContext.Current.Cache["MostActiveUsers"];

       }

        // *********************************************************************
        //  GetLoggedOnUser
        //
        /// <summary>
        /// Short-cut for getting back a user instance
        /// </summary>
        /// <returnsA User instance based off the value of User.Identity.Name</returns>
        /// 
        // ********************************************************************/
        public static User GetLoggedOnUser() {
        
            if (!HttpContext.Current.Request.IsAuthenticated)
                return null;

            return Users.GetUserInfo(HttpContext.Current.User.Identity.Name, true);
        }


        // *********************************************************************
        //  UpdateUserInfo
        //
        /// <summary>
        /// Updates a user's personal information.
        /// </summary>
        /// <param name="user">The user to update.  The Username indicates what user to update.</param>
        /// <param name="NewPassword">If the user is changing their password, the user's new password.
        /// Otherwise, this should be the user's existing password.</param>
        /// <returns>This method returns a boolean: it returns True if
        /// the update succeeds, false otherwise.  (The update might fail if the user enters an
        /// incorrect password.)</returns>
        /// <remarks>For the user to update their information, they must supply their password.  Therefore,
        /// the Password property of the user object passed in should be set to the user's existing password.
        /// The NewPassword parameter should contain the user's new password (if they are changing it) or
        /// existing password if they are not.  From this method, only the user's personal information can
        /// be updated (the user's password, forum view settings, email address, etc.); to update the user's
        /// system-level settings (whether or not they are banned, their trusted status, etc.), use the
        /// UpdateUserInfoFromAdminPage method.  <seealso cref="UpdateUserInfoFromAdminPage"/></remarks>
        /// 
        // ********************************************************************/
        public static bool UpdateUserProfile(User user) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();
            bool updatePasswordSucceded = false;

            // we need to strip the <script> tags from input forms
            user.Signature = StripScriptTagsFromInput(user.Signature);
            user.AolIM = Globals.HtmlEncode(user.AolIM);
            user.Email = Globals.HtmlEncode(user.Email);
            user.PublicEmail = Globals.HtmlEncode(user.PublicEmail);
            user.IcqIM = Globals.HtmlEncode(user.IcqIM);
            user.Interests = Globals.HtmlEncode(user.Interests);
            user.Location = Globals.HtmlEncode(user.Location);
            user.MsnIM = Globals.HtmlEncode(user.MsnIM);
            user.Occupation = Globals.HtmlEncode(user.Occupation);
            user.Url = Globals.HtmlEncode(user.Url);
            user.Username = StripScriptTagsFromInput(user.Username);
            user.YahooIM = Globals.HtmlEncode(user.YahooIM);

            // Call the underlying update
            updatePasswordSucceded = dp.UpdateUserProfile(user);

            // Remove from the cache if it exists
            HttpContext.Current.Cache.Remove("UserInfo-" + user.Username);

            return updatePasswordSucceded;
        }

        // *********************************************************************
        //  StripScriptTagsFromInput
        //
        /// <summary>
        /// Helper function used to ensure we don't inject script into the db.
        /// </summary>
        /// <param name="dirtyText">Text to be cleaned for script tags</param>
        /// <returns>Clean text with no script tags.</returns>
        /// 
        // ********************************************************************/
        public static string StripScriptTagsFromInput(string dirtyText) {
            string cleanText;

            // Perform RegEx
            cleanText = Regex.Replace(dirtyText, "<script((.|\n)*?)</script>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            return cleanText;
        }

        // *********************************************************************
        //  GetUsersByFirstCharacter
        //
        /// <summary>
        /// Returns a list of users whose username starts with FirstCharacter.
        /// </summary>
        /// <param name="FirstCharacter">The starting letter of users you are interested in
        /// viewing.</param>
        /// <returns>A UserCollection populated with the users whose Username begins with FirstCharacter.</returns>
        /// 
        // ********************************************************************/
        public static UserCollection GetUsersByFirstCharacter(String FirstCharacter) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetUsersByFirstCharacter(FirstCharacter);			
        }

        // *********************************************************************
        //  UpdateUserInfoFromAdminPage
        //
        /// <summary>
        /// Updates a user's system-level information.
        /// </summary>
        /// <param name="user">A user object containing information to be updated.  The Username
        /// property specifies what user should be updated.</param>
        /// <remarks>This method updates a user's system-level information: their approved status, their
        /// trusted status, etc.  To update a user's personal information (such as their password,
        /// signature, homepage Url, etc.), use the UpdateUserInfo method.  <seealso cref="UpdateUserInfo"/></remarks>
        /// 
        // ********************************************************************/
        public static void UpdateUserInfoFromAdminPage(User user) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.UpdateUserInfoFromAdminPage(user);			
        }


        // *********************************************************************
        //  GetForumsModeratedByUser
        //
        /// <summary>
        /// Returns a list of forums moderated by a particular user.
        /// </summary>
        /// <param name="Username">The user whose list of moderated forums you are interested in viewing.</param>
        /// <returns>A ModeratedForumCollection containing a listing of the forums moderated by the specified
        /// user.</returns>
        /// 
        // ********************************************************************/
        public static ModeratedForumCollection GetForumsModeratedByUser(String Username) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetForumsModeratedByUser(Username);			
        }


        // *********************************************************************
        //  GetForumsNotModeratedByUser
        //
        /// <summary>
        /// Returns a list of forums that are NOT moderated by the specified user.
        /// </summary>
        /// <param name="Username">The Username of the user whose list of non-moderated forums you
        /// are interested in.</param>
        /// <returns>A ModeratedForumColelction containing a listing of the forums NOT moderated by the 
        /// specified user.</returns>
        /// 
        // ********************************************************************/
        public static ModeratedForumCollection GetForumsNotModeratedByUser(String Username) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetForumsNotModeratedByUser(Username);			
        }

        // *********************************************************************
        //  ToggleOptions
        //
        /// <summary>
        /// Toggle various user options
        /// </summary>
        /// <param name="username">Name of user we're updating</param>
        /// <param name="hideReadThreads">Hide threads that the user has already read</param>
        /// 
        // ********************************************************************/
        public static void ToggleOptions(string username, bool hideReadThreads) {
            ToggleOptions(username, hideReadThreads, ViewOptions.NotSet);			
        }

        // *********************************************************************
        //  ToggleOptions
        //
        /// <summary>
        /// Toggle various user options
        /// </summary>
        /// <param name="username">Name of user we're updating</param>
        /// <param name="hideReadThreads">Hide threads that the user has already read</param>
        /// <param name="viewOptions">How the user views posts</param>
        /// 
        // ********************************************************************/
        public static void ToggleOptions(string username, bool hideReadThreads, ViewOptions viewOptions) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.ToggleOptions(username, hideReadThreads, viewOptions);			
        }

        // *********************************************************************

⌨️ 快捷键说明

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