コード例 #1
0
 public override bool HasLocalAccount(int userId)
 {
     using (var session = DocumentStore.OpenSession())
     {
         return(BirdBrainHelper.GetUserById(userId, session) != null);
     }
 }
コード例 #2
0
 public override int GetUserIdFromPasswordResetToken(string token)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByPasswordResetToken(token, session);
         return(user != null ? user.Id : -1);
     }
 }
コード例 #3
0
 public override bool ConfirmAccount(string accountConfirmationToken)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByConfirmationToken(accountConfirmationToken, session);
         return(ConfirmAccount(accountConfirmationToken, user, session));
     }
 }
コード例 #4
0
 public override int GetPasswordFailuresSinceLastSuccess(string userName)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(userName, session);
         return(user != null ? user.PasswordFailuresSinceLastSuccess : 0);
     }
 }
コード例 #5
0
 public override DateTime GetLastPasswordFailureDate(string userName)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(userName, session);
         return(user != null ? user.LastPasswordFailures : DateTime.MinValue);
     }
 }
コード例 #6
0
 public override bool IsUserInRole(string username, string roleName)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(username, session);
         return(user.Roles.Contains(roleName));
     }
 }
コード例 #7
0
 public override bool IsConfirmed(string userName)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(userName, session);
         return(user != null && user.IsApproved);
     }
 }
コード例 #8
0
 public override string[] GetRolesForUser(string username)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(username, session);
         return(user != null ? user.Roles : new string[] {});
     }
 }
コード例 #9
0
 public override bool DeleteAccount(string userName)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(userName, session);
         if (user != null)
         {
             session.Delete(user);
             session.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #10
0
 public override bool ChangePassword(string username, string oldPassword, string newPassword)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsernameAndPassword(username, HashPassword(oldPassword), session);
         if (user != null)
         {
             user.Password           = HashPassword(newPassword);
             user.LastPasswordChange = DateTime.Now;
             session.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #11
0
 public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsernameAndPassword(username, HashPassword(password), session);
         if (user != null)
         {
             user.PasswordQuestion = newPasswordQuestion;
             user.PasswordAnswer   = newPasswordAnswer;
             session.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #12
0
 public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(userName, session);
         if (user != null)
         {
             user.PasswordResetToken       = Guid.NewGuid().ToString();
             user.PasswordResetTokenExpiry = DateTime.Now.Add(TimeSpan.FromMinutes(tokenExpirationInMinutesFromNow));
             session.SaveChanges();
             return(user.PasswordResetToken);
         }
         return(null);
     }
 }
コード例 #13
0
 public override string ResetPassword(string username, string answer)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsernameAndAnswer(username, answer, session);
         if (user != null)
         {
             var password = Membership.GeneratePassword(MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters);
             user.Password           = HashPassword(password);
             user.LastPasswordChange = DateTime.Now;
             session.SaveChanges();
             return(password);
         }
         throw new MembershipPasswordException("Unable to reset password.");
     }
 }
コード例 #14
0
 public override bool ResetPasswordWithToken(string token, string newPassword)
 {
     using (var session = DocumentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByPasswordResetToken(token, session);
         if (user != null)
         {
             user.Password = BirdBrainMembershipProvider.HashPassword(newPassword);
             user.PasswordResetTokenExpiry = DateTime.MinValue;
             user.LastPasswordChange       = DateTime.Now;
             session.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #15
0
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsername(username, session);
         if (user != null)
         {
             if (userIsOnline)
             {
                 user.LastActive = DateTime.Now;
                 session.SaveChanges();
             }
             return(new BirdBrainMembershipUser(user));
         }
         return(null);
     }
 }
コード例 #16
0
        public override string CreateAccount(string userName, string password, bool requireConfirmationToken)
        {
            MembershipCreateStatus status;

            CreateUser(userName, password, null, null, null, !requireConfirmationToken, null, out status);
            if (status.Equals(MembershipCreateStatus.Success) && requireConfirmationToken)
            {
                using (var session = DocumentStore.OpenSession())
                {
                    var user = BirdBrainHelper.GetUserByUsername(userName, session);
                    user.ConfirmationToken = Guid.NewGuid().ToString();
                    session.SaveChanges();
                    return(user.ConfirmationToken);
                }
            }
            return(null);
        }
コード例 #17
0
        public override string CreateAccount(string userName, string password, bool requireConfirmationToken)
        {
            MembershipCreateStatus status;

            CreateUser(userName, password, null, null, null, !requireConfirmationToken, null, out status);
            if (status.Equals(MembershipCreateStatus.Success) && requireConfirmationToken)
            {
                using (var session = DocumentStore.OpenSession())
                {
                    session.Query <User>()
                    .Customize(a => a.WaitForNonStaleResultsAsOfLastWrite())
                    .First(u => u.Username == userName);
                    var user = BirdBrainHelper.GetUserByUsername(userName, session);
                    user.ConfirmationToken = Guid.NewGuid().ToString();
                    session.SaveChanges();
                    return(user.ConfirmationToken);
                }
            }
            return(null);
        }
コード例 #18
0
 public override bool ValidateUser(string username, string password)
 {
     using (var session = documentStore.OpenSession())
     {
         var user = BirdBrainHelper.GetUserByUsernameAndPassword(username, HashPassword(password), session);
         if (user != null)
         {
             user.LastActive = DateTime.Now;
             user.LastLogin  = DateTime.Now;
             session.SaveChanges();
             return(true);
         }
         user = BirdBrainHelper.GetUserByUsername(username, session);
         if (user != null)
         {
             user.PasswordFailuresSinceLastSuccess += 1;
             user.LastPasswordFailures              = DateTime.Now;
             session.SaveChanges();
         }
         return(false);
     }
 }