Merge branch 'Kerl/login' into 'master'

Ajoute une redirection après login

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.

See merge request !70
This commit is contained in:
Martin Pepin 2016-07-28 02:01:46 +02:00
commit 1db9c78972
3 changed files with 17 additions and 5 deletions

View file

@ -10,7 +10,8 @@
<p class="error">Identifiants incorrects.</p>
{% endif %}
<form method="post" action="{% url 'gestioncof.views.login_ext' %}">
<form method="post"
action="{% url 'gestioncof.views.login_ext' %}?next={{ next|urlencode }}">
{% csrf_token %}
<table>
<tr>

View file

@ -3,10 +3,12 @@
{% block content %}
<div id="main-login-container">
<div id="main-login">
<a id="login_clipper" href="{% url 'django_cas_ng.views.login' %}">
<a id="login_clipper"
href="{% url 'django_cas_ng.views.login' %}?next={{ next|urlencode }}">
Compte clipper
</a>
<a id="login_outsider" href="{% url 'gestioncof.views.login_ext' %}">
<a id="login_outsider"
href="{% url 'gestioncof.views.login_ext' %}?next={{ next|urlencode }}">
Extérieur
</a>
<div class="spacer"></div>

View file

@ -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