diff --git a/utils/management/__init__.py b/utils/management/__init__.py new file mode 100644 index 0000000..9bad579 --- /dev/null +++ b/utils/management/__init__.py @@ -0,0 +1 @@ +# coding=utf-8 diff --git a/utils/management/commands/__init__.py b/utils/management/commands/__init__.py new file mode 100644 index 0000000..9bad579 --- /dev/null +++ b/utils/management/commands/__init__.py @@ -0,0 +1 @@ +# coding=utf-8 diff --git a/utils/management/commands/initadmin.py b/utils/management/commands/initadmin.py new file mode 100644 index 0000000..94d2c3a --- /dev/null +++ b/utils/management/commands/initadmin.py @@ -0,0 +1,16 @@ +# coding=utf-8 +from django.core.management.base import BaseCommand, CommandError +from account.models import User, SUPER_ADMIN, UserProfile +from utils.shortcuts import rand_str + + +class Command(BaseCommand): + def handle(self, *args, **options): + user = User.objects.create(username="root", real_name="root", email="root@oj.com", admin_type=SUPER_ADMIN) + rand_password = rand_str(length=6) + user.set_password(rand_password) + user.save() + UserProfile.objects.create(user=user) + self.stdout.write("Successfully created super admin user.\nUsername: root\nPassword: %s\n" + "Remember to change password and turn on two factors auth " + "after installation." % rand_password)