mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
增加 initadmin 命令
This commit is contained in:
parent
1b25092cb4
commit
991a96ddb7
1
utils/management/__init__.py
Normal file
1
utils/management/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# coding=utf-8
|
1
utils/management/commands/__init__.py
Normal file
1
utils/management/commands/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# coding=utf-8
|
16
utils/management/commands/initadmin.py
Normal file
16
utils/management/commands/initadmin.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user