本文整理汇总了C#中ServiceStack.ServiceInterface.Auth.UserAuth类的典型用法代码示例。如果您正苦于以下问题:C# UserAuth类的具体用法?C# UserAuth怎么用?C# UserAuth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserAuth类属于ServiceStack.ServiceInterface.Auth命名空间,在下文中一共展示了UserAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateUserAuth
public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
AssertNoExistingUser(newUser, existingUser);
var hash = existingUser.PasswordHash;
var salt = existingUser.Salt;
if (password != null)
{
var saltedHash = new SaltedHash();
saltedHash.GetHashAndSaltString(password, out hash, out salt);
}
// If either one changes the digest hash has to be recalculated
var digestHash = existingUser.DigestHA1Hash;
if (password != null || existingUser.UserName != newUser.UserName)
{
var digestHelper = new DigestAuthFunctions();
digestHash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password);
}
newUser.Id = existingUser.Id;
newUser.PasswordHash = hash;
newUser.Salt = salt;
newUser.DigestHA1Hash = digestHash;
newUser.CreatedDate = existingUser.CreatedDate;
newUser.ModifiedDate = DateTime.UtcNow;
using (var session = _documentStore.OpenSession())
{
session.Store(newUser);
session.SaveChanges();
}
return newUser;
}
示例2: FindByPasswordCredential
private UserAuth FindByPasswordCredential(string login, string password)
{
UserAuth userAuth = null;
using (new UnitOfWork())
{
var manager = this.container.Resolve<IUserManager>();
var user = manager.FindByPasswordCredential(login, password);
if (user != null)
{
userAuth = new UserAuth
{
RefIdStr = user.Id.ToString(CultureInfo.InvariantCulture),
UserName = login,
Email = user.Email,
DisplayName = user.Name,
Roles = new List<string>(),
Permissions = new List<string>(),
};
if (user.Role != null)
{
userAuth.Roles.Add(user.Role.Name);
userAuth.Permissions.AddRange(from p in user.Role.Permissions select p.Name.ToString());
}
}
}
return userAuth;
}
示例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");
}
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;
});
}
示例4: CreateUserAuth
public UserAuth CreateUserAuth(UserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
AssertNoExistingUser(newUser);
var saltedHash = new SaltedHash();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
var digestHelper = new DigestAuthFunctions();
newUser.DigestHA1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password);
newUser.PasswordHash = hash;
newUser.Salt = salt;
newUser.CreatedDate = DateTime.UtcNow;
newUser.ModifiedDate = newUser.CreatedDate;
using (_session)
{
_session.Store(newUser);
_session.SaveChanges();
}
return newUser;
}
示例5: ToPerson
private static Person ToPerson(UserAuth auth)
{
if (auth == null)
{
return null;
}
var name = auth.FullName;
if (string.IsNullOrEmpty(name))
{
if (!string.IsNullOrEmpty(auth.FirstName) || !string.IsNullOrEmpty(auth.LastName))
{
name = auth.FirstName + " " + auth.LastName;
}
else
{
name = auth.UserName;
}
}
return new Person
{
Id = auth.Id,
Name = name,
CustomerId = auth.RefId,
IsEmployee = auth.Roles.Contains(Global.Constants.EmployeeRoleName)
};
}
示例6: CreateUserAuth
public virtual UserAuth CreateUserAuth(UserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
using (var redis = factory.GetClient())
{
AssertNoExistingUser(redis, newUser);
var saltedHash = new SaltedHash();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
newUser.Id = redis.As<UserAuth>().GetNextSequence();
newUser.PasswordHash = hash;
newUser.Salt = salt;
var digestHelper = new DigestAuthFunctions();
newUser.DigestHA1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password);
newUser.CreatedDate = DateTime.UtcNow;
newUser.ModifiedDate = newUser.CreatedDate;
var userId = newUser.Id.ToString(CultureInfo.InvariantCulture);
if (!newUser.UserName.IsNullOrEmpty())
redis.SetEntryInHash(IndexUserNameToUserId, newUser.UserName, userId);
if (!newUser.Email.IsNullOrEmpty())
redis.SetEntryInHash(IndexEmailToUserId, newUser.Email, userId);
redis.Store(newUser);
return newUser;
}
}
开发者ID:grammarware,项目名称:fodder,代码行数:32,代码来源:src_ServiceStack_ServiceInterface_Auth_RedisAuthRepository.cs
示例7: LoadUserAuth
private void LoadUserAuth(IAuthSession session, UserAuth userAuth)
{
if (userAuth == null) return;
session.PopulateWith(userAuth);
session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
session.ProviderOAuthAccess = GetUserOAuthProviders(session.UserAuthId)
.ConvertAll(x => (IOAuthTokens)x);
}
示例8: TryAuthenticate
public bool TryAuthenticate(
Dictionary<string, string> digestHeaders,
string privateKey,
int nonceTimeOut,
string sequence,
out UserAuth userAuth)
{
throw new NotSupportedException();
}
示例9: 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");
}
}
示例10: AssertNoExistingUser
private void AssertNoExistingUser(UserAuth newUser, UserAuth exceptForExistingUser = null)
{
if (newUser.UserName != null)
{
var existingUser = GetUserAuthByUserName(newUser.UserName);
if (existingUser != null
&& (exceptForExistingUser == null || existingUser.Id != exceptForExistingUser.Id))
throw new ArgumentException("User {0} already exists".Fmt(newUser.UserName));
}
if (newUser.Email != null)
{
var existingUser = GetUserAuthByUserName(newUser.Email);
if (existingUser != null
&& (exceptForExistingUser == null || existingUser.Id != exceptForExistingUser.Id))
throw new ArgumentException("Email {0} already exists".Fmt(newUser.Email));
}
}
示例11: Register
public ActionResult Register(RegisterModel model)
{
string hash;
string salt;
new SaltedHash().GetHashAndSaltString(model.Password, out hash, out salt);
var user = new UserAuth
{
DisplayName = model.UserName,
Email = model.Email,
UserName = model.UserName,
PasswordHash = hash,
Salt = salt
};
var response = UserAuthRepo.CreateUserAuth(user, model.Password);
var authResponse = AuthService.Authenticate(new Auth {UserName = model.UserName, Password = model.Password, RememberMe = true});
return RedirectToAction("Index", "Home");
}
示例12: CreateOrMergeAuthSession
public string CreateOrMergeAuthSession(IOAuthSession oAuthSession, IOAuthTokens tokens)
{
using (var redis = factory.GetClient())
{
UserOAuthProvider oauthProvider = null;
var oAuthProviderId = GetAuthProviderByUserId(redis, tokens.Provider, tokens.UserId);
if (!oAuthProviderId.IsNullOrEmpty())
oauthProvider = redis.As<UserOAuthProvider>().GetById(oAuthProviderId);
var userAuth = GetUserAuth(redis, oAuthSession, tokens);
if (userAuth == null)
{
userAuth = new UserAuth {
Id = redis.As<UserAuth>().GetNextSequence(),
};
}
if (oauthProvider == null)
{
oauthProvider = new UserOAuthProvider {
Id = redis.As<UserOAuthProvider>().GetNextSequence(),
UserAuthId = userAuth.Id,
Provider = tokens.Provider,
UserId = tokens.UserId,
};
var idx = IndexProviderUserIdHash(tokens.Provider);
redis.SetEntryInHash(idx, tokens.UserId, oauthProvider.Id.ToString());
}
oauthProvider.PopulateMissing(tokens);
userAuth.PopulateMissing(oauthProvider);
redis.Store(userAuth);
redis.Store(oauthProvider);
redis.AddItemToSet(IndexUserAuthAndProviderIdsSet(userAuth.Id), oauthProvider.Id.ToString());
return userAuth.Id.ToString();
}
}
示例13: CreateUserAuth
public UserAuth CreateUserAuth(UserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
AssertNoExistingUser(mongoDatabase, newUser);
var saltedHash = new SaltedHash();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
var digestHelper = new DigestAuthFunctions();
newUser.DigestHA1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password);
newUser.PasswordHash = hash;
newUser.Salt = salt;
newUser.CreatedDate = DateTime.UtcNow;
newUser.ModifiedDate = newUser.CreatedDate;
var collection = mongoDatabase.GetCollection<UserAuth>("UserAuth");
collection.Insert(newUser);
// todo - update id here
return newUser;
}
示例14: CreateUserAuth
public UserAuth CreateUserAuth(UserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
return dbFactory.Run(db => {
AssertNoExistingUser(db, newUser);
string salt;
string hash;
passwordHasher.GetHashAndSaltString(password, out hash, out salt);
var digestHelper = new DigestAuthFunctions();
newUser.DigestHa1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password);
newUser.PasswordHash = hash;
newUser.Salt = salt;
newUser.CreatedDate = DateTime.UtcNow;
newUser.ModifiedDate = newUser.CreatedDate;
db.Insert(newUser);
newUser = db.GetById<UserAuth>(db.GetLastInsertId());
return newUser;
});
}
示例15: CreateUserAuth
public UserAuth CreateUserAuth(UserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
return dbFactory.Exec(dbCmd => {
AssertNoExistingUser(dbCmd, newUser);
var saltedHash = new SaltedHash();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
newUser.PasswordHash = hash;
newUser.Salt = salt;
newUser.CreatedDate = DateTime.UtcNow;
newUser.ModifiedDate = newUser.CreatedDate;
dbCmd.Insert(newUser);
newUser = dbCmd.GetById<UserAuth>(dbCmd.GetLastInsertId());
return newUser;
});
}