本文整理汇总了C#中UserAccount.Create方法的典型用法代码示例。如果您正苦于以下问题:C# UserAccount.Create方法的具体用法?C# UserAccount.Create怎么用?C# UserAccount.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserAccount
的用法示例。
在下文中一共展示了UserAccount.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateUser
/// <summary>
/// Make a new end user in the database
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="email"></param>
/// <param name="passwordQuestion"></param>
/// <param name="passwordAnswer"></param>
/// <param name="isApproved"></param>
/// <param name="providerUserKey"></param>
/// <param name="status"></param>
/// <returns></returns>
public override MembershipUser CreateUser(
string username,
string password,
string email,
string passwordQuestion,
string passwordAnswer,
bool isApproved,
object providerUserKey,
out MembershipCreateStatus status
)
{
username = username.Trim();
password = password.Trim();
email = email.Trim();
if (passwordQuestion != null)
{
passwordQuestion = passwordQuestion.Trim();
}
if (passwordAnswer != null)
{
passwordAnswer = passwordAnswer.Trim();
}
// Validate username/password
var args = new ValidatePasswordEventArgs(username, password, true);
OnValidatingPassword(args);
if (args.Cancel)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty)
{
status = MembershipCreateStatus.DuplicateEmail;
return null;
}
// Check whether user with passed username already exists
MembershipUser mu = GetUser(username, false);
if (mu == null)
{
var eu = new UserAccount
{
UserName = username,
EMail = email,
Password = EncodePassword(password),
PasswordFormat = MembershipPasswordFormat.Hashed.ToString(),
PasswordSalt = string.Empty,
PasswordQuestion = passwordQuestion,
PasswordAnswer = EncodePassword(passwordAnswer),
FailedPasswordAttemptCount = 0,
IsOnLine = false,
IsApproved = isApproved,
Comment = string.Empty,
IsLockedOut = false,
};
try
{
eu.Create();
status = eu.UserAccountID > 0 ? MembershipCreateStatus.Success : MembershipCreateStatus.UserRejected;
}
catch
{
status = MembershipCreateStatus.UserRejected;
}
return GetUser(username, false);
}
status = MembershipCreateStatus.DuplicateUserName;
return null;
}