本文整理汇总了C#中ServiceStack.ServiceInterface.Auth.UserAuth.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# UserAuth.ThrowIfNull方法的具体用法?C# UserAuth.ThrowIfNull怎么用?C# UserAuth.ThrowIfNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.ServiceInterface.Auth.UserAuth
的用法示例。
在下文中一共展示了UserAuth.ThrowIfNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateUserAuth
public UserAuth CreateUserAuth(UserAuth newUser, string password)
{
newUser.ThrowIfNull("newUser");
password.ThrowIfNullOrEmpty("password");
if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
throw new ArgumentNullException("UserName or Email is required");
if (!newUser.UserName.IsNullOrEmpty())
{
if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
throw new ArgumentException("UserName contains invalid characters", "UserName");
}
return dbFactory.Exec(dbCmd => {
var effectiveUserName = newUser.UserName ?? newUser.Email;
var existingUser = GetUserAuthByUserName(dbCmd, effectiveUserName);
if (existingUser != null)
throw new ArgumentException("User {0} already exists".Fmt(effectiveUserName));
var saltedHash = new SaltedHash();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
newUser.PasswordHash = hash;
newUser.Salt = salt;
dbCmd.Insert(newUser);
newUser = dbCmd.GetById<UserAuth>(dbCmd.GetLastInsertId());
return newUser;
});
}
示例2: ValidateNewUserWithoutPassword
private void ValidateNewUserWithoutPassword(UserAuth newUser)
{
newUser.ThrowIfNull("newUser");
if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
throw new ArgumentNullException("UserName or Email is required");
if (!newUser.UserName.IsNullOrEmpty())
{
if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
throw new ArgumentException("UserName contains invalid characters", "UserName");
}
}
示例3: CreateUserAuth
public UserAuth CreateUserAuth(UserAuth newUser, string password)
{
newUser.ThrowIfNull("newUser");
password.ThrowIfNullOrEmpty("password");
if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
throw new ArgumentNullException("UserName or Email is required");
if (!newUser.UserName.IsNullOrEmpty())
{
if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
throw new ArgumentException("UserName contains invalid characters", "UserName");
}
using (var redis = factory.GetClient())
{
var effectiveUserName = newUser.UserName ?? newUser.Email;
var userAuth = GetUserAuthByUserName(redis, newUser.UserName);
if (userAuth != null)
throw new ArgumentException("User {0} already exists".Fmt(effectiveUserName));
var saltedHash = new SaltedHash();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
newUser.PasswordHash = hash;
newUser.Salt = salt;
newUser.Id = redis.As<UserAuth>().GetNextSequence();
if (!newUser.UserName.IsNullOrEmpty())
redis.SetEntryInHash(IndexUserNameToUserId, newUser.UserName, newUser.Id.ToString());
if (!newUser.Email.IsNullOrEmpty())
redis.SetEntryInHash(IndexEmailToUserId, newUser.Email, newUser.Id.ToString());
redis.Store(newUser);
return newUser;
}
}
示例4: ValidateNewUser
private void ValidateNewUser(UserAuth newUser, string password)
{
newUser.ThrowIfNull("newUser");
password.ThrowIfNullOrEmpty("password");
if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
throw new ArgumentNullException("UserName or Email is required");
//Want to have username and email be the same
//if (!newUser.UserName.IsNullOrEmpty())
//{
// if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
// throw new ArgumentException("UserName contains invalid characters", "UserName");
// }
}