From 87c7c98cefeb3476d77fe9396e6b40866dd71a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Thu, 28 Jul 2016 01:31:50 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20une=20redirection=20apr=C3=A8s=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si un utilisateur est redirigé vers la page de login en demandant une page, il est redirigé vers la page demandée initialement après authentification. --- gestioncof/templates/login.html | 3 ++- gestioncof/templates/login_switch.html | 6 ++++-- gestioncof/views.py | 13 +++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gestioncof/templates/login.html b/gestioncof/templates/login.html index 7e6a6e66..89b68380 100644 --- a/gestioncof/templates/login.html +++ b/gestioncof/templates/login.html @@ -10,7 +10,8 @@

Identifiants incorrects.

{% endif %} -
+ {% csrf_token %} diff --git a/gestioncof/templates/login_switch.html b/gestioncof/templates/login_switch.html index fe816a78..aafbf54f 100644 --- a/gestioncof/templates/login_switch.html +++ b/gestioncof/templates/login_switch.html @@ -3,10 +3,12 @@ {% block content %}
- + Compte clipper - + Extérieur
diff --git a/gestioncof/views.py b/gestioncof/views.py index e2f59d44..2d5f0487 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -43,7 +43,10 @@ def home(request): def login(request): if request.user.is_authenticated(): return redirect("gestioncof.views.home") - return render(request, "login_switch.html", {}) + context = {} + if request.method == "GET" and 'next' in request.GET: + context['next'] = request.GET['next'] + return render(request, "login_switch.html", context) def login_ext(request): @@ -60,7 +63,13 @@ def login_ext(request): {"error_type": "no_password"}) except User.DoesNotExist: pass - return django_login_view(request, template_name='login.html') + context = {} + if request.method == "GET" and 'next' in request.GET: + context['next'] = request.GET['next'] + if request.method == "POST" and 'next' in request.POST: + context['next'] = request.POST['next'] + return django_login_view(request, template_name='login.html', + extra_context=context) @login_required