I was tasked with member creation on a site that was already developed for Active Directory, so the log in functionality was there and most of the site was all ready to go (after minor major tweaks).
Here is what I came up with for my create user method (Button_Click
Event).
Please let me know what you think.
protected void createUser_Click(object sender, EventArgs e)
{
var createStatus = new MembershipCreateStatus();
if (IsBarNumberAndEmailValid(email.Text, barNumber.Text))
{
if (password.Text == confirmPassword.Text)
{
var newUser = Membership.CreateUser(username.Text, password.Text, email.Text, securityQuestion.Text, securityAnswer.Text, false, out createStatus);
switch (createStatus)
{
case MembershipCreateStatus.Success:
newUser.Comment = barNumber.Text;
userCreationResults.Text = "User account was created successfully. \n Please check your Email for an activation link";
SendActivationEmail(newUser);
//Roles.AddUserToRole(newUser.ToString(), "Attorney");
Membership.UpdateUser(newUser);
break;
case MembershipCreateStatus.DuplicateUserName:
userCreationResults.Text = "That username is already taken, please choose another username.";
break;
case MembershipCreateStatus.DuplicateEmail:
userCreationResults.Text = "A user with that E-mail address already exists.";
break;
case MembershipCreateStatus.InvalidEmail:
userCreationResults.Text = "Please Enter a valid E-mail address.";
break;
case MembershipCreateStatus.InvalidAnswer:
userCreationResults.Text = "The security answer is not valid.";
break;
case MembershipCreateStatus.InvalidPassword:
userCreationResults.Text = "Please enter a valid Password. please enter a password with at least 7 characters, 1 number and one non-alphanumeric";
break;
default:
userCreationResults.Text = "Unknown Error: Account NOT created.";
break;
}
}
else
{
userCreationResults.Text = "Confirmation Password must match the Password";
}
}
else
{
userCreationResults.Text = "Your Email and/or Bar Number doesn't match UJS Records.";
}
}
the following are Text Boxes
password
barNumber
email
confirmPassword
securityQuestion
securityAnswer
userCreationResults
is a label.
IsBarNumberAndEmailValid
is obviously a Boolean method that checks to make sure the bar number and email match a attorney record in a 3rd-party application.