Refactored common 'get' pattern into manager method.
This commit is contained in:
parent
b441a6bbc7
commit
52a02f1110
|
@ -13,9 +13,7 @@ class ModelBackend(object):
|
||||||
def authenticate(self, username=None, password=None):
|
def authenticate(self, username=None, password=None):
|
||||||
try:
|
try:
|
||||||
UserModel = get_user_model()
|
UserModel = get_user_model()
|
||||||
user = UserModel.objects.get(**{
|
user = UserModel.objects.get_by_natural_key(username)
|
||||||
getattr(UserModel, 'USERNAME_FIELD', 'username'): username
|
|
||||||
})
|
|
||||||
if user.check_password(password):
|
if user.check_password(password):
|
||||||
return user
|
return user
|
||||||
except UserModel.DoesNotExist:
|
except UserModel.DoesNotExist:
|
||||||
|
@ -111,9 +109,7 @@ class RemoteUserBackend(ModelBackend):
|
||||||
user = self.configure_user(user)
|
user = self.configure_user(user)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
user = UserModel.objects.get(**{
|
user = UserModel.objects.get_by_natural_key(username)
|
||||||
getattr(UserModel, 'USERNAME_FIELD', 'username'): username
|
|
||||||
})
|
|
||||||
except UserModel.DoesNotExist:
|
except UserModel.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
return user
|
return user
|
||||||
|
|
Loading…
Reference in New Issue