📄 createuser2.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetForums;
using AspNetForums.Components;
using System.ComponentModel;
using System.IO;
using AspNetForums.Enumerations;
namespace AspNetForums.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 CreateUser2 : SkinnedForumWebControl {
AccountActivation activation = Globals.GetSiteSettings().AccountActivation;
ForumContext forumContext = ForumContext.Current;
bool redirect = true;
string skinFilename = "Skin-CreateNewAccount2.ascx";
TextBox username;
TextBox password;
TextBox emailAddress;
Button cancelButton;
Button createButton;
RequiredFieldValidator usernameValidator;
RequiredFieldValidator passwordValidator;
RequiredFieldValidator emailValidator;
RequiredFieldValidator password2Validator;
RequiredFieldValidator email2Validator;
RegularExpressionValidator emailRegExValidator;
RequiredFieldValidator placeHolderValidator;
RegularExpressionValidator usernameRegExValidator;
CompareValidator compareEmail;
CompareValidator comparePassword;
TextBox antiSpamCode;
RequiredFieldValidator antiSpamCodeValidator;
CustomValidator antiSpamCodeCustomValidator;
// *********************************************************************
// CreateUser
//
/// <summary>
/// Constructor
/// </summary>
// ***********************************************************************/
public CreateUser2() : base()
{
// If the user is an Administrator they can create accounts
//
if (Users.GetUser().IsAdministrator) {
activation = AccountActivation.Automatic;
} else {
if (!Globals.GetSiteSettings().AllowNewUserRegistration)
throw new ForumException(ForumExceptionType.UserAccountRegistrationDisabled);
}
// Assign a default template name
if (SkinFilename == null)
SkinFilename = skinFilename;
}
// *********************************************************************
// Initializeskin
//
/// <summary>
/// Initialize the control template and populate the control with values
/// </summary>
// ***********************************************************************/
override protected void InitializeSkin(Control skin) {
// What account activation mode are we in?
//
switch (activation) {
case (AccountActivation.Automatic) :
skin.FindControl("AccountActivationAutomatic").Visible = true;
skin.FindControl("AccountActivationAutomatic2").Visible = true;
break;
case (AccountActivation.Email):
break;
case (AccountActivation.AdminApproval):
skin.FindControl("AccountActivationAutomatic").Visible = true;
skin.FindControl("AccountActivationAutomatic2").Visible = true;
break;
}
// Find the button on the user control and wire-it up to the CreateUser_Click event in this class
createButton = (Button) skin.FindControl("CreateAccount");
createButton.Text = AspNetForums.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) skin.FindControl("Cancel");
cancelButton.Text = AspNetForums.Components.ResourceManager.GetString("Cancel");
cancelButton.Click += new System.EventHandler(Cancel_Click);
// Find the other controls
username = (TextBox) skin.FindControl("Username");
password = (TextBox) skin.FindControl("Password");
emailAddress = (TextBox) skin.FindControl("Email");
usernameValidator = (RequiredFieldValidator) skin.FindControl("usernameValidator");
usernameValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_usernameValidator");
usernameRegExValidator = (RegularExpressionValidator) skin.FindControl("usernameRegExValidator");
usernameRegExValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_usernameRegExValidator");
passwordValidator = (RequiredFieldValidator) skin.FindControl("passwordValidator");
passwordValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_passwordValidator");
emailValidator = (RequiredFieldValidator) skin.FindControl("emailValidator");
emailValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_emailValidator");
emailRegExValidator = (RegularExpressionValidator) skin.FindControl("emailRegExValidator");
emailRegExValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_emailRegExValidator");
placeHolderValidator = (RequiredFieldValidator) skin.FindControl("placeHolderValidator");
comparePassword = (CompareValidator) skin.FindControl("ComparePassword");
comparePassword.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("ChangePassword_ReEnterNewPasswordRequired");
compareEmail = (CompareValidator) skin.FindControl("CompareEmail");
compareEmail.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_emailNoMatch");
password2Validator = (RequiredFieldValidator) skin.FindControl("password2Validator");
password2Validator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_passwordValidator");
email2Validator = (RequiredFieldValidator) skin.FindControl("email2Validator");
email2Validator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_emailValidator");
antiSpamCode = (TextBox) skin.FindControl("antiSpamCode");
antiSpamCodeValidator = (RequiredFieldValidator) skin.FindControl("antiSpamCodeValidator");
antiSpamCodeValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_AntiSpamCodeValidatorMsg");
antiSpamCodeCustomValidator = (CustomValidator) skin.FindControl("antiSpamCodeCustomValidator");
antiSpamCodeCustomValidator.ErrorMessage = AspNetForums.Components.ResourceManager.GetString("CreateNewAccount_AntiSpamCodeCustomValidatorMsg");
antiSpamCodeCustomValidator.ServerValidate += new ServerValidateEventHandler(AntiSpamCodeCustomValidator_ServerValidate);
// Do validations on server only
//
usernameValidator.EnableClientScript = false;
usernameRegExValidator.EnableClientScript = false;
passwordValidator.EnableClientScript = false;
emailValidator.EnableClientScript = false;
emailRegExValidator.EnableClientScript = false;
comparePassword.EnableClientScript = false;
compareEmail.EnableClientScript = false;
password2Validator.EnableClientScript = false;
email2Validator.EnableClientScript = false;
placeHolderValidator.EnableClientScript = false;
antiSpamCodeValidator.EnableClientScript = false;
antiSpamCodeCustomValidator.EnableClientScript = false;
// Enable/Disable anti-spam protection rows & validators
//
if(true /*Globals.GetSiteSettings().EnableAntiSpamProtection*/) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -