Esempio n. 1
0
    /// <summary>
    /// The Subscribe page must call this function if Request["optin"]!=null to provide the completion of double opt in.
    /// </summary>
    /// <example>if (Request["optin"]!=null) { Models.TextBlock myTextBlock = VerificationLinkClicked(Request["optin"]) }</example>
    /// <param name="optInCode">You need to pass in Request["optin"]</param>
    /// <returns>Returns a Models.TextBlock containing the title and body text to be displayed to the user</returns>
    public static Models.TextBlock VerificationLinkClicked(string optInCode)
    {
        Models.TextBlock textBlock;
        //Web.Write("optinCode: "+Crypto.DecryptID(optInCode));
        //Web.End();
        //var person = Person.LoadID(Crypto.DecryptID(optInCode));
        var person = new ActiveRecord <int>("Person", "PersonID");

        AssertFieldsExist(person);
        bool exists = person.LoadID(Crypto.DecryptID(optInCode));

        if (!exists)
        {
            // not on database, show error
            // get text to display on screen
            textBlock = Models.TextBlock.LoadBySectionCode("Double_OptIn_Error");
            // create if not found
            if (textBlock == null)
            {
                textBlock = new Models.TextBlock {
                    SectionCode      = "Double_OptIn_Error",
                    Title            = "Problem with confirmation link",
                    IsTitleAvailable = true,
                    IsBodyPlainText  = false,
                    BodyTextHtml     = "Sorry, the link you clicked did not work. Your record was not found in our database.<br><br>If you would like to subscribe to our email newsletter, please use the subscribe panel on the right and try the process again."
                };

                textBlock.Save();
            }
        }
        else
        {
            // opt in
            person["SubscribeDate"].ValueObject     = DateTime.Now;
            person["HasValidatedEmail"].ValueObject = true;
            person.Save();

            // get text to display on screen
            textBlock = Models.TextBlock.LoadBySectionCode("Double_OptIn_Confirmed");
            // create if not found
            if (textBlock == null)
            {
                textBlock = new Models.TextBlock {
                    SectionCode      = "Double_OptIn_Confirmed",
                    IsBodyPlainText  = false,
                    IsTitleAvailable = true,
                    Title            = "Subscribe Confirmed",
                    BodyTextHtml     = "Thanks very much for confirming your subscription.<br><br>You are now subscribed to our email newsletter."
                };
                textBlock.Save();
            }
        }
        return(textBlock);
    }