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
This commit is contained in:
Kumi 2024-06-23 09:23:17 +02:00
parent e2fddf8052
commit f291deece2
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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}/")