Commit a01b4455 authored by Luuk Scholten's avatar Luuk Scholten
Browse files

Merge branch '367-kan-geen-gebruiker-toevoegen' into 'master'

Prevent incorrect validation errors when creating new users

Closes #367

See merge request !426
parents 280153a4 7b24e550
......@@ -28,6 +28,11 @@ class UserCreationForm(BaseUserCreationForm):
# Don't forget to edit the formset in admin.py!
# This is a stupid quirk of the user admin.
# shadow the password fields to prevent validation errors,
# since we generate the passwords dynamically.
password1 = None
password2 = None
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in ('email', 'first_name', 'last_name'):
......@@ -47,6 +52,8 @@ class UserCreationForm(BaseUserCreationForm):
def save(self, commit=True):
password = User.objects.make_random_password(length=15)
# pass the password on as if it was filled in, so that save() works
self.cleaned_data['password1'] = password
user = super().save(commit=False)
user.set_password(password)
if commit:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment