Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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;
        }