Exemplo n.º 1
0
 public int IncrementFailedLoginAttemptCount(AccountId accountId)
 {
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope(TransactionScopeOption.Required,
                                                       new TransactionOptions {
             IsolationLevel = IsolationLevel.RepeatableRead
         })) {
             FailedLoginAttempt dbFailedLoginAttempt = FindFailedLoginAttempt(db, accountId.ToGuid());
             if (dbFailedLoginAttempt == null)
             {
                 db.FailedLoginAttempts.Add(new FailedLoginAttempt {
                     AccountId = accountId.ToGuid(), FailedLoginAttemptCount = 0
                 });
                 db.SaveChanges();
                 transaction.Complete();
                 return(1);
             }
             else
             {
                 ++dbFailedLoginAttempt.FailedLoginAttemptCount;
                 db.SaveChanges();
                 transaction.Complete();
                 return(dbFailedLoginAttempt.FailedLoginAttemptCount);
             }
         }
     }
 }
Exemplo n.º 2
0
 public SaltedHash GetAccountPassword(AccountId accountId)
 {
     using (var db = new THCard()) {
         Account dbAccount = db.Accounts.Find(accountId);
         AssertFound(dbAccount);
         return(MapToHashedPassword(dbAccount));
     }
 }
Exemplo n.º 3
0
 public SaltedHash GetAccountPassword(AccountId accountId)
 {
     using (var db = new THCard()) {
         Account dbAccount = db.Accounts.Find(accountId);
         AssertFound(dbAccount);
         return MapToHashedPassword(dbAccount);
     }
 }
Exemplo n.º 4
0
 public AccountManagement.User GetUser(UserId userId)
 {
     using (var db = new THCard()) {
         Guid userIdAsGuid = userId.ToGuid();
         User dbUser = db.Users.SingleOrDefault(u => u.UserId == userIdAsGuid);
         AccountManagement.User user = MapToUser(dbUser);
         return user;
     }
 }
Exemplo n.º 5
0
 public AccountManagement.User GetUser(UserId userId)
 {
     using (var db = new THCard()) {
         Guid userIdAsGuid           = userId.ToGuid();
         User dbUser                 = db.Users.SingleOrDefault(u => u.UserId == userIdAsGuid);
         AccountManagement.User user = MapToUser(dbUser);
         return(user);
     }
 }
Exemplo n.º 6
0
 public AccountManagement.Account FindAccount(Username username)
 {
     using (var db = new THCard()) {
         Account dbAccount = FindAccountByUsername(username, db);
         if (dbAccount == null) {
             return null;
         }
         return MapAccount(dbAccount);
     }
 }
Exemplo n.º 7
0
 public AccountManagement.User GetUser(AccountId accountId)
 {
     Contract.Requires(accountId != null && !accountId.IsNew);
     using (var db = new THCard()) {
         Account dbAccount = db.Accounts.Find(accountId.ToGuid());
         if (dbAccount == null) {
             throw new InvalidOperationException("Account not found.");
         }
         return MapToUser(dbAccount.User);
     }
 }
Exemplo n.º 8
0
 public AccountManagement.Account FindAccount(Username username)
 {
     using (var db = new THCard()) {
         Account dbAccount = FindAccountByUsername(username, db);
         if (dbAccount == null)
         {
             return(null);
         }
         return(MapAccount(dbAccount));
     }
 }
Exemplo n.º 9
0
 public AccountManagement.Account GetAccount(AccountId accountId)
 {
     using (var db = new THCard()) {
         Account dbAccount = FindAccountById(db, accountId.ToGuid());
         if (dbAccount != null) {
             return MapAccount(dbAccount);
         }
         else {
             return null;
         }
     }
 }
Exemplo n.º 10
0
 public AccountManagement.User GetUser(AccountId accountId)
 {
     Contract.Requires(accountId != null && !accountId.IsNew);
     using (var db = new THCard()) {
         Account dbAccount = db.Accounts.Find(accountId.ToGuid());
         if (dbAccount == null)
         {
             throw new InvalidOperationException("Account not found.");
         }
         return(MapToUser(dbAccount.User));
     }
 }
Exemplo n.º 11
0
 public AccountManagement.Account GetAccount(AccountId accountId)
 {
     using (var db = new THCard()) {
         Account dbAccount = FindAccountById(db, accountId.ToGuid());
         if (dbAccount != null)
         {
             return(MapAccount(dbAccount));
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 12
0
 public void SaveUser(AccountManagement.User user)
 {
     Contract.Requires(user != null && !user.Id.IsNew);
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope()) {
             User dbUser = db.Users.Find(user.Id.ToGuid());
             dbUser.FirstName  = user.FullName.FirstName.ToString();
             dbUser.MiddleName = user.FullName.MiddleName.ToString();
             dbUser.LastName   = user.FullName.FamilyName.ToString();
             db.SaveChanges();
             transaction.Complete();
         }
     }
 }
Exemplo n.º 13
0
 public void SaveUser(AccountManagement.User user)
 {
     Contract.Requires(user != null && !user.Id.IsNew);
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope()) {
             User dbUser = db.Users.Find(user.Id.ToGuid());
             dbUser.FirstName = user.FullName.FirstName.ToString();
             dbUser.MiddleName = user.FullName.MiddleName.ToString();
             dbUser.LastName = user.FullName.FamilyName.ToString();
             db.SaveChanges();
             transaction.Complete();
         }
     }
 }
Exemplo n.º 14
0
 public void CreateUser(AccountManagement.User user)
 {
     Contract.Requires(user != null && user.Id.IsNew);
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope()) {
             var dbUser = new User();
             dbUser.FirstName = user.FullName.FirstName.ToString();
             dbUser.MiddleName = user.FullName.MiddleName.ToString();
             dbUser.LastName = user.FullName.FamilyName.ToString();
             db.Users.Add(dbUser);
             db.SaveChanges();
             transaction.Complete();
             user.Id = new UserId(dbUser.UserId);
         }
     }
 }
Exemplo n.º 15
0
 public void CreateUser(AccountManagement.User user)
 {
     Contract.Requires(user != null && user.Id.IsNew);
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope()) {
             var dbUser = new User();
             dbUser.FirstName  = user.FullName.FirstName.ToString();
             dbUser.MiddleName = user.FullName.MiddleName.ToString();
             dbUser.LastName   = user.FullName.FamilyName.ToString();
             db.Users.Add(dbUser);
             db.SaveChanges();
             transaction.Complete();
             user.Id = new UserId(dbUser.UserId);
         }
     }
 }
Exemplo n.º 16
0
 public void CreateAccount(AccountManagement.Account account, SaltedHash passwordHash, UserId userId)
 {
     Contract.Assert(account.AccountId.IsNew);
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope()) {
             var dbAccount = new Account {
                 Username        = account.Username.ToString(),
                 UserId          = userId.ToGuid(),
                 AccountPassword = new AccountPassword {
                     PasswordHash = passwordHash.Hash,
                     Salt         = passwordHash.Salt
                 }
             };
             db.Accounts.Add(dbAccount);
             db.SaveChanges();
             transaction.Complete();
             account.AccountId = new AccountId(dbAccount.AccountId);
         }
     }
 }
Exemplo n.º 17
0
 public void CreateAccount(AccountManagement.Account account, SaltedHash passwordHash, UserId userId)
 {
     Contract.Assert(account.AccountId.IsNew);
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope()) {
             var dbAccount = new Account {
                 Username = account.Username.ToString(),
                 UserId = userId.ToGuid(),
                 AccountPassword = new AccountPassword {
                     PasswordHash = passwordHash.Hash,
                     Salt = passwordHash.Salt
                 }
             };
             db.Accounts.Add(dbAccount);
             db.SaveChanges();
             transaction.Complete();
             account.AccountId = new AccountId(dbAccount.AccountId);
         }
     }
 }
Exemplo n.º 18
0
 public int IncrementFailedLoginAttemptCount(AccountId accountId)
 {
     using (var db = new THCard()) {
         using (var transaction = new TransactionScope(TransactionScopeOption.Required,
                                                       new TransactionOptions {
                                                           IsolationLevel = IsolationLevel.RepeatableRead
                                                       })) {
             FailedLoginAttempt dbFailedLoginAttempt = FindFailedLoginAttempt(db, accountId.ToGuid());
             if (dbFailedLoginAttempt == null) {
                 db.FailedLoginAttempts.Add(new FailedLoginAttempt {AccountId = accountId.ToGuid(), FailedLoginAttemptCount = 0});
                 db.SaveChanges();
                 transaction.Complete();
                 return 1;
             }
             else {
                 ++dbFailedLoginAttempt.FailedLoginAttemptCount;
                 db.SaveChanges();
                 transaction.Complete();
                 return dbFailedLoginAttempt.FailedLoginAttemptCount;
             }
         }
     }
 }
Exemplo n.º 19
0
 private static FailedLoginAttempt FindFailedLoginAttempt(THCard db, Guid accountId)
 {
     return(db.FailedLoginAttempts.SingleOrDefault(fla => fla.AccountId == accountId));
 }
Exemplo n.º 20
0
 private static FailedLoginAttempt FindFailedLoginAttempt(THCard db, Guid accountId)
 {
     return db.FailedLoginAttempts.SingleOrDefault(fla => fla.AccountId == accountId);
 }
Exemplo n.º 21
0
 private static Account FindAccountByUsername(Username username, THCard db)
 {
     string usernameAsString = username.ToString();
     return db.Accounts.FirstOrDefault(a => a.Username == usernameAsString);
 }
Exemplo n.º 22
0
        private static Account FindAccountById(THCard db, Guid accountId)
        {
            Account dbAccount = db.Accounts.SingleOrDefault(a => a.AccountId == accountId);

            return(dbAccount);
        }
Exemplo n.º 23
0
 private static Account FindAccountById(THCard db, Guid accountId)
 {
     Account dbAccount = db.Accounts.SingleOrDefault(a => a.AccountId == accountId);
     return dbAccount;
 }
Exemplo n.º 24
0
        private static Account FindAccountByUsername(Username username, THCard db)
        {
            string usernameAsString = username.ToString();

            return(db.Accounts.FirstOrDefault(a => a.Username == usernameAsString));
        }