Beispiel #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);
             }
         }
     }
 }
Beispiel #2
0
 public SaltedHash GetAccountPassword(AccountId accountId)
 {
     using (var db = new THCard()) {
         Account dbAccount = db.Accounts.Find(accountId);
         AssertFound(dbAccount);
         return(MapToHashedPassword(dbAccount));
     }
 }
Beispiel #3
0
 public SaltedHash GetAccountPassword(AccountId accountId)
 {
     using (var db = new THCard()) {
         Account dbAccount = db.Accounts.Find(accountId);
         AssertFound(dbAccount);
         return MapToHashedPassword(dbAccount);
     }
 }
Beispiel #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;
     }
 }
Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
Beispiel #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));
     }
 }
Beispiel #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;
         }
     }
 }
Beispiel #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));
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #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();
         }
     }
 }
Beispiel #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();
         }
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #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;
             }
         }
     }
 }
Beispiel #19
0
 private static FailedLoginAttempt FindFailedLoginAttempt(THCard db, Guid accountId)
 {
     return(db.FailedLoginAttempts.SingleOrDefault(fla => fla.AccountId == accountId));
 }
Beispiel #20
0
 private static FailedLoginAttempt FindFailedLoginAttempt(THCard db, Guid accountId)
 {
     return db.FailedLoginAttempts.SingleOrDefault(fla => fla.AccountId == accountId);
 }
Beispiel #21
0
 private static Account FindAccountByUsername(Username username, THCard db)
 {
     string usernameAsString = username.ToString();
     return db.Accounts.FirstOrDefault(a => a.Username == usernameAsString);
 }
Beispiel #22
0
        private static Account FindAccountById(THCard db, Guid accountId)
        {
            Account dbAccount = db.Accounts.SingleOrDefault(a => a.AccountId == accountId);

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

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