From 4a1a249bc99681864c521dc32ee30cbef8700f05 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Fri, 15 Jun 2018 10:27:50 +0200 Subject: [PATCH] Print login errors, redirect to / on logout and use the Login/Logout view classes, instead of the deprecated functions --- ivatar/ivataraccount/templates/login.html | 9 +++++++++ ivatar/ivataraccount/urls.py | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ivatar/ivataraccount/templates/login.html b/ivatar/ivataraccount/templates/login.html index b0abae8..061c17d 100644 --- a/ivatar/ivataraccount/templates/login.html +++ b/ivatar/ivataraccount/templates/login.html @@ -7,6 +7,15 @@

{% trans 'Login' %}

+{% if form.errors %} + {% for error in form.non_field_errors %} +
+ {{ error|escape }} +
+ {% endfor %} +{% endif %} + +
{% csrf_token %} diff --git a/ivatar/ivataraccount/urls.py b/ivatar/ivataraccount/urls.py index 785b5d3..afaefdf 100644 --- a/ivatar/ivataraccount/urls.py +++ b/ivatar/ivataraccount/urls.py @@ -2,6 +2,9 @@ from django.urls import path from django.conf.urls import url from django.views.generic import TemplateView +from django.contrib.auth.views import LoginView, LogoutView +from django.contrib.auth.decorators import login_required + from . views import CreateView, PasswordSetView, AddEmailView from . views import RemoveUnconfirmedEmailView, ConfirmEmailView from . views import RemoveConfirmedEmailView, AssignPhotoEmailView @@ -10,19 +13,16 @@ from . views import ImportPhotoView, RawImageView, DeletePhotoView from . views import UploadPhotoView, AssignPhotoOpenIDView from . views import AddOpenIDView, RedirectOpenIDView, ConfirmOpenIDView from . views import CropPhotoView -from django.contrib.auth.views import login, logout -from django.urls import reverse_lazy - -from django.contrib.auth.decorators import login_required # Define URL patterns, self documenting # To see the fancy, colorful evaluation of these use: # ./manager show_urls urlpatterns = [ path('new/', CreateView.as_view(), name='new_account'), - path('login/', login, {'template_name': 'login.html'}, name='login'), + path('login/', LoginView.as_view(template_name='login.html'), + name='login'), path( - 'logout/', logout, {'next_page': reverse_lazy('login')}, + 'logout/', LogoutView.as_view(next_page='/'), name='logout'), path('export/', login_required( TemplateView.as_view(template_name='export.html')