示例#1
0
def incoming(request, api, campaign_id, content_id):
    campaign = get_object_or_404(models.Campaign, pk=campaign_id)
    properties = campaign.campaignproperties.get()
    fb_app = campaign.client.fb_app

    try:
        signature = oauth.handle_incoming(request, fb_app)
    except oauth.AccessDenied:
        # OAuth denial
        # Record auth fail and redirect to error URL:
        url = "{}?{}".format(
            reverse('targetshare:outgoing', args=[
                fb_app.appid,
                properties.client_error_url
            ]),
            urllib.urlencode({'campaignid': campaign_id}),
        )
        db.bulk_create.delay([
            models.relational.Event(
                visit_id=request.visit.visit_id,
                content=url[:1028],
                event_type='incoming_redirect',
                campaign_id=campaign_id,
                client_content_id=content_id,
            ),
            models.relational.Event(
                visit_id=request.visit.visit_id,
                event_type='auth_fail',
                content='oauth',
                campaign_id=campaign_id,
                client_content_id=content_id,
            ),
        ])
        return redirect(url)

    if signature.is_valid():
        token_task = store_oauth_token.delay(
            signature.code,
            signature.redirect_uri,
            api,
            client_id=campaign.client_id,
            visit_id=request.visit.visit_id,
            campaign_id=campaign_id,
            content_id=content_id,
        )
        request.session[OAUTH_TASK_KEY] = token_task.id

    # Record event and redirect to the campaign faces URL
    # (with inheritance of incoming query string)
    url = utils.faces_url(properties.client_faces_url,
                          campaign,
                          content_id,
                          signature.redirect_query)
    db.delayed_save.delay(
        models.relational.Event(
            visit_id=request.visit.visit_id,
            content=url[:1028],
            event_type='incoming_redirect',
            campaign_id=campaign_id,
            client_content_id=content_id,
        )
    )
    return http.HttpResponseRedirect(url)
示例#2
0
 def test_url_with_querydict_extra(self):
     self.assertEqual(
         faces_url('http://www.demandaction.org/SandovalSB221Share?cake=good', self.campaign, 1, QueryDict('churros=delicious&churros=convenient'), cookies='great'),
         'http://www.demandaction.org/SandovalSB221Share?cake=good&efcmpgslug=N9_DHXOFmaI&cookies=great&churros=delicious&churros=convenient'
     )
示例#3
0
 def test_url_with_multivalue_extra(self):
     self.assertEqual(
         faces_url('http://www.demandaction.org/SandovalSB221Share?cake=good', self.campaign, 1, MultiValueDict({'churros': ['delicious', 'convenient']}), cookies='great'),
         'http://www.demandaction.org/SandovalSB221Share?cake=good&efcmpgslug=N9_DHXOFmaI&cookies=great&churros=delicious&churros=convenient'
     )
示例#4
0
 def test_url_with_extra_query(self):
     self.assertEqual(
         faces_url('http://www.demandaction.org/SandovalSB221Share?cake=good', self.campaign, 1, cookies='great'),
         'http://www.demandaction.org/SandovalSB221Share?cake=good&efcmpgslug=N9_DHXOFmaI&cookies=great'
     )
示例#5
0
 def test_basic_url_with_extra(self):
     self.assertEqual(
         faces_url('http://www.demandaction.org/SandovalSB221Share', self.campaign, 1, cake='good'),
         'http://www.demandaction.org/SandovalSB221Share?cake=good&efcmpgslug=N9_DHXOFmaI'
     )
示例#6
0
 def test_basic_url(self):
     self.assertEqual(
         faces_url('http://www.demandaction.org/SandovalSB221Share', self.campaign, 1),
         'http://www.demandaction.org/SandovalSB221Share?efcmpgslug=N9_DHXOFmaI'
     )