Beispiel #1
0
        public void AddRolesToUser(string[] roleNames, string userName)
        {
            var userService = new UserService();

            var user = userService.GetUser(userName);
            if (user != null)
            {
                var roles = user.MemberShip.Roles;
                foreach (var item in roleNames)
                {
                    if (!roles.Select(x => x.RoleName).Contains(item))
                    {
                        var role = GetRole(item);
                        if (role != null)
                            user.MemberShip.Roles.Add(role);
                    }
                }
                userService.UpdateMemberShip(user.MemberShip);
            }
        }
 public override int GetPasswordFailuresSinceLastSuccess(string userName)
 {
     var user = new UserService().GetUser(userName);
     return user.MemberShip.PasswordFailuresSinceLastSuccess;
 }
 public override DateTime GetPasswordChangedDate(string userName)
 {
     var user = new UserService().GetUser(userName);
     return user.MemberShip.PasswordChangedDate;
 }
 public override DateTime GetLastPasswordFailureDate(string userName)
 {
     var user = new UserService().GetUser(userName);
     return user.MemberShip.LastPasswordFailureDate;
 }
 public override DateTime GetCreateDate(string userName)
 {
     var user = new UserService().GetUser(userName);
     return user.MemberShip.CreateDate;
 }
 public override ICollection<OAuthAccountData> GetAccountsForUser(string userName)
 {
     var user = new UserService().GetUser(userName);
     if (user == null)
     {
         throw new ProviderException("用户不存在");
     }
     List<OAuthAccountData> oalist = new List<OAuthAccountData>();
     user.OAuthMemberShips.ToList().ForEach(o =>
     {
         oalist.Add(new OAuthAccountData(o.Provider, o.ProviderUserId));
     });
     return oalist;
 }
        public override DateTime GetCreateDate(string userName)
        {
            var user = new UserService().GetUser(userName);

            return(user.MemberShip.CreateDate);
        }
 public override bool ValidateUser(string username, string password)
 {
     var user = new UserService().GetUser(username);
     if (user == null) return false;
     string pwd = EncodePassword(password, this.PasswordFormat, user.MemberShip.PasswordSalt);
     return pwd == user.MemberShip.Password;
 }
 public override bool ConfirmAccount(string userName, string accountConfirmationToken)
 {
     int status = new UserService().ConfirmAccount(userName, accountConfirmationToken);
     if (status != 0)
     {
         return false;
     }
     return true;
 }
Beispiel #10
0
 public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
 {
     if (ValidateUser(username, password))
     {
         var user = new UserService().GetUser(username);
         user.MemberShip.PasswordQuestion = newPasswordQuestion;
         user.MemberShip.QuestionAnswer = EncodePassword(newPasswordAnswer, this.PasswordFormat, user.MemberShip.PasswordSalt);
         new UserService().UpdateMemberShip(user.MemberShip);
         return true;
     }
     return false;
 }
Beispiel #11
0
 public override bool ChangePassword(string username, string oldPassword, string newPassword)
 {
     if (ValidateUser(username, oldPassword))
     {
         var user = new UserService().GetUser(username);
         user.MemberShip.Password = EncodePassword(newPassword, this.PasswordFormat, user.MemberShip.PasswordSalt);
         new UserService().UpdateMemberShip(user.MemberShip);
     }
     return false;
 }
Beispiel #12
0
        public override int GetPasswordFailuresSinceLastSuccess(string userName)
        {
            var user = new UserService().GetUser(userName);

            return(user.MemberShip.PasswordFailuresSinceLastSuccess);
        }
Beispiel #13
0
        public override DateTime GetPasswordChangedDate(string userName)
        {
            var user = new UserService().GetUser(userName);

            return(user.MemberShip.PasswordChangedDate);
        }
Beispiel #14
0
        public override DateTime GetLastPasswordFailureDate(string userName)
        {
            var user = new UserService().GetUser(userName);

            return(user.MemberShip.LastPasswordFailureDate);
        }
Beispiel #15
0
 public override string GetUserNameByEmail(string email)
 {
     var user = new UserService().GetUser(email);
     if(user==null)
         return string.Empty;
     return user.UserName;
 }
Beispiel #16
0
 public override bool UnlockUser(string userName)
 {
     var user = new UserService().GetUser(userName);
     if (user == null)
         return false;
     user.MemberShip.IsLockOut = false;
     new UserService().UpdateMemberShip(user.MemberShip);
     return true;
 }
Beispiel #17
0
 public override bool DeleteUser(string username, bool deleteAllRelatedData)
 {
     var service = new UserService();
     var user = service.GetUser(username);
     if (user == null)
         return false;
     if (deleteAllRelatedData)
         service.DeleteAccount(username);
     service.DeleteUser(user);
     return true;
 }
Beispiel #18
0
        private void GetPasswordWithFormat(string username, bool updateLastLoginActivityDate, out int status,
            out string password,
            out string passwordSalt,
            out int failedPasswordAttemptCount, out int failedPasswordAnswerAttemptCount, out DateTime lastActivityDate,
            out DateTime lastLoginDate)
        {
            User user = new UserService().GetUser(username);

            if (user != null && user.MemberShip != null)
            {
                if (updateLastLoginActivityDate)
                {
                    user.MemberShip.LastActivityDate = DateTime.UtcNow;
                    user.MemberShip.LastLoginDate = DateTime.UtcNow;

                    new UserService().UpdateUser(user);
                }

                password = user.MemberShip.Password;
                passwordSalt = user.MemberShip.PasswordSalt;
                failedPasswordAttemptCount = user.MemberShip.PasswordFailuresSinceLastSuccess;
                failedPasswordAnswerAttemptCount = user.MemberShip.AnswerFailureCount;
                lastLoginDate = user.MemberShip.LastLoginDate;
                lastActivityDate = user.MemberShip.LastActivityDate;

                status = 0;
            }
            else
            {
                password = null;
                passwordFormat = System.Web.Security.MembershipPasswordFormat.Clear;
                passwordSalt = null;
                failedPasswordAttemptCount = 0;
                failedPasswordAnswerAttemptCount = 0;
                lastLoginDate = DateTime.UtcNow;
                lastActivityDate = DateTime.UtcNow;

                status = 1;
            }
        }
Beispiel #19
0
 public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
 {
     var user = new UserService().GetUser(userName);
     if (user == null || user.MemberShip == null)
     {
         throw new ProviderException("本地帐号不存在");
     }
     if (user.MemberShip.PasswordVerificationTokenExpirationDate > DateTime.UtcNow)
     {
         return user.MemberShip.PasswordVerificationToken;
     }
     string token = UserService.GenerateToken();
     user.MemberShip.PasswordVerificationToken = token;
     user.MemberShip.PasswordVerificationTokenExpirationDate = DateTime.UtcNow.AddMinutes((double)tokenExpirationInMinutesFromNow);
     new UserService().UpdateMemberShip(user.MemberShip);
     return token;
 }