Skip to content
Browse files

Removed redundacy. Send users to /twitter/register to create a new ac…

…count OR login
  • Loading branch information...
1 parent c6c0570 commit b89e32b9193146123729417ba9bc01231bfb8226 @crgwbr committed Dec 5, 2010
Showing with 1 addition and 38 deletions.
  1. +1 −2 README.md
  2. +0 −1 urls.py
  3. +0 −35 views.py
View
3 README.md
@@ -21,7 +21,6 @@
Right now there are 5 working functions.
* `/twitter/auth` Send Users here to OAuth with Twitter. They must be logged in with Django's Auth system
-* `/twitter/register` Send anonymous users to create a new account via their Twitter account.
-* `/twitter/login` Send users here to login if they created their account via Twitter Login
+* `/twitter/register` Send anonymous users to create a new account / login via their Twitter account.
* `/twitter/post` Direct POST forms here with update="....." to post updates to twitter. If the user hasn't auth'd yet, they get sent to `/twitter/auth`
* `/twitter/test` A very rough *testing only* update form. Shows some basic user info and enables posting updates
View
1 urls.py
@@ -3,7 +3,6 @@
urlpatterns = patterns('',
url(r'register$', 'django_tweet.views.new_user'),
- url(r'login$', 'django_tweet.views.login_with_twitter'),
url(r'auth$', 'django_tweet.views.authorize'),
url(r'post$', 'django_tweet.views.send_tweet'),
url(r'test$', 'django_tweet.views.tweet_form'),
View
35 views.py
@@ -109,40 +109,6 @@ def new_user(request):
# Redirect User to Twitter
return HttpResponseRedirect(twitter_auth.getAuthorizationURL(temp_credentials, url=AUTHENTICATE_URL))
-def login_with_twitter(request):
- twitter_auth = oauthtwitter.OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
- if request.GET.has_key('oauth_token') or request.GET.has_key('oauth_verifier'):
- # Get temp_credentials from DB
- temp_credentials = {'oauth_token' : request.session['request_token'],
- 'oauth_token_secret' : request.session['request_token_secret']}
- # Get Access Token
- oauth_verifier = str(request.GET['oauth_verifier'])
- token = twitter_auth.getAccessToken(temp_credentials, oauth_verifier)
- access_token = token['oauth_token']
- access_token_secret = token['oauth_token_secret']
- # Verify User Auth
- api = twitter.Api(consumer_key=CONSUMER_KEY,
- consumer_secret=CONSUMER_SECRET,
- access_token_key=access_token,
- access_token_secret=access_token_secret)
- profile = api.VerifyCredentials()
- # Login User
- user = authenticate(username='%s@twitter' % profile.id, password=access_token_secret)
- if user != None:
- login(request, user)
- else:
- raise Exception("Auth Error: %s %s" % ('%s@twitter' % profile.id, access_token_secret))
- # Redirect user
- return HttpResponseRedirect(AUTH_REDIRECT)
- else:
- # Get the temporary credentials for our next few calls
- temp_credentials = twitter_auth.getRequestToken(callback=LOGIN_URL)
- # Save temp_credentials
- request.session['request_token'] = temp_credentials['oauth_token']
- request.session['request_token_secret'] = temp_credentials['oauth_token_secret']
- request.session.modified = True
- # Redirect User to Twitter
- return HttpResponseRedirect(twitter_auth.getAuthorizationURL(temp_credentials, url=AUTHENTICATE_URL))
def send_tweet(request):
if request.method == 'POST' and request.POST.has_key('update'):
@@ -166,7 +132,6 @@ def send_tweet(request):
else:
return HttpResponseRedirect("/")
-
def tweet_form(request):
# Testing only!!!
if request.user.is_authenticated():

0 comments on commit b89e32b

Please sign in to comment.
Something went wrong with that request. Please try again.