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

📄 createuser.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

// 修改说明:增加昵称相关控件 
// 修改人:宝玉
// 修改日期:2005-02-26

using System;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer;
using CommunityServer.Components;


namespace CommunityServer.Controls {

    /// <summary>
    /// This Web control displays the textboxes needed to create a new user account.
    /// The user can enter their username and email, and a warning message is displayed if
    /// either the username or email message is already taken.  Once the user enters an available
    /// username and password, they will be sent a confirmation email with their password.
    /// </summary>
    [
        ParseChildren(true)
    ]
    public class CreateUser : SecureTemplatedWebControl {

		#region Member Variables
        AccountActivation activation = CSContext.Current.SiteSettings.AccountActivation;
        CSContext csContext = CSContext.Current;

        TextBox username;
        TextBox password;
        TextBox emailAddress;
        Button cancelButton;
        Button createButton;
        RequiredFieldValidator usernameValidator;
        RequiredFieldValidator passwordValidator;
        RequiredFieldValidator emailValidator;
        RequiredFieldValidator password2Validator;
        RequiredFieldValidator email2Validator;
        RegularExpressionValidator emailRegExValidator;
        RequiredFieldValidator placeHolderValidator;
        RequiredFieldValidator placeHolderNicknameValidator;
        RegularExpressionValidator usernameRegExValidator;
        CompareValidator compareEmail;
        CompareValidator comparePassword;
		CustomValidator usernameLengthValidator;
		RegularExpressionValidator passwordRegExValidator;
		bool passportAuthentication = false;
        CustomValidator passwordContentValidator;
        CheckBox acceptAgreement;
        RequiredFieldValidator requiredAcceptAgreement;
		#region 新增内容
		private TextBox nickname;
		private RequiredFieldValidator nicknameValidator;
		#endregion
		#endregion

		#region Base class
        // *********************************************************************
        //  CreateUser
        //
        /// <summary>
        /// Constructor
        /// </summary>
        // ***********************************************************************/
        public CreateUser() : base() 
		{

            // If the user is an Administrator or moderator, they can create accounts
            //
			User user = CSContext.Current.User;
            if (user.IsForumAdministrator || user.IsBlogAdministrator || user.IsGalleryAdministrator) {
                activation = AccountActivation.Automatic;
            } else {
                if (!CSContext.Current.SiteSettings.AllowNewUserRegistration)
                    throw new CSException(CSExceptionType.UserAccountRegistrationDisabled);
            }

			
			//SkinName = "Skin-CreateNewAccount.ascx";


        }
		#endregion




		#region Init Skin
        // *********************************************************************
        //  Initializeskin
        //
        /// <summary>
        /// Initialize the control template and populate the control with values
        /// </summary>
        // ***********************************************************************/

		protected override void AttachChildControls()
		{
			if(Context.User.Identity.AuthenticationType.ToLower() == "passport")
				passportAuthentication = true;

			// What account activation mode are we in?
			//
			if (!passportAuthentication) 
			{
                switch (activation) 
                {

                    case AccountActivation.Automatic :
                    case AccountActivation.AdminApproval:
                        FindControl("AccountActivationAutomatic").Visible = true;
                        FindControl("AccountActivationAutomatic2").Visible = true;
                        break;
                    case AccountActivation.Email:
                        FindControl("AccountActivationAutomatic").Visible = false;
                        FindControl("AccountActivationAutomatic2").Visible = false;
                        break;

                }
			}

            // Find the button on the user control and wire-it up to the CreateUser_Click event in this class
            createButton = (Button) FindControl("CreateAccount");
            createButton.Text = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_CreateAccount");
            createButton.Click += new System.EventHandler(CreateUser_Click);

            // Find the cancel button on the user control and wire-it up to the Cancel_Click event in this class
            cancelButton = (Button) FindControl("Cancel");
            cancelButton.Text = CommunityServer.Components.ResourceManager.GetString("Cancel");
            cancelButton.Click += new System.EventHandler(Cancel_Click);

            // Find the other controls
            username = (TextBox) FindControl("Username");
            password = (TextBox) FindControl("Password");
            
            emailAddress = (TextBox) FindControl("Email");
            usernameValidator = (RequiredFieldValidator) FindControl("usernameValidator");
            usernameValidator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_usernameValidator").Replace("'", @"\'");
            usernameRegExValidator = (RegularExpressionValidator) FindControl("usernameRegExValidator");
            usernameRegExValidator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_usernameRegExValidator").Replace("'", @"\'");
            passwordValidator = (RequiredFieldValidator) FindControl("passwordValidator");
            passwordValidator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_passwordValidator").Replace("'", @"\'");
            emailValidator = (RequiredFieldValidator) FindControl("emailValidator");
            emailValidator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_emailValidator").Replace("'", @"\'");
            emailRegExValidator = (RegularExpressionValidator) FindControl("emailRegExValidator");
            emailRegExValidator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_emailRegExValidator").Replace("'", @"\'");
			usernameRegExValidator.ValidationExpression = CSContext.Current.SiteSettings.UsernameRegex;            
            placeHolderValidator = (RequiredFieldValidator) FindControl("placeHolderValidator");
            placeHolderNicknameValidator = (RequiredFieldValidator) FindControl("placeHolderNicknameValidator");
            comparePassword = (CompareValidator) FindControl("ComparePassword");
            comparePassword.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("ChangePassword_ReEnterNewPasswordRequired").Replace("'", @"\'");
            compareEmail = (CompareValidator) FindControl("CompareEmail");
            compareEmail.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_emailNoMatch").Replace("'", @"\'");
            password2Validator = (RequiredFieldValidator) FindControl("password2Validator");
            password2Validator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_passwordValidator").Replace("'", @"\'");
            email2Validator = (RequiredFieldValidator) FindControl("email2Validator");
            email2Validator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_emailValidator").Replace("'", @"\'");
			usernameLengthValidator = FindControl("usernameLengthValidator") as CustomValidator;
            usernameLengthValidator.ErrorMessage = string.Format(ResourceManager.GetString("CreateNewAccount_UsernameLimits"), CSContext.Current.SiteSettings.UsernameMinLength.ToString(), CSContext.Current.SiteSettings.UsernameMaxLength.ToString());
            passwordRegExValidator = FindControl("passwordRegExValidator") as RegularExpressionValidator;
			passwordRegExValidator.ValidationExpression = CSContext.Current.SiteSettings.PasswordRegex;
            passwordRegExValidator.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_PasswordRegExValidator").Replace("'", @"\'");;

            passwordContentValidator = FindControl("passwordContentValidator") as CustomValidator;
            //passwordContentValidator.ErrorMessage = string.Format( ResourceManager.GetString("ChangePassword_InvalidLength"), ms.Membership.MinRequiredPasswordLength.ToString() );

            acceptAgreement = FindControl("AcceptAgreement") as CheckBox;
            requiredAcceptAgreement = FindControl("RequiredAcceptAgreement") as RequiredFieldValidator;
            if (requiredAcceptAgreement != null)
                requiredAcceptAgreement.ErrorMessage = CommunityServer.Components.ResourceManager.GetString("CreateNewAccount_ServicesAgreementRequired").Replace("'", @"\'");
      
			#region 新增内容
			this.nickname = FindControl("Nickname") as TextBox;
			this.nicknameValidator = FindControl("nicknameValidator") as RequiredFieldValidator;
			this.nicknameValidator.ErrorMessage = ResourceManager.GetString("CreateNewAccount_nicknameValidator").Replace("'", @"\'");
			#endregion
		}
		#endregion

        #region Events
        // *********************************************************************
        //  CreateUser_Click
        //
        /// <summary>
        /// This event handler fires when the submit button is clicked and the
        /// form posts back.  It is responsible for updating the user's info
        /// </summary>
        //
        // ********************************************************************/
		private void CreateUser_Click(Object sender, EventArgs e) 
		{
			Microsoft.ScalableHosting.Security.MembershipCreateStatus status = Microsoft.ScalableHosting.Security.MembershipCreateStatus.ProviderError;

			// Is valid?
			if (!Page.IsValid)
				return;

			// Check for site services agreement
			if (!IsAgreementAccepted())
				return;

			// Check the max length on the signature
			//
			if ((username.Text.Length > CSContext.Current.SiteSettings.UsernameMaxLength) || (username.Text.Length < CSContext.Current.SiteSettings.UsernameMinLength)) 
			{
				usernameLengthValidator.IsValid = false;

⌨️ 快捷键说明

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