public void PersonWithPrimaryEmailShouldHandleAccountProtectionProfileCorrectly(string personGuid, string emailSearch, int accountProtectionProfile)
        {
            if (!Bus.RockMessageBus.IsRockStarted)
            {
                Bus.RockMessageBus.IsRockStarted = true;
                Bus.RockMessageBus.StartAsync().Wait();
            }

            var securitySettingService = new SecuritySettingsService();

            securitySettingService.SecuritySettings.AccountProtectionProfilesForDuplicateDetectionToIgnore = new List <AccountProtectionProfile>();
            securitySettingService.Save();

            // Give time for cache to update.
            Thread.Sleep(50);

            using (var rockContext = new RockContext())
            {
                var personService = new PersonService(rockContext);
                var person        = personService.Get(personGuid.AsGuid());

                var personMatchQuery = new PersonService.PersonMatchQuery(person.FirstName, person.LastName, emailSearch, null)
                {
                    MobilePhone   = null,
                    Gender        = person.Gender,
                    BirthDate     = person.BirthDate,
                    SuffixValueId = person.SuffixValueId
                };

                var foundPerson = personService.FindPerson(personMatchQuery, false);
                Assert.That.IsNotNull(foundPerson);
            }

            securitySettingService.SecuritySettings.AccountProtectionProfilesForDuplicateDetectionToIgnore = new List <AccountProtectionProfile> {
                ( AccountProtectionProfile )accountProtectionProfile
            };
            securitySettingService.Save();

            // Give time for cache to update.
            Thread.Sleep(50);

            using (var rockContext = new RockContext())
            {
                var personService = new PersonService(rockContext);
                var person        = personService.Get(personGuid.AsGuid());

                var personMatchQuery = new PersonService.PersonMatchQuery(person.FirstName, person.LastName, emailSearch, null)
                {
                    MobilePhone   = null,
                    Gender        = person.Gender,
                    BirthDate     = person.BirthDate,
                    SuffixValueId = person.SuffixValueId
                };

                var foundPerson = personService.FindPerson(personMatchQuery, false);
                Assert.That.IsNull(foundPerson);
            }
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var highProfile    = RoleCache.Get(ddlHighRoles.SelectedValue.AsInteger());
            var extremeProfile = RoleCache.Get(ddlExtremeRoles.SelectedValue.AsInteger());

            if (highProfile == null || extremeProfile == null)
            {
                return;
            }

            _securitySettingsService.SecuritySettings.AccountProtectionProfilesForDuplicateDetectionToIgnore =
                cblIgnoredAccountProtectionProfiles.SelectedValuesAsInt.Select(a => ( AccountProtectionProfile )a).ToList();

            _securitySettingsService.SecuritySettings.DisableTokensForAccountProtectionProfiles =
                cblDisableTokensForAccountProtectionProfiles.SelectedValuesAsInt.Select(a => ( AccountProtectionProfile )a).ToList();

            _securitySettingsService.SecuritySettings.AccountProtectionProfileSecurityGroup.AddOrReplace(AccountProtectionProfile.Extreme, extremeProfile);
            _securitySettingsService.SecuritySettings.AccountProtectionProfileSecurityGroup.AddOrReplace(AccountProtectionProfile.High, highProfile);

            if (_securitySettingsService.Save())
            {
                nbSaveResult.Text = "Your Security Settings have been saved.";
                nbSaveResult.NotificationBoxType = NotificationBoxType.Success;
                nbSaveResult.Visible             = true;
            }
            else
            {
                var errors = "<li>" + _securitySettingsService.ValidationResults.Select(r => r.ErrorMessage).JoinStrings("</li><li>") + "</li>";
                errors = errors.Replace("<li></li>", string.Empty);

                nbSaveResult.Text = $"The following errors occurred while trying to save:<ul>{errors}</ul>";
                nbSaveResult.NotificationBoxType = NotificationBoxType.Danger;
                nbSaveResult.Visible             = true;
            }
        }