(Hopefully) Fix user creation
This commit is contained in:
parent
0a9ffd1c9b
commit
261d65f8b3
@ -3,10 +3,12 @@ import logging
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
from rest_framework.permissions import BasePermission
|
from rest_framework.permissions import BasePermission
|
||||||
|
|
||||||
import ldap
|
import ldap
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
def ldap_setting(name, default):
|
def ldap_setting(name, default):
|
||||||
"""Wrapper around django.conf.settings"""
|
"""Wrapper around django.conf.settings"""
|
||||||
@ -83,7 +85,6 @@ class LDAPUserExists(BasePermission):
|
|||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
return LDAPConnection.get_instance().has_user(request.user.username)
|
return LDAPConnection.get_instance().has_user(request.user.username)
|
||||||
|
|
||||||
|
|
||||||
def create_user(*args, **kwargs):
|
def create_user(*args, **kwargs):
|
||||||
"""
|
"""
|
||||||
A create_user function which first checks if the user already exists in the
|
A create_user function which first checks if the user already exists in the
|
||||||
@ -91,4 +92,5 @@ def create_user(*args, **kwargs):
|
|||||||
"""
|
"""
|
||||||
if not LDAPConnection.get_instance().has_user(kwargs["username"]):
|
if not LDAPConnection.get_instance().has_user(kwargs["username"]):
|
||||||
raise PermissionDenied("User not in the LDAP directory.")
|
raise PermissionDenied("User not in the LDAP directory.")
|
||||||
|
_ = kwargs.pop("view")
|
||||||
return User.objects.create_user(*args, **kwargs)
|
return User.objects.create_user(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user