/// <summary>
        /// Sends the invite.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="component">The component.</param>
        /// <param name="document">The document.</param>
        /// <param name="person">The person.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        private bool SendInvite(RockContext rockContext, DigitalSignatureComponent component, SignatureDocument document, Person person, out List <string> errors)
        {
            errors = new List <string>();
            if (document != null &&
                document.SignatureDocumentTemplate != null &&
                document.SignatureDocumentTemplate.InviteSystemCommunicationId.HasValue &&
                person != null &&
                !string.IsNullOrWhiteSpace(person.Email))
            {
                string inviteLink = component.GetInviteLink(document, person, out errors);
                if (!errors.Any())
                {
                    var systemEmail = new SystemCommunicationService(rockContext).Get(document.SignatureDocumentTemplate.InviteSystemCommunicationId.Value);
                    if (systemEmail != null)
                    {
                        var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, person);
                        mergeFields.Add("SignatureDocument", document);
                        mergeFields.Add("InviteLink", inviteLink);

                        var emailMessage = new RockEmailMessage(systemEmail);
                        emailMessage.AddRecipient(new RockEmailMessageRecipient(person, mergeFields));
                        emailMessage.Send();
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends the invite.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="component">The component.</param>
        /// <param name="document">The document.</param>
        /// <param name="person">The person.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        private bool SendInvite(RockContext rockContext, DigitalSignatureComponent component, SignatureDocument document, Person person, out List <string> errors)
        {
            errors = new List <string>();
            if (document != null &&
                document.SignatureDocumentTemplate != null &&
                document.SignatureDocumentTemplate.InviteSystemEmailId.HasValue &&
                person != null &&
                !string.IsNullOrWhiteSpace(person.Email))
            {
                string inviteLink = component.GetInviteLink(document, person, out errors);
                if (!errors.Any())
                {
                    var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, person);
                    mergeFields.Add("SignatureDocument", document);
                    mergeFields.Add("InviteLink", inviteLink);

                    var recipients = new List <RecipientData>();
                    recipients.Add(new RecipientData(person.Email, mergeFields));

                    var systemEmail = new SystemEmailService(rockContext).Get(document.SignatureDocumentTemplate.InviteSystemEmailId.Value);
                    if (systemEmail != null)
                    {
                        var appRoot = Rock.Web.Cache.GlobalAttributesCache.Read(rockContext).GetValue("InternalApplicationRoot");
                        Email.Send(systemEmail.Guid, recipients, appRoot, string.Empty, false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load the SignNow control.
        /// </summary>
        /// <param name="currentRegistrantIndex">The current registrant index</param>
        /// <param name="registrationState">The registration state from RegistrationEntry</param>
        /// <param name="registrationInstanceState">The registration instance</param>
        /// <param name="digitalSignatureComponent">The digital signature component</param>
        /// <returns></returns>
        public bool Load(int currentRegistrantIndex, RegistrationInfo registrationState, RegistrationInstance registrationInstanceState)
        {
            CurrentRegistrantIndex    = currentRegistrantIndex;
            RegistrationState         = registrationState;
            RegistrationInstanceState = registrationInstanceState;

            var provider = DigitalSignatureContainer.GetComponent(RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.ProviderEntityType.Name);

            if (provider != null && provider.IsActive)
            {
                DigitalSignatureComponent = provider;
            }
            var registrant = RegistrationState.Registrants[CurrentRegistrantIndex];

            string firstName = RegistrationInstanceState.RegistrationTemplate.RegistrantTerm;

            if (RegistrationState != null && RegistrationState.RegistrantCount > CurrentRegistrantIndex)
            {
                firstName = registrant.GetFirstName(RegistrationInstanceState.RegistrationTemplate);
                string lastName = registrant.GetLastName(RegistrationInstanceState.RegistrationTemplate);
                string email    = registrant.GetEmail(RegistrationInstanceState.RegistrationTemplate);

                object   dateOfBirthObj = registrant.GetPersonFieldValue(RegistrationInstanceState.RegistrationTemplate, RegistrationPersonFieldType.Birthdate);
                DateTime?dateOfBirth    = null;
                if (dateOfBirthObj != null && dateOfBirthObj is DateTime? )
                {
                    dateOfBirth = dateOfBirthObj as DateTime?;
                }

                // If we have a single person, then we check to see if we already have the document
                var           rockContext     = new Rock.Data.RockContext();
                PersonService personService   = new PersonService(rockContext);
                var           possiblePersons = personService.GetByMatch(firstName, lastName, dateOfBirth, email: email);
                if (possiblePersons.Count() == 1)
                {
                    var person                   = possiblePersons.First();
                    var personAliasIds           = person.Aliases.Select(pa => pa.Id).ToList();
                    var signatureDocumentService = new SignatureDocumentService(rockContext);
                    var validSignatureDocuments  = signatureDocumentService.Queryable().Where(sd =>
                                                                                              personAliasIds.Contains(sd.AppliesToPersonAliasId.Value) &&
                                                                                              sd.SignatureDocumentTemplateId == RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.Id &&
                                                                                              sd.Status == SignatureDocumentStatus.Signed
                                                                                              ).OrderBy(sd => sd.CreatedDateTime);
                    if (validSignatureDocuments.Any())
                    {
                        registrant.SignatureDocumentId       = validSignatureDocuments.First().Id;
                        registrant.SignatureDocumentKey      = validSignatureDocuments.First().DocumentKey;
                        registrant.SignatureDocumentLastSent = validSignatureDocuments.First().LastInviteDate;
                        return(true);
                    }
                }
            }


            nbDigitalSignature.Heading = "Signature Required";
            nbDigitalSignature.Text    = string.Format(
                "This {0} requires that you sign a {1} for each registrant, please click the button below and then follow the prompts to digitally sign this document for {2}.  This will open the signing request within our digital signature provider's website.  When you have successfully signed this document, you will be returned to this page which will automatically proceed to the next step of your registration.",
                RegistrationInstanceState.RegistrationTemplate.RegistrationTerm,
                RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.Name,
                firstName);

            var    errors     = new List <string>();
            string inviteLink = DigitalSignatureComponent.GetInviteLink(RegistrationInstanceState.RegistrationTemplate.RequiredSignatureDocumentTemplate.ProviderTemplateKey, out errors);

            if (!string.IsNullOrWhiteSpace(inviteLink))
            {
                var key = Guid.NewGuid();

                string returnUrl = GlobalAttributesCache.Get().GetValue("PublicApplicationRoot").EnsureTrailingForwardslash() +
                                   ResolveUrl(Request.RawUrl).TrimStart('/');

                // We need to make sure if someone click's back that we don't end up with extra parameters
                var uri = new Uri(returnUrl);
                var qs  = HttpUtility.ParseQueryString(uri.Query);
                qs.Set("registration_key", key.ToString());
                qs.Remove("document_id");
                // Put the URL back together again
                var uriBuilder = new UriBuilder(uri);
                uriBuilder.Query = qs.ToString();

                // Snap off a copy of the viewstate and set the button URL
                hfRegistrantKey.Value = key.ToString();

                hfRequiredDocumentLinkUrl.Value = string.Format("{0}?redirect_uri={1}", inviteLink, uriBuilder.ToString().UrlEncode());
                btnRequiredDocument.Visible     = true;
            }
            else
            {
                nbDigitalSignature.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger;
                nbDigitalSignature.Heading             = "Digital Signature Error";
                nbDigitalSignature.Text = string.Format("An Error Occurred Trying to Get Document Link... <ul><li>{0}</li></ul>", errors.AsDelimited("</li><li>"));
            }
            return(false);
        }