From c623950b35733302983549baf6a14c8e5d916810 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 1 Jul 2024 12:19:02 +0200 Subject: [PATCH] add command add user --- user/management/__init__.py | 0 user/management/commands/__init__.py | 0 user/management/commands/add_user.py | 23 +++++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 user/management/__init__.py create mode 100644 user/management/commands/__init__.py create mode 100644 user/management/commands/add_user.py diff --git a/user/management/__init__.py b/user/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user/management/commands/__init__.py b/user/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user/management/commands/add_user.py b/user/management/commands/add_user.py new file mode 100644 index 0000000..5e3222c --- /dev/null +++ b/user/management/commands/add_user.py @@ -0,0 +1,23 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth import get_user_model + + +User = get_user_model() + + +class Command(BaseCommand): + help = "Create a new user" + + def add_arguments(self, parser): + parser.add_argument('email', type=str, help='email') + parser.add_argument('password', type=str, help='password') + + def handle(self, *args, **kwargs): + email = kwargs['email'] + password = kwargs['password'] + self.create_user(email, password) + + def create_user(self, email, password): + u = User.objects.create(email=email, password=password) + u.set_password(password) + u.save()