Пример #1
0
    /// <summary>
    /// Check that subscription hash is valid and subscription didn't expire
    /// </summary>
    /// <param name="subscriptionHash">Subscription hash to check</param>
    /// <param name="requestTime">Date time of subscription request</param>
    /// <param name="checkOnly">Indicates if only check will be performed</param>
    private void CheckAndSubscribe(string subscriptionHash, string requestTime, bool checkOnly)
    {
        // Get date and time
        DateTime datetime = DateTimeHelper.ZERO_TIME;

        // Get date and time
        if (!string.IsNullOrEmpty(requestTime))
        {
            try
            {
                datetime = DateTimeUrlFormatter.Parse(requestTime);
            }
            catch
            {
                DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_failed")));
                return;
            }
        }

        // Initialize opt-in result
        OptInApprovalResultEnum result = OptInApprovalResultEnum.NotFound;

        // Check only data consistency
        if (checkOnly)
        {
            if (SubscriptionObject != null)
            {
                // Validate hash
                result = ForumSubscriptionInfoProvider.ValidateHash(SubscriptionObject, subscriptionHash, SiteContext.CurrentSiteName, datetime);
                if ((result == OptInApprovalResultEnum.Success) && (SubscriptionObject.SubscriptionApproved))
                {
                    result = OptInApprovalResultEnum.NotFound;
                }
            }
        }
        else
        {
            // Try to approve subscription
            result = ForumSubscriptionInfoProvider.ApproveSubscription(SubscriptionObject, mSubscriptionHash, false, SiteContext.CurrentSiteName, datetime);
        }

        // Process result
        switch (result)
        {
        // Approving subscription was successful
        case OptInApprovalResultEnum.Success:
            if (!checkOnly)
            {
                ShowInfo(DataHelper.GetNotEmpty(SuccessfulConfirmationText, GetString("general.subscription_approval")));
                ForumSubscriptionInfoProvider.LogSubscriptionActivity(SubscriptionObject, null, QueryHelper.GetInteger("cid", 0), QueryHelper.GetInteger("siteid", 0), QueryHelper.GetText("url", ""), QueryHelper.GetInteger("docid", 0), QueryHelper.GetText("camp", ""), true);
                Service.Resolve <ICurrentContactMergeService>().UpdateCurrentContactEmail(SubscriptionObject.SubscriptionEmail, MembershipContext.AuthenticatedUser);
            }
            break;

        // Subscription was already approved
        case OptInApprovalResultEnum.Failed:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_failed")));
            break;

        case OptInApprovalResultEnum.TimeExceeded:
            ForumSubscriptionInfoProvider.DeleteForumSubscriptionInfo(SubscriptionObject);
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_timeexceeded")));
            break;

        // Subscription not found
        default:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_invalid")));
            break;
        }
    }
Пример #2
0
    /// <summary>
    /// Check that subscription hash is valid and subscription didn't expire
    /// </summary>
    /// <param name="subscriptionHash">Subscription hash to check</param>
    /// <param name="requestTime">Date time of subscription request</param>
    /// <param name="checkOnly">Indicates if only check will be performed</param>
    private void CheckAndSubscribe(string subscriptionHash, string requestTime, bool checkOnly)
    {
        // Get date and time
        DateTime datetime = DateTimeHelper.ZERO_TIME;

        // Get date and time
        if (!string.IsNullOrEmpty(requestTime))
        {
            try
            {
                datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null);
            }
            catch
            {
                DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_failed")));
                return;
            }
        }

        // Initialize opt-in result
        OptInApprovalResultEnum result = OptInApprovalResultEnum.NotFound;

        // Check only data consistency
        if (checkOnly)
        {
            if (SubscriptionObject != null)
            {
                // Validate hash
                result = ForumSubscriptionInfoProvider.ValidateHash(SubscriptionObject, subscriptionHash, SiteContext.CurrentSiteName, datetime);
                if ((result == OptInApprovalResultEnum.Success) && (SubscriptionObject.SubscriptionApproved))
                {
                    result = OptInApprovalResultEnum.NotFound;
                }
            }
        }
        else
        {
            // Try to approve subscription
            result = ForumSubscriptionInfoProvider.ApproveSubscription(SubscriptionObject, mSubscriptionHash, false, SiteContext.CurrentSiteName, datetime);
        }

        // Process result
        switch (result)
        {
        // Approving subscription was successful
        case OptInApprovalResultEnum.Success:
            if (!checkOnly)
            {
                ShowInfo(DataHelper.GetNotEmpty(SuccessfulConfirmationText, GetString("general.subscription_approval")));
                ForumSubscriptionInfoProvider.LogSubscriptionActivity(SubscriptionObject, null, QueryHelper.GetInteger("cid", 0), QueryHelper.GetInteger("siteid", 0), QueryHelper.GetText("url", ""), QueryHelper.GetInteger("docid", 0), QueryHelper.GetText("camp", ""), PredefinedActivityType.SUBSCRIPTION_FORUM_POST, true);
            }
            break;

        // Subscription was already approved
        case OptInApprovalResultEnum.Failed:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_failed")));
            break;

        case OptInApprovalResultEnum.TimeExceeded:
            ForumSubscriptionInfoProvider.DeleteForumSubscriptionInfo(SubscriptionObject);
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_timeexceeded")));
            break;

        // Subscription not found
        default:
        case OptInApprovalResultEnum.NotFound:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_invalid")));
            break;
        }
    }
    /// <summary>
    /// Check that subscription hash is valid and subscription didn't expire
    /// </summary>
    /// <param name="subGuid">Subscription GUID for subscriptions without</param>
    /// <param name="subscriptionHash">Subscription hash to check</param>
    /// <param name="requestTime">Date time of subscription request</param>
    /// <param name="checkOnly">Indicates if only check will be performed</param>
    private void CheckAndUnsubscribe(Guid subGuid, string subscriptionHash, string requestTime, bool checkOnly)
    {
        OptInApprovalResultEnum result = OptInApprovalResultEnum.NotFound;

        // Get date and time
        DateTime datetime = DateTimeHelper.ZERO_TIME;

        if (!string.IsNullOrEmpty(requestTime))
        {
            try
            {
                datetime = DateTimeUrlFormatter.Parse(requestTime);
            }
            catch
            {
                DisplayError(GetString("general.unsubscription_unsuccessful"));

                return;
            }
        }

        if (subGuid != Guid.Empty)
        {
            if (SubscriptionObject != null)
            {
                if (!checkOnly)
                {
                    ForumSubscriptionInfoProvider.DeleteForumSubscriptionInfo(SubscriptionObject);
                }
                result = OptInApprovalResultEnum.Success;
            }
        }
        // Check if subscription approval hash is supplied
        else if (!string.IsNullOrEmpty(subscriptionHash))
        {
            result = checkOnly
                ? ForumSubscriptionInfoProvider.ValidateHash(SubscriptionObject, subscriptionHash, SiteContext.CurrentSiteName, datetime)
                : ForumSubscriptionInfoProvider.Unsubscribe(subscriptionHash, true, SiteContext.CurrentSiteName, datetime);
        }

        switch (result)
        {
        // Approving subscription was successful
        case OptInApprovalResultEnum.Success:
            if (!checkOnly)
            {
                ShowInfo(DataHelper.GetNotEmpty(SuccessfulUnsubscriptionText, GetString("Unsubscribe.Unsubscribed")));
            }
            break;

        // Subscription was already approved
        case OptInApprovalResultEnum.Failed:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnsubscriptionText, GetString("general.unsubscription_unsuccessful")));
            break;

        case OptInApprovalResultEnum.TimeExceeded:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnsubscriptionText, GetString("general.unsubscription_timeexceeded")));
            break;

        // Subscription not found
        default:
            DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnsubscriptionText, GetString("general.unsubscription_NotSubscribed")));
            break;
        }
    }