Fix new user creation

This commit is contained in:
2025-05-27 15:01:12 +02:00
parent 95407cc3d7
commit 071b8ca2aa
3 changed files with 10 additions and 6 deletions

View File

@@ -114,10 +114,14 @@ def new_contact():
is_admin=form.is_admin.data,
profile_picture=profile_picture
)
user.set_password('changeme') # Set a default password that must be changed
if form.new_password.data:
user.set_password(form.new_password.data)
else:
flash('Password is required when creating a new user.', 'error')
return render_template('contacts/form.html', form=form, title='New User', total_admins=total_admins)
db.session.add(user)
db.session.commit()
flash('User created successfully! They will need to set their password on first login.', 'success')
flash('User created successfully!', 'success')
return redirect(url_for('contacts.contacts_list'))
return render_template('contacts/form.html', form=form, title='New User', total_admins=total_admins)