本文整理汇总了C#中MembershipCreateStatus类的典型用法代码示例。如果您正苦于以下问题:C# MembershipCreateStatus类的具体用法?C# MembershipCreateStatus怎么用?C# MembershipCreateStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MembershipCreateStatus类属于命名空间,在下文中一共展示了MembershipCreateStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Page.Validate();
if (Page.IsValid)
{
StockplayMembershipProvider provider = (StockplayMembershipProvider) Membership.Provider;
MembershipCreateStatus status = new MembershipCreateStatus();
provider.CreateUser(UserName.Text, Password.Text, Email.Text,
txtLastname.Text, txtFirstname.Text,- 1, out status);
if (status != MembershipCreateStatus.Success)
{
ErrorLabel.Visible = true;
}
else
{
ErrorLabel.Visible = false;
TableRegister.Visible = false;
FinishRegistration.Visible = true;
try
{
SendMail();
}
catch (Exception ex)
{
ILog sysLog = LogManager.GetLogger("Register");
sysLog.Error("Failed to send e-mail", ex);
}
}
}
}
}
示例2: CreateUser
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
if (string.IsNullOrEmpty(username))
{
status = MembershipCreateStatus.InvalidUserName;
return null;
}
if (string.IsNullOrEmpty(password))
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
string hashedPassword = Crypto.HashPassword(password);
if (hashedPassword.Length > 128)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
if (_userRepository.UserNameTaken(username))
{
status = MembershipCreateStatus.DuplicateUserName;
return null;
}
var newBorn = _userRepository.CreateUser(username, hashedPassword, email);
status = MembershipCreateStatus.Success;
//TODO: Schedule E-mail notification in case email is provided. Also set up a default user settings.
return new MembershipUser(System.Web.Security.Membership.Provider.Name, newBorn.UserName, newBorn.Id,
newBorn.Email, null, null, true, newBorn.IsLockedOut, newBorn.CreateDate.Value, newBorn.LastLoginDate.Value,
newBorn.LastActivityDate.Value, newBorn.LastPasswordChangedDate.Value, newBorn.LastLockoutDate.Value);
}
示例3: CreateUser
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
if (!SecUtility.ValidateParameter(ref password, true, true, false, 0x80))
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
if (!SecUtility.ValidateParameter(ref username, true, true, true, 0x100))
{
status = MembershipCreateStatus.InvalidUserName;
return null;
}
if (!SecUtility.ValidateParameter(ref email, this.RequiresUniqueEmail, this.RequiresUniqueEmail, false, 0x100))
{
status = MembershipCreateStatus.InvalidEmail;
return null;
}
if (GetUser(username, false) != null)
{
status = MembershipCreateStatus.DuplicateUserName;
return null;
}
if (GetUserNameByEmail(email) != null)
{
status = MembershipCreateStatus.DuplicateUserName;
return null;
}
if (password.Length < this.MinRequiredPasswordLength)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
int num = 0;
for (int i = 0; i < password.Length; i++)
{
if (!char.IsLetterOrDigit(password, i))
{
num++;
}
}
if (num < this.MinRequiredNonAlphanumericCharacters)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
if ((this.PasswordStrengthRegularExpression.Length > 0) && !Regex.IsMatch(password, this.PasswordStrengthRegularExpression))
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, password, true);
this.OnValidatingPassword(e);
if (e.Cancel)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
return CheckedCreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
}
示例4: CreateUser
public override MembershipUser CreateUser(string firstName, string lastName, string username, string password, string email,
bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
var entities = new BdJobsEntities();
if (entities.Users.Any(u => u.UserName == username))
{
status = MembershipCreateStatus.DuplicateUserName;
}
else if (entities.Users.Any(u => u.Email == email))
{
status = MembershipCreateStatus.DuplicateEmail;
}
else
{
string hPassword = GetSHA1HashData(password);
var user = new User { UserName = username, Password = hPassword, RoleId = 3, FirstName = firstName, LastName = lastName, Email = email };
entities.Users.Add(user);
entities.SaveChanges();
status = MembershipCreateStatus.Success;
}
return null;
}
示例5: TestCustomerMemembershipProvider_CreateOneUser_Fail
public void TestCustomerMemembershipProvider_CreateOneUser_Fail()
{
MembershipCreateStatus status = new MembershipCreateStatus();
Assert.IsNull(provider.CreateUser("admin", "123456", "", "abc", "123", true, 4, out status));
Assert.AreEqual(status, MembershipCreateStatus.DuplicateUserName);
Assert.AreEqual(repository.UserInformations.Count(), 1);
}
示例6: ErrorCodeToString
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
{
string statusString = createStatus.ToString();
string resourceKey = "Exceptions.ErrorMessages.UserRegister.{0}".FormatWith(statusString);
return ResourceManager.GetString(resourceKey);
}
示例7: ErrorCodeToString
private string ErrorCodeToString(MembershipCreateStatus status)
{
switch (status)
{
case MembershipCreateStatus.DuplicateUserName:
return "Username already exists. Please enter a different user name.";
case MembershipCreateStatus.DuplicateEmail:
return "A user name for that e-mail address already exists. Please enter a different e-mail address.";
case MembershipCreateStatus.InvalidPassword:
return "The password provided is invalid. Please enter a valid password value.";
case MembershipCreateStatus.InvalidEmail:
return "The e-mail address provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidUserName:
return "The user name provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.UserRejected:
return "The user creation request has been canceled. Please verify your entry and try again." +
"If the problem persists, please contact your system administrator.";
default:
return "An unknown error occurred. Please verify your entry and try again. If the problem persists, " +
"please contact your system administrator.";
}
}
示例8: CreateUser
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
if (_dataService.IsExistingUsername(username))
{
status = MembershipCreateStatus.DuplicateUserName;
return null;
}
if (_dataService.IsExistingEmail(email))
{
status = MembershipCreateStatus.DuplicateEmail;
return null;
}
TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
string salt = SimpleHash.GetSalt(32);
string activationCode = ShortGuid.NewGuid();
User user = new User()
{
email = email,
usergroupid = 3,
username = username,
password = SimpleHash.MD5(password, salt),
passworddate = DateTime.Now.Date,
usertitle = "Guest",
joindate = Convert.ToInt32(ts.TotalSeconds),
timezoneoffset = -6,
options = 45108439,
salt = salt,
showbirthday = 0,
showvbcode = 0,
membergroupids = string.Empty
};
user = _dataService.CreateForumUser(user, activationCode);
if (user != null)
{
Login login = new Login();
login.Username = username;
login.Password = SimpleHash.MD5(password, salt);
login.Email = email;
login.ForumUserId = user.userid;
login.PasswordSalt = salt;
login = _dataService.CreateLogin(login);
if (login != null)
{
NtxfcMembershipProvider provider = Membership.Provider as NtxfcMembershipProvider;
provider.SendConfirmationEmail(username, email, String.Format("{0}/Account/Activation/?u={1}&i={2}", ConfigurationManager.AppSettings["MemberUrl"], HttpContext.Current.Server.UrlEncode(username), activationCode));
status = MembershipCreateStatus.Success;
return new MembershipUser(this.Name, username, login.Id, login.Email, string.Empty, string.Empty, true, false, new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime());
}
}
status = MembershipCreateStatus.ProviderError;
return null;
}
示例9: GetErrorMessage
public string GetErrorMessage(MembershipCreateStatus status)
{
switch (status)
{
case MembershipCreateStatus.DuplicateUserName:
return "Bu kullanıcı adı kullanılmakta,Başka bir kullanıcı adı deneyin";
case MembershipCreateStatus.DuplicateEmail:
return "Bu email kullanılmakta,Başka bir email deneyin";
case MembershipCreateStatus.InvalidPassword:
return "Geçersiz şifre";
case MembershipCreateStatus.InvalidEmail:
return "Geçersiz email";
case MembershipCreateStatus.InvalidUserName:
return "Geçersiz kullanıcı adı";
//case MembershipCreateStatus.InvalidAnswer:
// return "The password retrieval answer provided is invalid. Please check the value and try again.";
//case MembershipCreateStatus.InvalidQuestion:
// return "The password retrieval question provided is invalid. Please check the value and try again.";
//case MembershipCreateStatus.ProviderError:
// return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
//case MembershipCreateStatus.UserRejected:
// return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
default:
return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
}
}
示例10: CreateUser
/// <summary>
/// 新しいメンバーシップユーザーをデータソースに追加します。
/// </summary>
/// <returns>
/// 新しく作成されたユーザーの情報が格納された <see cref="T:System.Web.Security.MembershipUser"/> オブジェクト。
/// </returns>
/// <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">ユーザーが正常に作成されたかどうかを示す <see cref="T:System.Web.Security.MembershipCreateStatus"/> 列挙値。</param>
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
status = MembershipCreateStatus.ProviderError;
// パスワードの保護
var securePassword = new SecureString();
securePassword.AppendString(password);
// 認証の作成
var membership = new DomainModels.Membership(
new MembershipEntity
{
Name = username,
Password = securePassword,
});
var result = MembershipCreateStatus.ProviderError;
membership.Created += (sender, entity) => { result = MembershipCreateStatus.Success; };
membership.Create();
status = result;
var user = default (KandaMembershipUser);
membership.Found += (sender, entity) => { user = new KandaMembershipUser(entity); };
membership.Find();
return user;
}
示例11: Authenticate
public MyTrelloUser Authenticate(string nickName, string password, out MembershipCreateStatus status)
{
var userModel = _repo.GetById(nickName);
if (userModel == null)
{
status = MembershipCreateStatus.InvalidUserName;
return null;
}
if(!userModel.IsValid)
{
status = MembershipCreateStatus.ProviderError;
return userModel;
}
IGenerator gen = new Generator();
if (!gen.GenerateHash(password).SequenceEqual(userModel.Password))
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
status = MembershipCreateStatus.Success;
return userModel;
}
示例12: ErrorCodeToString
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
{
// See http://msdn.microsoft.com/en-us/library/system.web.security.membershipcreatestatus.aspx for
// a full list of status codes and add appropriate error handling.
switch (createStatus)
{
case MembershipCreateStatus.DuplicateUserName:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusDuplicateUserName);
case MembershipCreateStatus.DuplicateEmail:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusDuplicateEmail);
case MembershipCreateStatus.ProviderError:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusProviderError);
case MembershipCreateStatus.UserRejected:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusUserRejected);
case MembershipCreateStatus.InvalidPassword:
case MembershipCreateStatus.InvalidEmail:
case MembershipCreateStatus.InvalidAnswer:
case MembershipCreateStatus.InvalidQuestion:
case MembershipCreateStatus.InvalidUserName:
// All this errors should have been handled by the UI validation so theoretically
// we should never get to this point
return "Validation Error: " + createStatus.ToString();
default:
return "Could not register the user, please verify the provided information and try again.";
}
}
示例13: ErrorMessage
public string ErrorMessage(MembershipCreateStatus status, out string field)
{
switch (status)
{
case MembershipCreateStatus.DuplicateUserName:
case MembershipCreateStatus.DuplicateEmail:
field = "userID";
return "The email is already being used";
case MembershipCreateStatus.InvalidPassword:
field = "password";
return "Invalid password";
case MembershipCreateStatus.InvalidEmail:
case MembershipCreateStatus.InvalidUserName:
field = "userID";
return "The email is invalid";
case MembershipCreateStatus.InvalidAnswer:
field = String.Empty;
return "The password retrieval answer provided is invalid";
case MembershipCreateStatus.InvalidQuestion:
field = String.Empty;
return "The password retrieval question provided is invalid";
case MembershipCreateStatus.ProviderError:
case MembershipCreateStatus.UserRejected:
default:
field = String.Empty;
return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
}
}
示例14: CreateUser
public MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status, string name, string surname, string telephone, string country)
{
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;
}
var user = GetUser(username, true);
if (user == null)
{
var userObj = new User { Username = username, Password = Assets.Encrypt(password), Email = email, Name = name, Surname = surname, Telephone = telephone };
new UserDa(databasecontext).Add(userObj);
status = MembershipCreateStatus.Success;
return GetUser(username, true);
}
status = MembershipCreateStatus.DuplicateUserName;
return null;
}
示例15: CreateUser
/// <summary>
/// Adds a new user to the SQL Server membership database.
/// </summary>
/// <param name="username">The user name for the new user.</param>
/// <param name="password">The password for the new user.</param>
/// <param name="email">The e-mail address for the new user.</param>
/// <param name="passwordQuestion">The password question for the new user.</param>
/// <param name="passwordAnswer">The password answer for the new user.</param>
/// <param name="isApproved">Whether or not the new user is approved to be validated.</param>
/// <param name="providerUserKey">A <see cref="T:System.Guid"></see> that uniquely identifies the membership user in the SQL Server database.</param>
/// <param name="status">One of the <see cref="T:System.Web.Security.MembershipCreateStatus"></see> values, indicating whether the user was created successfully.</param>
/// <returns>
/// A <see cref="T:System.Web.Security.MembershipUser"></see> object for the newly created user. If no user was created, this method returns null.
/// </returns>
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
MembershipUser oldUser = base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
if (status == MembershipCreateStatus.Success)
{
ProfileBase profile = ProfileBase.Create(oldUser.UserName);
string firstName = (string)profile.GetPropertyValue("FirstName");
string lastName = (string)profile.GetPropertyValue("LastName");
string displayName = (string)profile.GetPropertyValue("DisplayName");
CustomMembershipUser newUser = new CustomMembershipUser(oldUser.ProviderName,
oldUser.UserName,
oldUser.ProviderUserKey,
oldUser.Email,
oldUser.PasswordQuestion,
oldUser.Comment,
oldUser.IsApproved,
oldUser.IsLockedOut,
oldUser.CreationDate,
oldUser.LastLoginDate,
oldUser.LastActivityDate,
oldUser.LastPasswordChangedDate,
oldUser.LastLockoutDate,
displayName,
firstName,
lastName);
return newUser;
}
return null;
}