users: Add email address field during first boot

- Mostly because administrators won't discover the email address field for the
user later on.

- This field is important to be able to run 'reset password' operation.

Tests:

- In stable and testing containers, run first boot wizard. Enter the email
address during the first boot and see that it was saved as part of user account.
Leave the email address blank and it is possible to proceed. User account show
blank email address.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-03-14 10:55:01 -07:00 committed by Veiko Aasa
parent 9d2a11b874
commit 1b09d01575
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -382,11 +382,16 @@ class UserChangePasswordForm(PasswordConfirmForm, SetPasswordForm):
return user
class FirstBootForm(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
class FirstBootForm(ValidNewUsernameCheckMixin, EmailFieldMixin,
auth.forms.UserCreationForm):
"""User module first boot step: create a new admin user."""
username = USERNAME_FIELD
class Meta(UserCreationForm.Meta):
"""Metadata to control automatic form building."""
fields = ('username', 'email', 'password1')
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)
@ -399,6 +404,8 @@ class FirstBootForm(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
"""Create and log the user in."""
user = super().save(commit=commit)
if commit:
self.save_m2m() # Django 3.x does not call save_m2m()
first_boot.mark_step_done('users_firstboot')
try: