Browse Source

Removing twitter stuff for now

David Leonard 10 years ago
parent
commit
b40cc535a2
2 changed files with 0 additions and 82 deletions
  1. 0 3
      hackathon_starter/hackathon/urls.py
  2. 0 79
      hackathon_starter/hackathon/views.py

+ 0 - 3
hackathon_starter/hackathon/urls.py

@@ -13,7 +13,4 @@ urlpatterns = patterns('',
     url(r'^github/$', views.github, name='github'),
     url(r'^github/$', views.github, name='github'),
     url(r'^tumblr/$', views.tumblr, name='tumblr'),
     url(r'^tumblr/$', views.tumblr, name='tumblr'),
     url(r'^linkedin/$', views.linkedin, name='linkedin'),
     url(r'^linkedin/$', views.linkedin, name='linkedin'),
-    url(r'^twitter_login/?$', views.twitter_login),
-    url(r'^twitter_logout/?$', views.twitter_logout),
-    url(r'^twitter_login/authenticated/?$', views.twitter_authenticated),
 )
 )

+ 0 - 79
hackathon_starter/hackathon/views.py

@@ -6,9 +6,6 @@ from django.template import RequestContext, loader
 from django.contrib.auth import authenticate, login
 from django.contrib.auth import authenticate, login
 from django.http import HttpResponse, HttpResponseRedirect
 from django.http import HttpResponse, HttpResponseRedirect
 from django.conf import settings
 from django.conf import settings
-from django.shortcuts import render_to_response
-from django.http import HttpResponseRedirect
-from django.conf import settings
 from django.contrib.auth import authenticate, login, logout
 from django.contrib.auth import authenticate, login, logout
 from django.contrib.auth.models import User
 from django.contrib.auth.models import User
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.decorators import login_required
@@ -20,86 +17,10 @@ from scripts.tumblr import *
 
 
 # Python
 # Python
 import oauth2 as oauth
 import oauth2 as oauth
-import cgi
 
 
-# Models
-from hackathon.models import Profile
 
 
 getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET)
 getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET)
 
 
-consumer = oauth.Consumer(settings.TWITTER_TOKEN, settings.TWITTER_SECRET)
-client = oauth.Client(consumer)
-
-request_token_url = 'https://twitter.com/oauth/request_token'
-access_token_url = 'https://twitter.com/oauth/access_token'
-authenticate_url = 'http://twitter.com/oauth/authenticate'
-
-def twitter_login(request):
-    # Step 1. Get a request token from Twitter.
-    resp, content = client.request(request_token_url, "GET")
-    if resp['status'] != '200':
-        raise Exception("Invalid response from Twitter.")
-
-    # Step 2. Store the request token in a session for later use.
-    request.session['request_token'] = dict(cgi.parse_qsl(content))
-
-    # Step 3. Redirect the user to the authentication URL.
-    url = "%s?oauth_token=%s" % (authenticate_url,
-        request.session['request_token']['oauth_token'])
-
-    return HttpResponseRedirect(url)
-
-@login_required
-def twitter_logout(request):
-    # Log a user out using Django's logout function and redirect them
-    # back to the homepage.
-    logout(request)
-    return HttpResponseRedirect('/')
-
-def twitter_authenticated(request):
-    # Step 1. Use the request token in the session to build a new client.
-    token = oauth.Token(request.session['request_token']['oauth_token'],
-        request.session['request_token']['oauth_token_secret'])
-    client = oauth.Client(consumer, token)
-
-    # Step 2. Request the authorized access token from Twitter.
-    resp, content = client.request(access_token_url, "GET")
-    if resp['status'] != '200':
-        print content
-        raise Exception("Invalid response from Twitter.")
-    access_token = dict(cgi.parse_qsl(content))
-
-    # Step 3. Lookup the user or create them if they don't exist.
-    try:
-        user = User.objects.get(username=access_token['screen_name'])
-        print user
-    except User.DoesNotExist:
-        # When creating the user I just use their screen_name@twitter.com
-        # for their email and the oauth_token_secret for their password.
-        # These two things will likely never be used. Alternatively, you 
-        # can prompt them for their email here. Either way, the password 
-        # should never be used.
-        user = User.objects.create_user(access_token['screen_name'],
-            '%s@twitter.com' % access_token['screen_name'],
-            access_token['oauth_token_secret'])
-        print user
-
-        # Save our permanent token and secret for later.
-        profile = Profile()
-        profile.user = user
-        profile.oauth_token = access_token['oauth_token']
-        profile.oauth_secret = access_token['oauth_token_secret']
-        profile.save()
-
-    # Authenticate the user and log them in using Django's pre-built 
-    # functions for these things.
-    user = authenticate(username=access_token['screen_name'],
-        password=access_token['oauth_token_secret'])
-    login(request, user)
-
-    return HttpResponseRedirect('/')
-
-
 def index(request):
 def index(request):
     context = {'hello': 'world'}
     context = {'hello': 'world'}
     return render(request, 'hackathon/index.html', context)
     return render(request, 'hackathon/index.html', context)