mirror of
https://github.com/correl/codereview.git
synced 2024-11-23 19:19:50 +00:00
Added a PAM authentication backend
This commit is contained in:
parent
be02342af5
commit
3aebdc0cd0
2 changed files with 26 additions and 0 deletions
21
dashboard/auth.py
Normal file
21
dashboard/auth.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import pam
|
||||||
|
from django.contrib.auth.models import User, Group
|
||||||
|
|
||||||
|
class PAMBackend:
|
||||||
|
def authenticate(self, username=None, password=None):
|
||||||
|
if pam.authenticate(username, password, service='login'):
|
||||||
|
try:
|
||||||
|
return User.objects.get(username=username)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
# Create new django user
|
||||||
|
user = User(username=username)
|
||||||
|
user.set_password(password)
|
||||||
|
user.save()
|
||||||
|
user.groups.add(Group.objects.get(name='Users'))
|
||||||
|
return user
|
||||||
|
return None
|
||||||
|
def get_user(self, user_id):
|
||||||
|
try:
|
||||||
|
return User.objects.get(pk=user_id)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return None
|
|
@ -78,6 +78,11 @@ MIDDLEWARE_CLASSES = (
|
||||||
ROOT_URLCONF = 'codereview.urls'
|
ROOT_URLCONF = 'codereview.urls'
|
||||||
LOGIN_URL = '/dashboard/login/'
|
LOGIN_URL = '/dashboard/login/'
|
||||||
|
|
||||||
|
AUTHENTICATION_BACKENDS = (
|
||||||
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
|
'codereview.dashboard.auth.PAMBackend',
|
||||||
|
)
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS = (
|
||||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||||
# Always use forward slashes, even on Windows.
|
# Always use forward slashes, even on Windows.
|
||||||
|
|
Loading…
Reference in a new issue