You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. import getpass
  2. from django.core.management.base import BaseCommand
  3. from hc.accounts.forms import SignupForm
  4. from hc.accounts.views import _make_user
  5. class Command(BaseCommand):
  6. help = """Create a super-user account."""
  7. def handle(self, *args, **options):
  8. email = None
  9. password = None
  10. while not email:
  11. raw = input("Email address:")
  12. form = SignupForm({"identity": raw})
  13. if not form.is_valid():
  14. self.stderr.write("Error: " + " ".join(form.errors["identity"]))
  15. continue
  16. email = form.cleaned_data["identity"]
  17. while not password:
  18. p1 = getpass.getpass()
  19. p2 = getpass.getpass("Password (again):")
  20. if p1.strip() == "":
  21. self.stderr.write("Error: Blank passwords aren't allowed.")
  22. continue
  23. if p1 != p2:
  24. self.stderr.write("Error: Your passwords didn't match.")
  25. continue
  26. password = p1
  27. user = _make_user(email)
  28. user.set_password(password)
  29. user.is_staff = True
  30. user.is_superuser = True
  31. user.save()
  32. return "Superuser created successfully."