Exemplo n.º 1
0
        protected void btnSend_Click( object sender, EventArgs e )
        {
            var mergeObjects = new Dictionary<string, object>();

            var url = LinkedPageUrl( "ConfirmationPage" );
            if ( string.IsNullOrWhiteSpace( url ) )
            {
                url = ResolveRockUrl( "~/ConfirmAccount" );
            }
            mergeObjects.Add( "ConfirmAccountUrl", RootPath + url.TrimStart( new char[] { '/' } ) );

            var personDictionaries = new List<IDictionary<string, object>>();

            var personService = new PersonService();
            var userLoginService = new UserLoginService();

            foreach ( Person person in personService.GetByEmail( tbEmail.Text ) )
            {
                var users = new List<IDictionary<string,object>>();
                foreach ( UserLogin user in userLoginService.GetByPersonId( person.Id ) )
                {
                    if ( user.EntityType != null )
                    {
                        var component = AuthenticationContainer.GetComponent( user.EntityType.Name );
                        if ( component.ServiceType == AuthenticationServiceType.Internal )
                        {
                            users.Add( user.ToDictionary() );
                        }
                    }
                }

                if (users.Count > 0)
                {
                    IDictionary<string,object> personDictionary = person.ToDictionary();
                    personDictionary.Add("Users", users.ToArray());
                    personDictionaries.Add( personDictionary );
                }
            }

            if ( personDictionaries.Count > 0 )
            {
                mergeObjects.Add( "Persons", personDictionaries.ToArray() );

                var recipients = new Dictionary<string, Dictionary<string, object>>();
                recipients.Add( tbEmail.Text, mergeObjects );

                Email email = new Email( GetAttributeValue( "EmailTemplate" ) );
                email.Send( recipients );

                pnlEntry.Visible = false;
                pnlSuccess.Visible = true;
            }
            else
                pnlWarning.Visible = true;
        }
        /// <summary>
        /// Handles the Click event of the btnSend 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 btnSend_Click( object sender, EventArgs e )
        {
            var url = LinkedPageUrl( "ConfirmationPage" );
            if ( string.IsNullOrWhiteSpace( url ) )
            {
                url = ResolveRockUrl( "~/ConfirmAccount" );
            }

            var mergeObjects = GlobalAttributesCache.GetMergeFields( CurrentPerson );
            mergeObjects.Add( "ConfirmAccountUrl", RootPath + url.TrimStart( new char[] { '/' } ) );
            var results = new List<IDictionary<string, object>>();

            var rockContext = new RockContext();
            var personService = new PersonService( rockContext );
            var userLoginService = new UserLoginService( rockContext );

            foreach ( Person person in personService.GetByEmail( tbEmail.Text )
                .Where( p => p.Users.Any()))
            {
                var users = new List<UserLogin>();
                foreach ( UserLogin user in userLoginService.GetByPersonId( person.Id ) )
                {
                    if ( user.EntityType != null )
                    {
                        var component = AuthenticationContainer.GetComponent( user.EntityType.Name );
                        if ( !component.RequiresRemoteAuthentication )
                        {
                            users.Add( user );
                        }
                    }
                }

                var resultsDictionary = new Dictionary<string, object>();
                resultsDictionary.Add( "Person", person);
                resultsDictionary.Add( "Users", users );
                results.Add( resultsDictionary );
            }

            if ( results.Count > 0 )
            {
                mergeObjects.Add( "Results", results.ToArray() );
                var recipients = new List<RecipientData>();
                recipients.Add( new RecipientData( tbEmail.Text, mergeObjects ) );

                Email.Send( GetAttributeValue( "EmailTemplate" ).AsGuid(), recipients, ResolveRockUrlIncludeRoot( "~/" ), ResolveRockUrlIncludeRoot( "~~/" ) );

                pnlEntry.Visible = false;
                pnlSuccess.Visible = true;
            }
            else
            {
                pnlWarning.Visible = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Processes the bounce.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="bounceType">Type of the bounce.</param>
        /// <param name="message">The message.</param>
        /// <param name="bouncedDateTime">The bounced date time.</param>
        public static void ProcessBounce( string email, BounceType bounceType, string message, DateTime bouncedDateTime )
        {
            // currently only processing hard bounces
            if ( bounceType == BounceType.HardBounce )
            {
                // get people who have those emails

                RockContext rockContext = new RockContext();
                PersonService personService = new PersonService( rockContext );

                var peopleWithEmail = personService.GetByEmail( email );

                foreach ( var person in peopleWithEmail )
                {
                    person.IsEmailActive = false;

                    person.EmailNote = String.Format( "Email experienced a {0} on {1} ({2}).", bounceType.Humanize(), bouncedDateTime.ToShortDateString(), message );
                }

                rockContext.SaveChanges();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Click event of the btnSend 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 btnSend_Click( object sender, EventArgs e )
        {
            var url = LinkedPageUrl( "ConfirmationPage" );
            if ( string.IsNullOrWhiteSpace( url ) )
            {
                url = ResolveRockUrl( "~/ConfirmAccount" );
            }

            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson );
            mergeFields.Add( "ConfirmAccountUrl", RootPath + url.TrimStart( new char[] { '/' } ) );
            var results = new List<IDictionary<string, object>>();

            var rockContext = new RockContext();
            var personService = new PersonService( rockContext );
            var userLoginService = new UserLoginService( rockContext );

            bool hasAccountWithPasswordResetAbility = false;
            List<string> accountTypes = new List<string>();

            foreach ( Person person in personService.GetByEmail( tbEmail.Text )
                .Where( p => p.Users.Any()))
            {
                var users = new List<UserLogin>();
                foreach ( UserLogin user in userLoginService.GetByPersonId( person.Id ) )
                {
                    if ( user.EntityType != null )
                    {
                        var component = AuthenticationContainer.GetComponent( user.EntityType.Name );
                        if ( !component.RequiresRemoteAuthentication )
                        {
                            users.Add( user );
                            hasAccountWithPasswordResetAbility = true;
                        }

                        accountTypes.Add( user.EntityType.FriendlyName );
                    }
                }

                var resultsDictionary = new Dictionary<string, object>();
                resultsDictionary.Add( "Person", person);
                resultsDictionary.Add( "Users", users );
                results.Add( resultsDictionary );
            }

            if ( results.Count > 0 && hasAccountWithPasswordResetAbility )
            {
                mergeFields.Add( "Results", results.ToArray() );
                var recipients = new List<RecipientData>();
                recipients.Add( new RecipientData( tbEmail.Text, mergeFields ) );

                Email.Send( GetAttributeValue( "EmailTemplate" ).AsGuid(), recipients, ResolveRockUrlIncludeRoot( "~/" ), ResolveRockUrlIncludeRoot( "~~/" ), false );

                pnlEntry.Visible = false;
                pnlSuccess.Visible = true;
            }
            else if (results.Count > 0 )
            {
                // the person has user accounts but none of them are allowed to have their passwords reset (Facebook/Google/etc)

                lWarning.Text = string.Format( @"<p>We were able to find the following accounts for this email, but
                                                none of them are able to be reset from this website.</p> <p>Accounts:<br /> {0}</p>
                                                <p>To create a new account with a username and password please see our <a href='{1}'>New Account</a>
                                                page.</p>"
                                    , string.Join( ",", accountTypes )
                                    , ResolveRockUrl( "~/NewAccount" ) );
                pnlWarning.Visible = true;
            }
            else
            {
                pnlWarning.Visible = true;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the person.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private Person GetPerson( RockContext rockContext )
        {
            var personService = new PersonService( rockContext );

            var personMatches = personService.GetByEmail( txtEmail.Text )
                .Where( p =>
                    p.LastName.Equals( txtLastName.Text, StringComparison.OrdinalIgnoreCase ) &&
                    ( ( p.FirstName != null && p.FirstName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) ||
                        ( p.NickName != null && p.NickName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) ) )
                .ToList();
            if ( personMatches.Count() == 1 )
            {
                return personMatches.FirstOrDefault();
            }
            else
            {
                DefinedValueCache dvcConnectionStatus = DefinedValueCache.Read( GetAttributeValue( "ConnectionStatus" ).AsGuid() );
                DefinedValueCache dvcRecordStatus = DefinedValueCache.Read( GetAttributeValue( "RecordStatus" ).AsGuid() );

                Person person = new Person();
                person.FirstName = txtFirstName.Text;
                person.LastName = txtLastName.Text;
                person.Email = txtEmail.Text;
                person.IsEmailActive = true;
                person.EmailPreference = EmailPreference.EmailAllowed;
                person.RecordTypeValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id;
                if ( dvcConnectionStatus != null )
                {
                    person.ConnectionStatusValueId = dvcConnectionStatus.Id;
                }

                if ( dvcRecordStatus != null )
                {
                    person.RecordStatusValueId = dvcRecordStatus.Id;
                }

                PersonService.SaveNewPerson( person, rockContext, null, false );

                return personService.Get( person.Id );
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Finds the person if they're logged in, or by email and name. If not found, creates a new person.
        /// </summary>
        /// <returns></returns>
        private Person FindPerson()
        {
            Person person;
            var personService = new PersonService();

            if ( CurrentPerson != null )
            {
                person = CurrentPerson;
            }
            else
            {
                person = personService.GetByEmail( tbEmail.Text )
                    .FirstOrDefault( p => p.FirstName == tbFirstName.Text && p.LastName == tbLastName.Text );
            }

            if ( person == null )
            {
                var definedValue = DefinedValueCache.Read( new Guid( GetAttributeValue( "DefaultConnectionStatus" ) ) );
                person = new Person
                {
                    FirstName = tbFirstName.Text,
                    LastName = tbLastName.Text,
                    Email = tbEmail.Text,
                    ConnectionStatusValueId = definedValue.Id,
                };

                personService.Add( person, CurrentPersonId );
                personService.Save( person, CurrentPersonId );
            }

            return person;
        }
        /// <summary>
        /// Gets the person.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private Person GetPerson( RockContext rockContext )
        {
            var personService = new PersonService( rockContext );

            var personMatches = personService.GetByEmail( txtEmail.Text )
                .Where( p =>
                    p.LastName.Equals( txtLastName.Text, StringComparison.OrdinalIgnoreCase ) &&
                    ( ( p.FirstName != null && p.FirstName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) ||
                        ( p.NickName != null && p.NickName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) ) )
                .ToList();
            if ( personMatches.Count() == 1 )
            {
                return personMatches.FirstOrDefault();
            }
            else
            {
                Person person = new Person();
                person.FirstName = txtFirstName.Text;
                person.LastName = txtLastName.Text;
                person.Email = txtEmail.Text;
                person.EmailPreference = EmailPreference.EmailAllowed;

                GroupService.SaveNewFamily( rockContext, person, null, false );

                return personService.Get( person.Id );
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the person.
        /// </summary>
        /// <param name="create">if set to <c>true</c> [create].</param>
        /// <returns></returns>
        private Person GetPerson( bool create )
        {
            Person person = null;

            int personId = ViewState["PersonId"] as int? ?? 0;
            if ( personId == 0 && TargetPerson != null )
            {
                person = TargetPerson;
            }
            else
            {
                using ( new UnitOfWorkScope() )
                {
                    var personService = new PersonService();

                    if ( personId != 0 )
                    {
                        person = personService.Get( personId );
                    }

                    if ( person == null && create )
                    {
                        // Check to see if there's only one person with same email, first name, and last name
                        if ( !string.IsNullOrWhiteSpace( txtEmail.Text ) &&
                            !string.IsNullOrWhiteSpace( txtFirstName.Text ) &&
                            !string.IsNullOrWhiteSpace( txtLastName.Text ) )
                        {
                            var personMatches = personService.GetByEmail( txtEmail.Text ).Where( p =>
                                p.LastName.Equals( txtLastName.Text, StringComparison.OrdinalIgnoreCase ) &&
                                ( p.FirstName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ||
                                p.NickName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) );
                            if ( personMatches.Count() == 1 )
                            {
                                person = personMatches.FirstOrDefault();
                            }
                        }

                        if ( person == null )
                        {
                            // Create Person
                            person = new Person();
                            person.FirstName = txtFirstName.Text;
                            person.LastName = txtLastName.Text;
                            person.Email = txtEmail.Text;

                            bool displayPhone = false;
                            if ( bool.TryParse( GetAttributeValue( "DisplayPhone" ), out displayPhone ) && displayPhone )
                            {
                                var phone = new PhoneNumber();
                                phone.Number = txtPhone.Text.AsNumeric();
                                phone.NumberTypeValueId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ) ).Id;
                                person.PhoneNumbers.Add( phone );
                            }

                            // Create Family Role
                            var groupMember = new GroupMember();
                            groupMember.Person = person;
                            groupMember.GroupRole = new GroupTypeRoleService().Get(new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) );

                            // Create Family
                            var group = new Group();
                            group.Members.Add( groupMember );
                            group.Name = person.LastName + " Family";
                            group.GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;

                            var groupLocation = new GroupLocation();
                            var location = new LocationService().Get(
                                txtStreet.Text, string.Empty, txtCity.Text, ddlState.SelectedValue, txtZip.Text );
                            if ( location != null )
                            {
                                Guid addressTypeGuid = Guid.Empty;
                                if ( !Guid.TryParse( GetAttributeValue( "AddressType" ), out addressTypeGuid ) )
                                {
                                    addressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME );
                                }

                                groupLocation = new GroupLocation();
                                groupLocation.Location = location;
                                groupLocation.GroupLocationTypeValueId = DefinedValueCache.Read( addressTypeGuid ).Id;

                                group.GroupLocations.Add( groupLocation );
                            }

                            var groupService = new GroupService();
                            groupService.Add( group, CurrentPersonId );
                            groupService.Save( group, CurrentPersonId );
                        }

                        ViewState["PersonId"] = person != null ? person.Id : 0;

                    }
                }
            }

            return person;
        }
        /// <summary>
        /// Gets the person.
        /// </summary>
        /// <param name="create">if set to <c>true</c> [create].</param>
        /// <returns></returns>
        private Person GetPerson( bool create )
        {
            Person person = null;
            var rockContext = new RockContext();

            int personId = ViewState["PersonId"] as int? ?? 0;
            if ( personId == 0 && TargetPerson != null )
            {
                person = TargetPerson;
            }
            else
            {
                var personService = new PersonService( rockContext );

                if ( personId != 0 )
                {
                    person = personService.Get( personId );
                }

                if ( person == null && create )
                {
                    // Check to see if there's only one person with same email, first name, and last name
                    if ( !string.IsNullOrWhiteSpace( txtEmail.Text ) &&
                        !string.IsNullOrWhiteSpace( txtFirstName.Text ) &&
                        !string.IsNullOrWhiteSpace( txtLastName.Text ) )
                    {
                        var personMatches = personService.GetByEmail( txtEmail.Text )
                            .Where( p =>
                                p.LastName.Equals( txtLastName.Text, StringComparison.OrdinalIgnoreCase ) &&
                                ( p.FirstName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ||
                                    p.NickName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) )
                            .ToList();
                        if ( personMatches.Count() == 1 )
                        {
                            person = personMatches.FirstOrDefault();
                        }
                    }

                    if ( person == null )
                    {
                        // Create Person
                        person = new Person();
                        person.FirstName = txtFirstName.Text;
                        person.LastName = txtLastName.Text;
                        person.Email = txtEmail.Text;
                        person.EmailPreference = EmailPreference.EmailAllowed;

                        bool displayPhone = false;
                        if ( bool.TryParse( GetAttributeValue( "DisplayPhone" ), out displayPhone ) && displayPhone )
                        {
                            var phone = new PhoneNumber();
                            phone.CountryCode = PhoneNumber.CleanNumber( pnbPhone.CountryCode );
                            phone.Number = PhoneNumber.CleanNumber( pnbPhone.Number );
                            phone.NumberTypeValueId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ) ).Id;
                            person.PhoneNumbers.Add( phone );
                        }

                        // Create Family
                        var familyGroup = GroupService.SaveNewFamily( rockContext, person, null, false  );
                        if ( familyGroup != null )
                        {
                            GroupService.AddNewFamilyAddress(
                                rockContext,
                                familyGroup,
                                GetAttributeValue( "AddressType" ),
                                txtStreet.Text,
                                string.Empty,
                                txtCity.Text,
                                ddlState.SelectedValue,
                                txtZip.Text );
                        }
                    }

                    ViewState["PersonId"] = person != null ? person.Id : 0;
                }
            }

            return person;
        }
Exemplo n.º 10
0
        private Person GetPerson()
        {
            using ( new UnitOfWorkScope() )
            {
                var personService = new PersonService();

                var personMatches = personService.GetByEmail( txtEmail.Text ).Where( p =>
                    p.LastName.Equals( txtLastName.Text, StringComparison.OrdinalIgnoreCase ) &&
                    ( ( p.FirstName != null && p.FirstName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) ||
                    ( p.NickName != null && p.NickName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) ) );

                if ( personMatches.Count() == 1 )
                {
                    return personMatches.FirstOrDefault();
                }
                else
                {
                    Person person = new Person();
                    person.FirstName = txtFirstName.Text;
                    person.LastName = txtLastName.Text;
                    person.Email = txtEmail.Text;

                    // Create Family Role
                    var groupMember = new GroupMember();
                    groupMember.Person = person;
                    groupMember.GroupRole = new GroupTypeRoleService().Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) );

                    // Create Family
                    var group = new Group();
                    group.Members.Add( groupMember );
                    group.Name = person.LastName + " Family";
                    group.GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;

                    // Save person/family
                    var groupService = new GroupService();
                    groupService.Add( group, CurrentPersonId );
                    groupService.Save( group, CurrentPersonId );

                    return personService.Get( person.Id );
                }
            }
        }