From f291deece2e4f4b8cb88fd9f2675f1ffd0bd6074 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 23 Jun 2024 09:23:17 +0200 Subject: [PATCH] fix(accounts): create user if email doesn't exist Updated the login email view to use get_or_create for retrieving user by email, ensuring a user is created if the email doesn't exist. This prevents errors when attempting to login with an unregistered email, enhancing the user experience and robustness of the login process --- freedoi/accounts/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freedoi/accounts/views.py b/freedoi/accounts/views.py index 434e4b9..c4d85a6 100644 --- a/freedoi/accounts/views.py +++ b/freedoi/accounts/views.py @@ -19,7 +19,7 @@ class SendLoginEmailView(FormView): def form_valid(self, form): email = form.cleaned_data["email"] - user = User.objects.get(email=email) + user, _ = User.objects.get_or_create(email=email) token = default_token_generator.make_token(user) uid = urlsafe_base64_encode(force_bytes(user.pk)) login_url = self.request.build_absolute_uri(f"/accounts/login/{uid}/{token}/")