mirror of
https://github.com/correl/codereview.git
synced 2024-11-27 19:19:50 +00:00
22 lines
744 B
Python
22 lines
744 B
Python
|
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
|