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

📄 createuser2.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
              skin.FindControl("EnableAntiSpamProtection1").Visible = true;
              skin.FindControl("EnableAntiSpamProtection2").Visible = true;
                    
              antiSpamCodeValidator.Enabled = true;
              antiSpamCodeCustomValidator.Enabled = true;
            }
            else {
              skin.FindControl("EnableAntiSpamProtection1").Visible = false;
              skin.FindControl("EnableAntiSpamProtection2").Visible = false;

              antiSpamCodeValidator.Enabled = false;
              antiSpamCodeCustomValidator.Enabled = false;
            }

        }

        #region Events
        public void AntiSpamCodeCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) 
        {
          try {
            string sessVal = HttpContext.Current.Session["forumsAntiSpamTextGen"] as string;
            string inputVal = antiSpamCode.Text as string;
            //HttpContext.Current.Response.Write("anti-spam code:" + sessVal.ToLower() + "<br>");

            if(sessVal != null && inputVal != null && sessVal.ToLower() == inputVal.ToLower()) {
              args.IsValid = true;
            }
            else {
              args.IsValid = false;
            }
          }
          catch {
            args.IsValid = false;
          }
        }        

        // *********************************************************************
        //  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) 
        {
            CreateUserStatus status;

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

            // Reset the placeHolderValidator
            //
            placeHolderValidator.IsValid = true;

            // try to create the new user account
            User user = new User();
            user.Username = username.Text;			
            user.Email = emailAddress.Text;
            user.IsAnonymous = false;

            // What account activation mode are we in?
            //
            switch (activation) {
              case (AccountActivation.AdminApproval) : // added because of AccountActivationAutomatic.Visible=true
              case (AccountActivation.Automatic) :
                    user.Password = password.Text.Trim();
                    break;
                default:
                    user.Password = String.Empty;
                    break;
            }

            // Does the user require approval?
            //
            if (activation == AccountActivation.AdminApproval)
                user.AccountStatus = UserAccountStatus.ApprovalPending;
            else
                user.AccountStatus = UserAccountStatus.Approved;
            
            // Set the Anonymous flag to false
            //
            user.IsAnonymous = false;

            // Attempt to create the user
            //
            if (user.Username == "Anonymous")
                status = CreateUserStatus.DuplicateUsername;
            else if (activation == AccountActivation.Automatic)
                status = Users.Create(user, false);
            else
                status = Users.Create(user, true);

            // Determine if the account was created successfully
            //
            switch (status) {

                // Username already exists!
                case CreateUserStatus.DuplicateUsername:
                    placeHolderValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_CreateUserStatus_DuplicateUsername");
                    placeHolderValidator.IsValid = false;
                    break;

                // Email already exists!
                case CreateUserStatus.DuplicateEmailAddress:
                    placeHolderValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_CreateUserStatus_DuplicateEmailAddress");
                    placeHolderValidator.IsValid = false;
                    break;

                // Unknown failure has occurred!
                case CreateUserStatus.UnknownFailure:
                    placeHolderValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_CreateUserStatus_UnknownFailure");
                    placeHolderValidator.IsValid = false;
                    break;

                // Username is disallowed
                case CreateUserStatus.DisallowedUsername:
                    placeHolderValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_CreateUserStatus_DisallowedUsername");
                    placeHolderValidator.IsValid = false;
                    break;

                // Everything went off fine, good
                case CreateUserStatus.Created:

                    if (!redirect) {
                        placeHolderValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_CreateUserStatus_Created");
                        placeHolderValidator.IsValid = false;
                    } else {

                      if (activation == AccountActivation.AdminApproval)
                          throw new ForumException(ForumExceptionType.UserAccountPending);
                      if(activation == AccountActivation.Email)
                          throw new ForumException(ForumExceptionType.UserAccountCreated);
                      if(activation == AccountActivation.Automatic)
                          throw new ForumException(ForumExceptionType.UserAccountCreatedAuto);
                    }
                    break;
            }			
        }

        void Cancel_Click (Object sender, EventArgs e) {
            // send the user back to from where they came
            Context.Response.Redirect(forumContext.ReturnUrl);
            Context.Response.End();

        }
        #endregion

        // *********************************************************************
        //  Redirect
        //
        /// <summary>
        /// Optionally don't perform redirect when creating a new user
        /// </summary>
        // ***********************************************************************/
        public bool Redirect {
            get {
                return redirect;
            }
            set {
                redirect = value;
            }
        }
    }
}

⌨️ 快捷键说明

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