SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.conf import settings
  2. from django.contrib.auth.models import User
  3. from better_facebook.models import FacebookUser
  4.  
  5. # Get the name of the AUTH profile so that we can check if the user
  6. # has a relationship with facebook. Is there a neater way of doing this?
  7. _lowercase_profile_name = settings.AUTH_PROFILE_MODULE.split(".")[1].lower()
  8. _facebook_relation = '{0}__facebook'.format(_lowercase_profile_name)
  9.  
  10. class FacebookBackend(object):
  11.     """
  12.     Authenticate against a facebook_user object.
  13.     """
  14.     def authenticate(self, facebook_user):
  15.         assert(isinstance(facebook_user, FacebookUser))
  16.         try:
  17.             return User.objects.get(**{_facebook_relation: facebook_user})
  18.         except User.DoesNotExist:
  19.             return None
  20.  
  21.     def get_user(self, user_id):
  22.         try:
  23.             return User.objects.get(pk=user_id)
  24.         except User.DoesNotExist:
  25.             return None
  26.      
  27. from django.conf import settings
  28. from django.contrib.auth import get_user_model
  29. from django.core.exceptions import ObjectDoesNotExist
  30. from better_facebook.models import FacebookUser
  31.  
  32. # Get the name of the AUTH profile so that we can check if the user
  33. # has a relationship with facebook. Is there a neater way of doing this?
  34. _lowercase_profile_name = settings.AUTH_PROFILE_MODULE.split(".")[1].lower()
  35. _facebook_relation = '{0}__facebook'.format(_lowercase_profile_name)
  36.  
  37. class FacebookBackend(object):
  38.     """
  39.     Authenticate against a facebook_user object.
  40.     """
  41.     def authenticate(self, facebook_user):
  42.         assert(isinstance(facebook_user, FacebookUser))
  43.         try:
  44.             UserModel = get_user_model()
  45.             return UserModel.objects.get(**{_facebook_relation: facebook_user})
  46.         except ObjectDoesNotExist:
  47.             return None
  48.  
  49.     def get_user(self, user_id):
  50.         try:
  51.             UserModel = get_user_model()
  52.             return UserModel.objects.get(pk=user_id)
  53.         except ObjectDoesNotExist:
  54.             return None
  55. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top