Add a command to import a user from LDAP

This commit is contained in:
Adam Goldsmith 2021-05-15 13:27:43 -04:00
parent 76ffb649a3
commit e19df73642

View File

@ -0,0 +1,18 @@
from django.core.management.base import BaseCommand
from django_auth_ldap.backend import LDAPBackend
class Command(BaseCommand):
help = 'Import a user from LDAP by username'
def add_arguments(self, parser):
parser.add_argument('username', type=str)
def handle(self, *args, **options):
username = options['username']
user = LDAPBackend().populate_user(username)
if user is None:
raise Exception(f"No user named {username}")
else:
print("Imported user:", user)