Commit 6be5ff7b authored by Sharad Heft's avatar Sharad Heft

Refactor getting of user model in auth backend.

parent 8847bdc6
...@@ -5,15 +5,12 @@ from django.conf import settings ...@@ -5,15 +5,12 @@ from django.conf import settings
from django.db import transaction from django.db import transaction
UserModel = get_user_model()
class TESTOAuth2Backend(ModelBackend): class TESTOAuth2Backend(ModelBackend):
def authenticate(self, id=None, username=None, **profile): def authenticate(self, id=None, username=None, **profile):
if id is None or username is None: if id is None or username is None:
return None return None
user, _ = UserModel.objects.get_or_create( user, _ = get_user_model().objects.get_or_create(
pk=id, pk=id,
username=username username=username
) )
...@@ -24,6 +21,8 @@ class TESTOAuth2Backend(ModelBackend): ...@@ -24,6 +21,8 @@ class TESTOAuth2Backend(ModelBackend):
return user return user
def get_user(self, user_id): def get_user(self, user_id):
UserModel = get_user_model()
try: try:
return UserModel.objects.get(pk=user_id) return UserModel.objects.get(pk=user_id)
except UserModel.DoesNotExist: except UserModel.DoesNotExist:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment