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)
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()
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()