Skip to content

Commit

Permalink
Merge 1cb1472 into cf03f6d
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Sep 1, 2018
2 parents cf03f6d + 1cb1472 commit 676da35
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions misago/users/management/commands/createsuperuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from getpass import getpass

from django.contrib.auth import get_user_model
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand
from django.db import DEFAULT_DB_ALIAS, IntegrityError
Expand Down Expand Up @@ -47,6 +46,7 @@ def add_arguments(self, parser):
)
parser.add_argument(
'--noinput',
'--no-input',
action='store_false',
dest='interactive',
default=True,
Expand Down Expand Up @@ -84,24 +84,21 @@ def handle(self, *args, **options):
username = username.strip()
validate_username(username)
except ValidationError as e:
self.stderr.write(e.messages[0])
self.stderr.write(u'\n'.join(e.messages))
username = None

if email is not None:
try:
email = email.strip()
validate_email(email)
except ValidationError as e:
self.stderr.write(e.messages[0])
self.stderr.write(u'\n'.join(e.messages))
email = None

if password is not None:
try:
password = password.strip()
validate_password(password)
except ValidationError as e:
self.stderr.write(e.messages[0])
password = None
password = password.strip()
if password == '':
self.stderr.write("Error: Blank passwords aren't allowed.")

if not interactive:
if username and email and password:
Expand All @@ -122,29 +119,23 @@ def handle(self, *args, **options):
validate_username(raw_value)
username = raw_value
except ValidationError as e:
self.stderr.write(e.messages[0])
self.stderr.write(u'\n'.join(e.messages))

while not email:
try:
raw_value = input("Enter E-mail address: ").strip()
raw_value = input("Enter e-mail address: ").strip()
validate_email(raw_value)
email = raw_value
except ValidationError as e:
self.stderr.write(e.messages[0])
self.stderr.write(u'\n'.join(e.messages))

while not password:
try:
raw_value = getpass("Enter password: ").strip()
validate_password(
raw_value, user=UserModel(username=username, email=email)
)

repeat_raw_value = getpass("Repeat password: ").strip()
if raw_value != repeat_raw_value:
raise ValidationError("Entered passwords are different.")
password = raw_value
except ValidationError as e:
self.stderr.write(e.messages[0])
password = getpass("Enter password: ")
password2 = getpass("Repeat password")
if password != password2:
self.stderr.write("Error: Your passwords didn't match.")
if password.strip() == '':
self.stderr.write("Error: Blank passwords aren't allowed.")

# Call User manager's create_superuser using our wrapper
self.create_superuser(username, email, password, verbosity)
Expand Down

0 comments on commit 676da35

Please sign in to comment.