From 261d65f8b3d4a469224c1815dd7d13823e53db02 Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Thu, 4 Feb 2021 18:49:00 +0100 Subject: [PATCH] (Hopefully) Fix user creation --- myauth/ldap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/myauth/ldap.py b/myauth/ldap.py index 97a2cc3..273834e 100644 --- a/myauth/ldap.py +++ b/myauth/ldap.py @@ -3,10 +3,12 @@ import logging from django.utils import timezone from django.conf import settings from django.core.exceptions import PermissionDenied +from django.contrib.auth import get_user_model from rest_framework.permissions import BasePermission import ldap +User = get_user_model() def ldap_setting(name, default): """Wrapper around django.conf.settings""" @@ -83,7 +85,6 @@ class LDAPUserExists(BasePermission): def has_permission(self, request, view): return LDAPConnection.get_instance().has_user(request.user.username) - def create_user(*args, **kwargs): """ 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"]): raise PermissionDenied("User not in the LDAP directory.") + _ = kwargs.pop("view") return User.objects.create_user(*args, **kwargs)