mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
959 B
35 lines
959 B
6 years ago
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
|
||
|
from django.contrib.auth import get_user_model
|
||
|
from radiusauth.backends import RADIUSBackend, RADIUSRealmBackend
|
||
|
from django.conf import settings
|
||
|
|
||
|
User = get_user_model()
|
||
|
|
||
|
|
||
|
class CreateUserMixin:
|
||
|
def get_django_user(self, username, password=None):
|
||
|
if isinstance(username, bytes):
|
||
|
username = username.decode()
|
||
|
try:
|
||
|
user = User.objects.get(username=username)
|
||
|
except User.DoesNotExist:
|
||
|
if '@' in username:
|
||
|
email = username
|
||
|
else:
|
||
|
email_suffix = settings.EMAIL_SUFFIX
|
||
|
email = '{}@{}'.format(username, email_suffix)
|
||
|
user = User(username=username, name=username, email=email)
|
||
|
user.source = user.SOURCE_RADIUS
|
||
|
user.save()
|
||
|
return user
|
||
|
|
||
|
|
||
|
class RadiusBackend(CreateUserMixin, RADIUSBackend):
|
||
|
pass
|
||
|
|
||
|
|
||
|
class RadiusRealmBackend(CreateUserMixin, RADIUSRealmBackend):
|
||
|
pass
|