Beispiel #1
0
    def test_affiliates_email_validation(self):
        """
        The affiliates_email field is only valid if an Affiliates user exists
        with the specified email address.
        """
        form = FacebookAccountLinkForm({'affiliates_email': '*****@*****.**'})
        eq_(form.is_valid(), False)

        user = UserFactory.create()
        form = FacebookAccountLinkForm({'affiliates_email': user.email})
        eq_(form.is_valid(), True)
Beispiel #2
0
def app_context(request):
    """
    Adds context data that is shared across the Facebook app.
    """
    if not in_facebook_app(request):
        return {}

    ctx = {
        'FACEBOOK_DOWNLOAD_URL': settings.FACEBOOK_DOWNLOAD_URL,
        'FACEBOOK_APP_ID': settings.FACEBOOK_APP_ID,
        'FACEBOOK_CLICK_GOAL': settings.FACEBOOK_CLICK_GOAL
    }

    # Add account link form.
    if not request.user.is_linked:
        ctx['account_link_form'] = FacebookAccountLinkForm()

    if is_logged_in(request):
        # Add newsletter form to en-US
        if request.locale.startswith('en'):
            ctx['newsletter_form'] = NewsletterSubscriptionForm(
                request.user, auto_id='newsletter_%s')

        # Add notifications
        ctx['app_notifications'] = (AppNotification.objects.filter(
            user=request.user))

    return ctx
Beispiel #3
0
def link_accounts(request):
    """
    Link the current user's account with an Affiliates account. Called via AJAX
    by the frontend.
    """
    if not is_logged_in(request):
        # Only logged in users can link accounts.
        return http.HttpResponseForbidden()

    form = FacebookAccountLinkForm(request.POST or None)
    if form.is_valid():
        affiliates_email = form.cleaned_data["affiliates_email"]
        link = FacebookAccountLink.objects.create_link(request.user, affiliates_email)
        if link:
            FacebookAccountLink.objects.send_activation_email(request, link)

    # Tell the user we were successful regardless of outcome in order to avoid
    # revealing valid emails.
    return http.HttpResponse()
Beispiel #4
0
def link_accounts(request):
    """
    Link the current user's account with an Affiliates account. Called via AJAX
    by the frontend.
    """
    if not is_logged_in(request):
        # Only logged in users can link accounts.
        return http.HttpResponseForbidden()

    form = FacebookAccountLinkForm(request.POST or None)
    if form.is_valid():
        affiliates_email = form.cleaned_data['affiliates_email']
        link = FacebookAccountLink.objects.create_link(request.user,
                                                       affiliates_email)
        if link:
            FacebookAccountLink.objects.send_activation_email(request, link)

    # Tell the user we were successful regardless of outcome in order to avoid
    # revealing valid emails.
    return http.HttpResponse()
Beispiel #5
0
    def test_affiliates_email_validation(self):
        """
        The affiliates_email field is only valid if an Affiliates user exists
        with the specified email address.
        """
        form = FacebookAccountLinkForm({'affiliates_email': '*****@*****.**'})
        eq_(form.is_valid(), False)

        user = UserFactory.create()
        form = FacebookAccountLinkForm({'affiliates_email': user.email})
        eq_(form.is_valid(), True)