Пример #1
0
        /// <summary>
        /// Changes the password.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="oldPassword">The old password.</param>
        /// <param name="newPassword">The new password.</param>
        /// <param name="warningMessage">The warning message.</param>
        /// <returns>
        /// A <see cref="System.Boolean" /> value that indicates if the password change was successful. <c>true</c> if successful; otherwise <c>false</c>.
        /// </returns>
        /// <exception cref="System.Exception">Cannot change password on external service type</exception>
        public override bool ChangePassword(UserLogin user, string oldPassword, string newPassword, out string warningMessage)
        {
            warningMessage = null;
            AuthenticationComponent authenticationComponent = AuthenticationContainer.GetComponent(user.EntityType.Name);

            if (authenticationComponent == null || !authenticationComponent.IsActive)
            {
                throw new Exception(string.Format("'{0}' service does not exist, or is not active", user.EntityType.FriendlyName));
            }

            if (authenticationComponent.ServiceType == AuthenticationServiceType.External)
            {
                throw new Exception("Cannot change password on external service type");
            }

            if (!authenticationComponent.Authenticate(user, oldPassword))
            {
                return(false);
            }

            user.Password = authenticationComponent.EncodePassword(user, newPassword);
            user.LastPasswordChangedDateTime = RockDateTime.Now;

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Changes the password.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        public void ChangePassword(UserLogin user, string password)
        {
            if (user.ServiceType == AuthenticationServiceType.External)
            {
                throw new Exception("Cannot change password on external service type");
            }

            AuthenticationComponent authenticationComponent = GetComponent(user.ServiceName);

            if (authenticationComponent == null)
            {
                throw new Exception(string.Format("'{0}' service does not exist, or is not active", user.ServiceName));
            }

            user.Password = authenticationComponent.EncodePassword(user, password);
            user.LastPasswordChangedDate = DateTime.Now;
        }
Пример #3
0
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="serviceType">Type of the service.</param>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="isConfirmed">if set to <c>true</c> [is confirmed].</param>
        /// <param name="currentPersonId">The current person id.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException">username;Username already exists</exception>
        /// <exception cref="System.ArgumentException">serviceName</exception>
        public UserLogin Create(Rock.Model.Person person,
                                AuthenticationServiceType serviceType,
                                string serviceName,
                                string username,
                                string password,
                                bool isConfirmed,
                                int?currentPersonId)
        {
            UserLogin user = this.GetByUserName(username);

            if (user != null)
            {
                throw new ArgumentOutOfRangeException("username", "Username already exists");
            }

            DateTime createDate = DateTime.Now;

            user                         = new UserLogin();
            user.ServiceType             = serviceType;
            user.ServiceName             = serviceName;
            user.UserName                = username;
            user.IsConfirmed             = isConfirmed;
            user.CreationDate            = createDate;
            user.LastPasswordChangedDate = createDate;
            if (person != null)
            {
                user.PersonId = person.Id;
            }

            if (serviceType == AuthenticationServiceType.Internal)
            {
                AuthenticationComponent authenticationComponent = GetComponent(serviceName);
                if (authenticationComponent == null)
                {
                    throw new ArgumentException(string.Format("'{0}' service does not exist, or is not active", serviceName), "serviceName");
                }

                user.Password = authenticationComponent.EncodePassword(user, password);
            }

            this.Add(user, currentPersonId);
            this.Save(user, currentPersonId);

            return(user);
        }