-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_local.py
35 lines (30 loc) · 1.13 KB
/
auth_local.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
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
import configurable
class ConfigurableUserBackend(ModelBackend):
"""
Authenticates against configurable.UserModel
"""
supports_object_permissions = False
supports_anonymous_user = True
supports_inactive_user = True
# TODO: Model, login attribute name and password attribute name should be
# configurable.
def authenticate(self, username=None, password=None):
try:
user = configurable.UserModel.objects.get(username=username)
except configurable.UserModel.DoesNotExist:
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
return None
if user.check_password(password):
return user
def get_user(self, user_id):
try:
return configurable.UserModel.objects.get(pk=user_id)
except configurable.UserModel.DoesNotExist:
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None