forked from voy/django-socialregistration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
45 lines (38 loc) · 1.29 KB
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from socialregistration.models import (FacebookProfile, TwitterProfile, OpenIDProfile)
class Auth(object):
supports_anonymous_user = False
supports_object_permissions = False
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
class FacebookAuth(Auth):
def authenticate(self, uid=None):
try:
return FacebookProfile.objects.get(
uid=uid,
site=Site.objects.get_current()
).user
except FacebookProfile.DoesNotExist:
return None
class TwitterAuth(Auth):
def authenticate(self, twitter_id=None):
try:
return TwitterProfile.objects.get(
twitter_id=twitter_id,
site=Site.objects.get_current()
).user
except TwitterProfile.DoesNotExist:
return None
class OpenIDAuth(Auth):
def authenticate(self, identity=None):
try:
return OpenIDProfile.objects.get(
identity=identity,
site=Site.objects.get_current()
).user
except OpenIDProfile.DoesNotExist:
return None