From 066070128711ff7511dc866c680b25b7914c6088 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Mon, 10 Jun 2024 16:28:31 +0200 Subject: [PATCH] createsuperuser and how it relates to email-based addresses: document chaning actual createsuperuser behavior is usually done using the USERNAME_FIELD but that field has other repurcussions (that we don't want) too --- docs/howto/deployment/single-server.md | 3 ++- users/forms.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/howto/deployment/single-server.md b/docs/howto/deployment/single-server.md index 3a16f0d..68d5f48 100644 --- a/docs/howto/deployment/single-server.md +++ b/docs/howto/deployment/single-server.md @@ -146,7 +146,8 @@ ls *.sqlite3 You can create a superuser account to access the Bugsink admin interface. -Run the following command and follow the prompts: +Run the following command and follow the prompts (to stay consistent with usernames in the rest of the system, you may +want to use your email-address as a username): ```bash bugsink-manage createsuperuser diff --git a/users/forms.py b/users/forms.py index 9f9d1a3..ee6442d 100644 --- a/users/forms.py +++ b/users/forms.py @@ -21,6 +21,11 @@ UserModel = get_user_model() class UserCreationForm(BaseUserCreationForm): + # Our UserCreationForm is the place where the "use email for usernames" logic is implemented. + # We could instead push such logic in the model, and do it more thoroughly (i.e. remove either field, and point the + # USERNAME_FIELD to the other). But I'm not sure that this is the most future-proof way forward. In particular, + # external systems (AD, OAuth, etc.) may have 2 fields rather than 1. + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['username'].validators = [EmailValidator()]