From: Radek Czajka Date: Tue, 16 Dec 2025 12:41:20 +0000 (+0100) Subject: Allow email login X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/39c7b0bdbe5157ba606196042b2a7309d492eca0 Allow email login --- diff --git a/src/api/views.py b/src/api/views.py index 86275aaf4..aa03f460d 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -3,6 +3,7 @@ # from time import time from allauth.account.forms import ResetPasswordForm +from allauth.account.utils import filter_users_by_email from django.conf import settings from django.contrib.auth import authenticate, login from django.contrib.auth.decorators import login_required @@ -260,14 +261,20 @@ class RegisterView(GenericAPIView): serializer.is_valid(raise_exception=True) d = serializer.validated_data + email = d['email'] + user = User( - username=d['email'], - email=d['email'], - is_active=False + username=email, + email=email, + is_active=True ) user.set_password(d['password']) + if settings.FEATURE_CONFIRM_USER: + user.is_active = False + try: + assert not filter_users_by_email(email) user.save() except: return Response( @@ -277,7 +284,8 @@ class RegisterView(GenericAPIView): status=400 ) - UserConfirmation.request(user) + if settings.FEATURE_CONFIRM_USER: + UserConfirmation.request(user) return Response({}) diff --git a/src/wolnelektury/settings/auth.py b/src/wolnelektury/settings/auth.py index 372490f16..89e520f46 100644 --- a/src/wolnelektury/settings/auth.py +++ b/src/wolnelektury/settings/auth.py @@ -2,10 +2,13 @@ # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # AUTHENTICATION_BACKENDS = [ - 'django.contrib.auth.backends.ModelBackend', - # 'allauth.account.auth_backends.AuthenticationBackend', + #'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', ] ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2 +ACCOUNT_AUTHENTICATION_METHOD = "username_email" +FEATURE_CONFIRM_USER = False + LOGIN_URL = '/uzytkownik/login/' LOGIN_REDIRECT_URL = '/'