Example #1
0
        public override void UpdateUser( MembershipUser user )
        {
            UserService UserService = new Services.Cms.UserService();

            Rock.Models.Cms.User userModel = UserService.GetUserByApplicationNameAndUsername( applicationName, user.UserName );

            if ( userModel != null )
            {
                userModel.Email = user.Email;
                userModel.Comment = user.Comment;
                userModel.IsApproved = user.IsApproved;
                UserService.Save( userModel, CurrentPersonId() );
            }
        }
Example #2
0
        public override bool ValidateUser( string username, string password )
        {
            UserService UserService = new Services.Cms.UserService();

            Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndUsername( applicationName, username );

            if ( user != null )
                return ValidateUser( UserService, user, password );
            else
                return false;
        }
Example #3
0
        public override string ResetPassword( string username, string answer )
        {
            if ( !EnablePasswordReset )
                throw new NotSupportedException( "Password Reset is not enabled" );

            UserService UserService = new Services.Cms.UserService();

            Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndUsername( applicationName, username );

            if ( user != null )
            {
                if ( string.IsNullOrEmpty( answer ) && RequiresQuestionAndAnswer )
                {
                    UpdateFailureCount( user, FailureType.PasswordAnswer );
                    throw new ProviderException( "Password answer required for password reset" );
                }

                string newPassword = System.Web.Security.Membership.GeneratePassword( newPasswordLength, MinRequiredNonAlphanumericCharacters );

                ValidatePasswordEventArgs args = new ValidatePasswordEventArgs( username, newPassword, true );

                OnValidatingPassword( args );

                if ( args.Cancel )
                {
                    if ( args.FailureInformation != null )
                        throw args.FailureInformation;
                    else
                        throw new MembershipPasswordException( "Reset password canceled due to password validation failure" );
                }

                if ( user.IsLockedOut ?? false )
                    throw new MembershipPasswordException( "The supplied user is locked out" );

                if ( RequiresQuestionAndAnswer && EncodePassword( answer) != user.PasswordAnswer )
                {
                    UpdateFailureCount( user, FailureType.PasswordAnswer );
                    throw new MembershipPasswordException( "Incorrect password answer" );
                }

                user.Password = EncodePassword( newPassword );
                user.LastPasswordChangedDate = DateTime.Now;
                UserService.Save( user, CurrentPersonId() );

                return newPassword;
            }
            else
                throw new MembershipPasswordException( "User does not exist" );
        }
Example #4
0
        public override bool UnlockUser( string userName )
        {
            UserService UserService = new Services.Cms.UserService();

            Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndUsername( applicationName, userName );

            if ( user != null )
            {
                user.IsLockedOut = false;
                user.LastLockedOutDate = DateTime.Now;
                UserService.Save( user, CurrentPersonId() );
                return true;
            }
            else
                return false;
        }
Example #5
0
        public override MembershipUser GetUser( object providerUserKey, bool userIsOnline )
        {
            if ( providerUserKey != null && providerUserKey is int )
            {
                UserService UserService = new Services.Cms.UserService();

                Rock.Models.Cms.User user = UserService.GetUser( ( int )providerUserKey );

                if ( user != null )
                    return GetUser( UserService, user, userIsOnline );
                else
                    return null;
            }
            else
                throw new ProviderException( "Invalid providerUserKey" );
        }
Example #6
0
 public override string GetUserNameByEmail( string email )
 {
     UserService UserService = new Services.Cms.UserService();
     return GetUserNameByEmail( UserService, email );
 }
Example #7
0
        public override int GetNumberOfUsersOnline()
        {
            UserService UserService = new Services.Cms.UserService();

            TimeSpan onlineSpan = new TimeSpan( 0, System.Web.Security.Membership.UserIsOnlineTimeWindow, 0 );
            DateTime compareTime = DateTime.Now.Subtract( onlineSpan );

            return UserService.Queryable().Where( u =>
                    u.ApplicationName == applicationName &&
                    u.LastActivityDate > compareTime).Count();
        }
Example #8
0
 public override MembershipUser GetUser( string username, bool userIsOnline )
 {
     UserService UserService = new Services.Cms.UserService();
     return GetUser( UserService, username, userIsOnline );
 }
Example #9
0
        public override MembershipUserCollection GetAllUsers( int pageIndex, int pageSize, out int totalRecords )
        {
            MembershipUserCollection membershipUsers = new MembershipUserCollection();

            UserService UserService = new Services.Cms.UserService();

            int counter = 0;
            int startIndex = pageSize * pageIndex;
            int endIndex = startIndex + pageSize - 1;

            foreach ( Rock.Models.Cms.User user
                in UserService.Queryable().Where( u =>
                    u.ApplicationName == applicationName ) )
            {
                if ( counter >= startIndex && counter <= endIndex )
                    membershipUsers.Add( GetUserFromModel( user ) );

                counter++;
            }

            totalRecords = counter;
            return membershipUsers;
        }
Example #10
0
        public override MembershipUserCollection FindUsersByName( string usernameToMatch, int pageIndex, int pageSize, out int totalRecords )
        {
            MembershipUserCollection membershipUsers = new MembershipUserCollection();

            UserService UserService = new Services.Cms.UserService();

            int counter = 0;
            int startIndex = pageSize * pageIndex;
            int endIndex = startIndex + pageSize - 1;

            foreach ( Rock.Models.Cms.User user
                in UserService.Queryable().Where( u =>
                    u.ApplicationName == applicationName &&
                    u.Username.ToLower().StartsWith( usernameToMatch.ToLower() ) ) )
            {
                if ( counter >= startIndex && counter <= endIndex )
                    membershipUsers.Add( GetUserFromModel( user ) );

                counter++;
            }

            totalRecords = counter;
            return membershipUsers;
        }
Example #11
0
        public override bool DeleteUser( string username, bool deleteAllRelatedData )
        {
            UserService UserService = new Services.Cms.UserService();

            Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndUsername( applicationName, username );

            if ( user != null )
            {
                try
                {
                    UserService.DeleteUser( user );
                    return true;
                }
                catch ( SystemException ex )
                {
                    throw new ProviderException( "Error occurred attempting to delete User", ex );
                }
            }
            else
                return false;
        }
Example #12
0
        public override MembershipUser CreateUser( string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status )
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs( username, password, true );

            OnValidatingPassword( args );

            if ( args.Cancel )
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            UserService UserService = new Services.Cms.UserService();

            if ( ( RequiresUniqueEmail && ( GetUserNameByEmail( UserService, email ) != String.Empty ) ) )
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser membershipUser = GetUser( UserService, username, false );

            if ( membershipUser == null )
            {
                DateTime createDate = DateTime.Now;

                Rock.Models.Cms.User user = new Rock.Models.Cms.User();

                if ( providerUserKey != null && providerUserKey is int )
                    user.PersonId = ( int )providerUserKey;
                else
                {
                    status = MembershipCreateStatus.InvalidProviderUserKey;
                    return null;
                }

                user.ApplicationName = applicationName;
                user.Username = username;
                user.Password = EncodePassword( password );
                user.Email = email;
                user.PasswordQuestion = passwordQuestion;
                user.PasswordAnswer = passwordAnswer;
                user.IsApproved = isApproved;
                user.Comment = string.Empty;
                user.CreationDate = createDate;
                user.LastPasswordChangedDate = createDate;
                user.LastActivityDate = createDate;
                user.IsLockedOut = false;
                user.LastLockedOutDate = createDate;
                user.FailedPasswordAttemptCount = 0;
                user.FailedPasswordAttemptWindowStart = createDate;
                user.FailedPasswordAnswerAttemptCount = 0;
                user.FailedPasswordAnswerAttemptWindowStart = createDate;
                user.AuthenticationType = (int)AuthenticationType.Database;

                try
                {
                    UserService.AddUser( user );
                    UserService.Save( user, CurrentPersonId() );
                    status = MembershipCreateStatus.Success;

                }
                catch ( SystemException ex )
                {
                    status = MembershipCreateStatus.ProviderError;
                }

                return GetUser( UserService, user, false );

            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }
        }
Example #13
0
        public override bool ChangePasswordQuestionAndAnswer( string username, string password, string newPasswordQuestion, string newPasswordAnswer )
        {
            UserService UserService = new Services.Cms.UserService();

            Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndUsername( applicationName, username );

            if ( user != null )
            {
                if ( !ValidateUser( UserService, user, password ) )
                    return false;

                user.PasswordQuestion = newPasswordQuestion;
                user.PasswordAnswer = newPasswordAnswer;
                UserService.Save( user, CurrentPersonId() );
                return true;
            }
            else
                return false;
        }