mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
2to3 apps/oauth/views.py
This commit is contained in:
parent
b3eaa200b9
commit
861f0175d9
1 changed files with 10 additions and 10 deletions
|
@ -1,9 +1,9 @@
|
||||||
import urllib
|
import urllib.request, urllib.parse, urllib.error
|
||||||
import datetime
|
import datetime
|
||||||
import lxml.html
|
import lxml.html
|
||||||
import tweepy
|
import tweepy
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.urlresolvers import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.http import HttpResponseForbidden, HttpResponseRedirect
|
from django.http import HttpResponseForbidden, HttpResponseRedirect
|
||||||
|
@ -45,12 +45,12 @@ def twitter_connect(request):
|
||||||
auth.get_access_token(oauth_verifier)
|
auth.get_access_token(oauth_verifier)
|
||||||
api = tweepy.API(auth)
|
api = tweepy.API(auth)
|
||||||
twitter_user = api.me()
|
twitter_user = api.me()
|
||||||
except (tweepy.TweepError, IOError), e:
|
except (tweepy.TweepError, IOError) as e:
|
||||||
logging.user(request, "~BB~FRFailed Twitter connect: %s" % e)
|
logging.user(request, "~BB~FRFailed Twitter connect: %s" % e)
|
||||||
return dict(error="Twitter has returned an error. Try connecting again.")
|
return dict(error="Twitter has returned an error. Try connecting again.")
|
||||||
|
|
||||||
# Be sure that two people aren't using the same Twitter account.
|
# Be sure that two people aren't using the same Twitter account.
|
||||||
existing_user = MSocialServices.objects.filter(twitter_uid=unicode(twitter_user.id))
|
existing_user = MSocialServices.objects.filter(twitter_uid=str(twitter_user.id))
|
||||||
if existing_user and existing_user[0].user_id != request.user.pk:
|
if existing_user and existing_user[0].user_id != request.user.pk:
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(pk=existing_user[0].user_id)
|
user = User.objects.get(pk=existing_user[0].user_id)
|
||||||
|
@ -62,7 +62,7 @@ def twitter_connect(request):
|
||||||
existing_user.delete()
|
existing_user.delete()
|
||||||
|
|
||||||
social_services = MSocialServices.get_user(request.user.pk)
|
social_services = MSocialServices.get_user(request.user.pk)
|
||||||
social_services.twitter_uid = unicode(twitter_user.id)
|
social_services.twitter_uid = str(twitter_user.id)
|
||||||
social_services.twitter_access_key = auth.access_token
|
social_services.twitter_access_key = auth.access_token
|
||||||
social_services.twitter_access_secret = auth.access_token_secret
|
social_services.twitter_access_secret = auth.access_token_secret
|
||||||
social_services.syncing_twitter = True
|
social_services.syncing_twitter = True
|
||||||
|
@ -99,8 +99,8 @@ def facebook_connect(request):
|
||||||
args["client_secret"] = facebook_secret
|
args["client_secret"] = facebook_secret
|
||||||
args["code"] = verification_code
|
args["code"] = verification_code
|
||||||
uri = "https://graph.facebook.com/oauth/access_token?" + \
|
uri = "https://graph.facebook.com/oauth/access_token?" + \
|
||||||
urllib.urlencode(args)
|
urllib.parse.urlencode(args)
|
||||||
response_text = urllib.urlopen(uri).read()
|
response_text = urllib.request.urlopen(uri).read()
|
||||||
response = json.decode(response_text)
|
response = json.decode(response_text)
|
||||||
|
|
||||||
if "access_token" not in response:
|
if "access_token" not in response:
|
||||||
|
@ -142,7 +142,7 @@ def facebook_connect(request):
|
||||||
else:
|
else:
|
||||||
# Start the OAuth process
|
# Start the OAuth process
|
||||||
logging.user(request, "~BB~FRStarting Facebook connect")
|
logging.user(request, "~BB~FRStarting Facebook connect")
|
||||||
url = "https://www.facebook.com/dialog/oauth?" + urllib.urlencode(args)
|
url = "https://www.facebook.com/dialog/oauth?" + urllib.parse.urlencode(args)
|
||||||
return {'next': url}
|
return {'next': url}
|
||||||
|
|
||||||
@ajax_login_required
|
@ajax_login_required
|
||||||
|
@ -185,7 +185,7 @@ def follow_twitter_account(request):
|
||||||
try:
|
try:
|
||||||
api = social_services.twitter_api()
|
api = social_services.twitter_api()
|
||||||
api.create_friendship(username)
|
api.create_friendship(username)
|
||||||
except tweepy.TweepError, e:
|
except tweepy.TweepError as e:
|
||||||
code = -1
|
code = -1
|
||||||
message = e
|
message = e
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ def unfollow_twitter_account(request):
|
||||||
try:
|
try:
|
||||||
api = social_services.twitter_api()
|
api = social_services.twitter_api()
|
||||||
api.destroy_friendship(username)
|
api.destroy_friendship(username)
|
||||||
except tweepy.TweepError, e:
|
except tweepy.TweepError as e:
|
||||||
code = -1
|
code = -1
|
||||||
message = e
|
message = e
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue