本文整理汇总了C#中NuGetGallery.User.ConfirmEmailAddress方法的典型用法代码示例。如果您正苦于以下问题:C# User.ConfirmEmailAddress方法的具体用法?C# User.ConfirmEmailAddress怎么用?C# User.ConfirmEmailAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGetGallery.User
的用法示例。
在下文中一共展示了User.ConfirmEmailAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public virtual User Create(
string username,
string password,
string emailAddress)
{
// TODO: validate input
// TODO: consider encrypting email address with a public key, and having the background process that send messages have the private key to decrypt
var existingUser = FindByUsername(username);
if (existingUser != null)
{
throw new EntityException(Strings.UsernameNotAvailable, username);
}
var existingUsers = FindAllByEmailAddress(emailAddress);
if (existingUsers.AnySafe())
{
throw new EntityException(Strings.EmailAddressBeingUsed, emailAddress);
}
var hashedPassword = Crypto.GenerateSaltedHash(password, Constants.PBKDF2HashAlgorithmId);
var apiKey = Guid.NewGuid();
var newUser = new User(username)
{
ApiKey = apiKey,
EmailAllowed = true,
UnconfirmedEmailAddress = emailAddress,
EmailConfirmationToken = Crypto.GenerateToken(),
HashedPassword = hashedPassword,
PasswordHashAlgorithm = Constants.PBKDF2HashAlgorithmId,
CreatedUtc = DateTime.UtcNow
};
// Add a credential for the password and the API Key
newUser.Credentials.Add(CredentialBuilder.CreateV1ApiKey(apiKey));
newUser.Credentials.Add(new Credential(CredentialTypes.Password.Pbkdf2, newUser.HashedPassword));
if (!Config.ConfirmEmailAddresses)
{
newUser.ConfirmEmailAddress();
}
UserRepository.InsertOnCommit(newUser);
UserRepository.CommitChanges();
return newUser;
}
示例2: Create
public virtual User Create(
string username,
string password,
string emailAddress)
{
// TODO: validate input
// TODO: consider encrypting email address with a public key, and having the background process that send messages have the private key to decrypt
var existingUser = FindByUsername(username);
if (existingUser != null)
{
throw new EntityException(Strings.UsernameNotAvailable, username);
}
existingUser = FindByEmailAddress(emailAddress);
if (existingUser != null)
{
throw new EntityException(Strings.EmailAddressBeingUsed, emailAddress);
}
var hashedPassword = _cryptoService.GenerateSaltedHash(password, Constants.PBKDF2HashAlgorithmId);
var newUser = new User(
username,
hashedPassword)
{
ApiKey = Guid.NewGuid(),
EmailAllowed = true,
UnconfirmedEmailAddress = emailAddress,
EmailConfirmationToken = _cryptoService.GenerateToken(),
PasswordHashAlgorithm = Constants.PBKDF2HashAlgorithmId,
};
if (!_config.ConfirmEmailAddresses)
{
newUser.ConfirmEmailAddress();
}
_userRepository.InsertOnCommit(newUser);
_userRepository.CommitChanges();
return newUser;
}
示例3: ConfirmEmailAddress
public bool ConfirmEmailAddress(User user, string token)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
if (String.IsNullOrEmpty(token))
{
throw new ArgumentNullException("token");
}
if (user.EmailConfirmationToken != token)
{
return false;
}
user.ConfirmEmailAddress();
_userRepo.CommitChanges();
return true;
}
示例4: ConfirmEmailAddress
public async Task<bool> ConfirmEmailAddress(User user, string token)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
if (String.IsNullOrEmpty(token))
{
throw new ArgumentNullException("token");
}
if (user.EmailConfirmationToken != token)
{
return false;
}
var conflictingUsers = FindAllByEmailAddress(user.UnconfirmedEmailAddress);
if (conflictingUsers.AnySafe(u => u.Key != user.Key))
{
throw new EntityException(Strings.EmailAddressBeingUsed, user.UnconfirmedEmailAddress);
}
await Auditing.SaveAuditRecord(new UserAuditRecord(user, UserAuditAction.ConfirmEmail, user.UnconfirmedEmailAddress));
user.ConfirmEmailAddress();
UserRepository.CommitChanges();
return true;
}