本文整理汇总了C#中IUserAuth类的典型用法代码示例。如果您正苦于以下问题:C# IUserAuth类的具体用法?C# IUserAuth怎么用?C# IUserAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IUserAuth类属于命名空间,在下文中一共展示了IUserAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AuditInterceptor
public AuditInterceptor(IUserAuth userAuth, IRepository<Audit> auditRepository)
{
Check.Require(userAuth != null, "User Authorization Context is Required");
UserAuth = userAuth;
AuditRepository = auditRepository;
}
示例2: GetPermissions
public static ICollection<string> GetPermissions(this IAuthRepository UserAuthRepo, IUserAuth userAuth)
{
var managesRoles = UserAuthRepo as IManageRoles;
return managesRoles != null
? managesRoles.GetPermissions(userAuth.Id.ToString())
: userAuth.Permissions;
}
示例3: CreateUserAuth
public IUserAuth CreateUserAuth(IUserAuth 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 (var session = _documentStore.OpenSession())
{
session.Store(newUser);
session.SaveChanges();
}
return newUser;
}
示例4: AssignRoles
/// <summary>
/// Creates the required missing tables or DB schema
/// </summary>
public static void AssignRoles(this IAuthRepository UserAuthRepo, IUserAuth userAuth,
ICollection<string> roles = null, ICollection<string> permissions = null)
{
var managesRoles = UserAuthRepo as IManageRoles;
if (managesRoles != null)
{
managesRoles.AssignRoles(userAuth.Id.ToString(), roles, permissions);
}
else
{
if (!roles.IsEmpty())
{
foreach (var missingRole in roles.Where(x => !userAuth.Roles.Contains(x)))
{
userAuth.Roles.Add(missingRole);
}
}
if (!permissions.IsEmpty())
{
foreach (var missingPermission in permissions.Where(x => !userAuth.Permissions.Contains(x)))
{
userAuth.Permissions.Add(missingPermission);
}
}
UserAuthRepo.SaveUserAuth(userAuth);
}
}
示例5: CreateUser
private static void CreateUser(IUserAuthRepository userRepo, IUserAuth user, string password)
{
string hash;
string salt;
new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
user.Salt = salt;
user.PasswordHash = hash;
userRepo.CreateUserAuth(user, password);
}
示例6: PopulateSession
public static void PopulateSession(this IAuthSession session, IUserAuth userAuth, List<IAuthTokens> authTokens)
{
if (userAuth == null)
return;
var originalId = session.Id;
session.PopulateWith(userAuth);
session.Id = originalId;
session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
session.ProviderOAuthAccess = authTokens;
}
示例7: GetRoles
public static ICollection<string> GetRoles(this IAuthRepository UserAuthRepo, IUserAuth userAuth)
{
var managesRoles = UserAuthRepo as IManageRoles;
if (managesRoles != null)
{
return managesRoles.GetRoles(userAuth.Id.ToString());
}
else
{
return userAuth.Roles;
}
}
示例8: ValidateNewUserWithoutPassword
private void ValidateNewUserWithoutPassword(IUserAuth 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");
}
}
示例9: AssertNoExistingUser
private void AssertNoExistingUser(IUserAuth newUser, IUserAuth 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));
}
}
示例10: Setup
public void Setup()
{
_userBLL = MockRepository.GenerateStub<IUserBLL>();
_userAuth = MockRepository.GenerateStub<IUserAuth>();
_delegateBLL = new DelegateBLL(_userAuth, _userBLL);
_roleProvider = MockRepository.GenerateStub<RoleProvider>();
_userAuth.RoleProvider = _roleProvider;
_currentUser.UserName = "_currentUser";
_userBLL.Expect(a => a.GetUser()).Return(_currentUser).Repeat.Any();
for (int i = 0; i < 3; i++)
{
_users.Add(CreateValidEntities.User(i+3));
//_users[i].Delegate = _users[0];
}
}
示例11: TryAuthenticate
public bool TryAuthenticate(string userName, string password, out IUserAuth userAuth)
{
userAuth = GetUserAuthByUserName(userName);
if (userAuth == null)
return false;
if (HostContext.Resolve<IHashProvider>().VerifyHashString(password, userAuth.PasswordHash, userAuth.Salt))
{
this.RecordSuccessfulLogin(userAuth);
return true;
}
this.RecordInvalidLoginAttempt(userAuth);
userAuth = null;
return false;
}
示例12: CreateUserAuth
public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
{
ValidateNewUser(newUser, password);
AssertNoExistingUser(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;
Session.Save(new UserAuthNHibernate(newUser));
return newUser;
}
示例13: UnAssignRoles
public static void UnAssignRoles(this IAuthRepository UserAuthRepo, IUserAuth userAuth,
ICollection<string> roles = null, ICollection<string> permissions = null)
{
var managesRoles = UserAuthRepo as IManageRoles;
if (managesRoles != null)
{
managesRoles.UnAssignRoles(userAuth.Id.ToString(), roles, permissions);
}
else
{
roles.Each(x => userAuth.Roles.Remove(x));
permissions.Each(x => userAuth.Permissions.Remove(x));
if (roles != null || permissions != null)
{
UserAuthRepo.SaveUserAuth(userAuth);
}
}
}
示例14: CreateUserAuth
public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
{
UserEntry user = newUser as UserEntry;
ValidateNewUser(user, password);
AssertNoExistingUser(user);
var saltedHash = HostContext.Resolve<IHashProvider>();
string salt;
string hash;
saltedHash.GetHashAndSaltString(password, out hash, out salt);
user.PartitionKey = Guid.NewGuid().ToString();
user.RowKey = newUser.UserName;
user.RowKey = TableEntityHelper.RemoveDiacritics(user.RowKey);
user.RowKey = TableEntityHelper.ToAzureKeyString(user.RowKey);
//user.Id = 0;
user.PasswordHash = hash;
user.Salt = salt;
var digestHelper = new DigestAuthFunctions();
user.DigestHa1Hash = digestHelper.CreateHa1(user.UserName, DigestAuthProvider.Realm, password);
user.CreatedDate = DateTime.UtcNow;
user.ModifiedDate = user.CreatedDate;
//var userId = user.Id.ToString(CultureInfo.InvariantCulture);
//if (!newUser.UserName.IsNullOrEmpty())
//{
// redis.SetEntryInHash(IndexUserNameToUserId, newUser.UserName, userId);
//}
//if (!newUser.Email.IsNullOrEmpty())
//{
// redis.SetEntryInHash(IndexEmailToUserId, newUser.Email, userId);
//}
SaveUserAuth(user);
return user;
}
示例15: CreateUserAuth
public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
{
newUser.ValidateNewUser(password);
AssertNoExistingUser(mongoDatabase, newUser);
var saltedHash = HostContext.Resolve<IHashProvider>();
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;
SaveUser(newUser);
return newUser;
}