feat(main): main
This commit is contained in:
0
core/scripts/__init__.py
Normal file
0
core/scripts/__init__.py
Normal file
41
core/scripts/make_user.py
Normal file
41
core/scripts/make_user.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
from getpass import getpass
|
||||
|
||||
def main():
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pytv.settings")
|
||||
django.setup()
|
||||
|
||||
from core.models import AppUser
|
||||
|
||||
print("--- Create PYTV User ---")
|
||||
try:
|
||||
username = input("Username: ").strip()
|
||||
if not username:
|
||||
print("Username is required!")
|
||||
sys.exit(1)
|
||||
|
||||
email = input("Email: ").strip()
|
||||
password = getpass("Password: ")
|
||||
|
||||
is_admin_str = input("Is Admin? (y/N): ").strip().lower()
|
||||
is_admin = is_admin_str in ['y', 'yes']
|
||||
|
||||
if AppUser.objects.filter(username=username).exists():
|
||||
print(f"User '{username}' already exists!")
|
||||
sys.exit(1)
|
||||
|
||||
if is_admin:
|
||||
AppUser.objects.create_superuser(username=username, email=email, password=password)
|
||||
print(f"Superuser '{username}' created successfully!")
|
||||
else:
|
||||
AppUser.objects.create_user(username=username, email=email, password=password)
|
||||
print(f"User '{username}' created successfully!")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nOperation cancelled.")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user