This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def verify(request): | |
| # Twitter will direct with oauth_token and oauth_verifier in the URL | |
| # ?oauth_token=EoSsg1...&oauth_verifier=NB3bvAkb... | |
| # did the user deny the request | |
| if 'denied' in request.GET: | |
| return False | |
| # ensure we have a session state and the state value is the same as what twitter returned | |
| if 'twitter_request_token_key' not in request.session \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import tweepy | |
| from django.conf import settings | |
| from app.lib import RawJsonParser | |
| def get_user_data(request): | |
| data = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tweepy.parsers import Parser | |
| class RawJsonParser(Parser): | |
| def parse(self, method, payload): | |
| return payload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://code.google.com/apis/console/ | |
| GOOGLE_OAUTH2_CLIENT_ID = 'YOUR-APP-ID' | |
| GOOGLE_OAUTH2_CLIENT_SECRET = 'YOUR-APP-SECRET' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib | |
| from django.conf import settings | |
| from django.core.urlresolvers import reverse | |
| from django.core.context_processors import csrf | |
| def get_authorization_url(request): | |
| # URL to where we will redirect to | |
| redirect_url = urllib.quote_plus(settings.SITE_URL + reverse('register_google')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def verify(request): | |
| # Google will direct with state and code in the URL | |
| # ?state=zNHRjuYO...&code=4/zK5F93g2we... | |
| # ensure we have a session state and the state value is the same as what google returned | |
| if 'google_state' not in request.session \ | |
| or 'state' not in request.GET \ | |
| or 'code' not in request.GET \ | |
| or request.session['google_state'] != request.GET['state']: | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib2 | |
| import json | |
| import re | |
| from django.conf import settings | |
| from django.core.urlresolvers import reverse | |
| def get_user_data(request): | |
| data = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| find . -name '*.pyc' -exec rm {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NotFound(Exception): | |
| def __init__(self, template): | |
| # call the base class constructor | |
| Exception.__init__(self, 'Record not found') | |
| # set the template | |
| self.template = template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import render | |
| from app.exceptions.custom import NotFound | |
| class ExceptionMiddleware(object): | |
| def process_exception(self, request, exception): | |
| if type(exception) == NotFound: | |
| return render(request, exception.template) | |
| return None |