From 2c8cbdedff9b723bd481e51d3aea771dd93fee7a Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 20 Oct 2022 12:29:58 +0200 Subject: [PATCH] Login form. --- src/wolnelektury/forms.py | 6 ++- src/wolnelektury/static/2022/more.scss | 12 +++++ .../templates/registration/login.html | 50 +++++++++++++++++++ src/wolnelektury/views.py | 13 ++++- 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/wolnelektury/templates/registration/login.html diff --git a/src/wolnelektury/forms.py b/src/wolnelektury/forms.py index 180406500..f04501f99 100644 --- a/src/wolnelektury/forms.py +++ b/src/wolnelektury/forms.py @@ -2,12 +2,16 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from allauth.socialaccount.forms import SignupForm -from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.forms import AuthenticationForm, UserCreationForm from django.contrib.auth.models import User from newsletter.forms import NewsletterForm +class WLAuthenticationForm(AuthenticationForm): + template_name = '2022/form.html' + + # has to be this order, because otherwise the form is lacking fields class RegistrationForm(UserCreationForm, NewsletterForm): data_processing_part2 = '''\ diff --git a/src/wolnelektury/static/2022/more.scss b/src/wolnelektury/static/2022/more.scss index 89621ce50..06a462734 100644 --- a/src/wolnelektury/static/2022/more.scss +++ b/src/wolnelektury/static/2022/more.scss @@ -273,4 +273,16 @@ form { line-height: 150%; margin-bottom: 30px; } + } + +.socialaccount_providers { + list-style: none; + padding: 0; + + li { + display: inline-block; + margin-right: 10px; + } +} + diff --git a/src/wolnelektury/templates/registration/login.html b/src/wolnelektury/templates/registration/login.html new file mode 100644 index 000000000..691d3db3b --- /dev/null +++ b/src/wolnelektury/templates/registration/login.html @@ -0,0 +1,50 @@ +{% extends "2022/base.html" %} +{% load i18n %} + +{% block content %} +
+ +
+ +
+
+
+
+

Zaloguj się

+
+
+
+
+
+
+
+ {% csrf_token %} + {{ form }} +
+
+ +
+
+ + {% trans "Forgot Password?" %} +
+
+ + {% if USE_OPENID %} +

{% trans "Sign in using:" %}

+ +
    + {% include "socialaccount/snippets/provider_list.html" %} +
+ + {% include "socialaccount/snippets/login_extra.html" %} + {% endif %} + +
+
+
+
+{% endblock %} diff --git a/src/wolnelektury/views.py b/src/wolnelektury/views.py index 1855222ed..593a7ba22 100644 --- a/src/wolnelektury/views.py +++ b/src/wolnelektury/views.py @@ -10,6 +10,7 @@ from django.conf import settings from django.contrib import auth from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import AuthenticationForm +from django.contrib.auth.views import LoginView from django.core.cache import cache from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render @@ -21,7 +22,7 @@ from ajaxable.utils import placeholdized from catalogue.models import Book, Collection, Tag, Fragment from social.utils import get_or_choose_cite -from wolnelektury.forms import RegistrationForm, SocialSignupForm +from wolnelektury.forms import RegistrationForm, SocialSignupForm, WLAuthenticationForm @never_cache @@ -72,6 +73,13 @@ def main_page(request): return render(request, "main_page.html", ctx) +class WLLoginView(LoginView): + form_class = WLAuthenticationForm + + +wl_login_view = WLLoginView.as_view() + + class LoginFormView(AjaxableFormView): form_class = AuthenticationForm template = "auth/login.html" @@ -81,6 +89,9 @@ class LoginFormView(AjaxableFormView): ajax_redirect = True def __call__(self, request): + if request.EXPERIMENTS['layout'].value: + return wl_login_view(request) + if request.user.is_authenticated: return self.redirect_or_refresh( request, '/', -- 2.20.1