add add_user management command
This commit is contained in:
33
procat2/management/commands/add_user.py
Normal file
33
procat2/management/commands/add_user.py
Normal file
@ -0,0 +1,33 @@
|
||||
import re
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Add a procat2 user'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('first_name', type=str)
|
||||
parser.add_argument('last_name', type=str)
|
||||
parser.add_argument('email', type=str)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
fname = options['first_name']
|
||||
lname = options['last_name']
|
||||
email = options['email']
|
||||
email = re.sub('[<>]', '', email)
|
||||
|
||||
uname = lname[:5] + fname[:3]
|
||||
pw = fname[0] + lname[0] + 'visual'
|
||||
|
||||
user = User.objects.create_user(uname, password=pw)
|
||||
user.first_name = fname
|
||||
user.last_name = lname
|
||||
user.email = email
|
||||
user.is_superuser = False
|
||||
user.is_staff = False
|
||||
user.is_active = True
|
||||
user.save()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(f'Added user "{uname}" with password "{pw}" ({email})'))
|
||||
Reference in New Issue
Block a user