Exemplo n.º 1
0
        private MembershipUser GetUser( UserService UserService, string username, bool userIsOnline )
        {
            Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndUsername( applicationName, username );

            if ( user != null )
                return GetUser( UserService, user, userIsOnline );
            else
                return null;
        }
Exemplo n.º 2
0
        private UserInfo GetUser( string username )
        {
            using ( new Rock.Helpers.UnitOfWorkScope() )
            {
                UserService UserService = new UserService();
                MemberService MemberService = new MemberService();

                Dictionary<string, UserInfo> applicationUsers = GetUsers();

                if ( applicationUsers == null )
                    applicationUsers = new Dictionary<string, UserInfo>();

                if ( !applicationUsers.ContainsKey( username ) )
                {
                    Rock.Models.Cms.User userModel = UserService.GetUserByApplicationNameAndUsername( applicationName, username );
                    if ( userModel != null && userModel.PersonId != null )
                    {
                        List<string> rolenames = new List<string>();

                        foreach ( Rock.Models.Groups.Member member in
                            MemberService.Queryable().Where( m => m.Group.IsSecurityRole && m.PersonId == userModel.PersonId.Value ) )
                            rolenames.Add( member.Group.Guid.ToString() );

                        applicationUsers.Add( userModel.Username, new UserInfo( userModel.PersonId.Value, rolenames ) );
                    }
                }

                if ( applicationUsers.ContainsKey( username ) )
                    return applicationUsers[username];
                else
                    return null;
            }
        }
Exemplo n.º 3
0
        public override bool ChangePassword( string username, string oldPassword, string newPassword )
        {
            UserService UserService = new UserService();

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

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

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

                OnValidatingPassword( args );

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

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

                return true;
            }
            else
                return false;
        }