Support User model in Django 1.4 that has not a USERNAME_FIELD attribute

Support User model in Django 1.4 that has not a USERNAME_FIELD attribute.
This commit is contained in:
Petros Moisiadis 2015-05-19 19:05:50 +03:00
parent 43b4ae752d
commit c63ea01f4f

View File

@ -85,8 +85,13 @@ class BasicAuthentication(BaseAuthentication):
""" """
Authenticate the userid and password against username and password. Authenticate the userid and password against username and password.
""" """
user_model = get_user_model()
if hasattr(user_model, 'USERNAME_FIELD'):
username_field = user_model.USERNAME_FIELD
else:
username_field = 'username'
credentials = { credentials = {
get_user_model().USERNAME_FIELD: userid, username_field: userid,
'password': password 'password': password
} }
user = authenticate(**credentials) user = authenticate(**credentials)