Esempio n. 1
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;
            }
        }
Esempio n. 2
0
 private bool ValidateUser( UserService UserService, Rock.Models.Cms.User user, string password )
 {
     if ( EncodePassword( password ) == user.Password )
     {
         if ( user.IsApproved ?? false )
         {
             user.LastLoginDate = DateTime.Now;
             UserService.Save( user, CurrentPersonId() );
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         UpdateFailureCount( user, FailureType.Password );
         UserService.Save( user, CurrentPersonId() );
         return false;
     }
 }
Esempio n. 3
0
 private string GetUserNameByEmail( UserService UserService, string email )
 {
     Rock.Models.Cms.User user = UserService.GetUserByApplicationNameAndEmail( applicationName, email );
     if ( user != null )
         return user.Username;
     else
         return string.Empty;
 }
Esempio n. 4
0
        private MembershipUser GetUser( UserService UserService, Rock.Models.Cms.User user, bool userIsOnline )
        {
            MembershipUser membershipUser = GetUserFromModel( user );

            if ( userIsOnline )
            {
                user.LastActivityDate = DateTime.Now;
                UserService.Save( user, CurrentPersonId(membershipUser) );
            }

            return membershipUser;
        }
Esempio n. 5
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;
        }
Esempio n. 6
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;
        }