redirecting user after login: to a specific url or to one requested by him
Closes #5574
This commit is contained in:
parent
c8a28de757
commit
d0b100eba8
|
@ -121,6 +121,16 @@ def get_tilesurl():
|
|||
tilesurl = tilesurl.text
|
||||
return tilesurl
|
||||
|
||||
def get_redirect_params():
|
||||
sp = root().find('univnautes/sp')
|
||||
redirect_url = sp.find('redirect_url')
|
||||
if redirect_url is not None:
|
||||
redirect_url = redirect_url.text
|
||||
redirect_delay = sp.find('redirect_delay')
|
||||
if redirect_delay is not None:
|
||||
redirect_delay = redirect_delay.text or 0
|
||||
return redirect_url, redirect_delay
|
||||
|
||||
def get_sp():
|
||||
sp = root().find('univnautes/sp')
|
||||
if sp is None:
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>{% block page-title %}eduspot{% endblock %}</title>
|
||||
{% block meta %}{% endblock %}
|
||||
{% block js %}{% endblock %}
|
||||
{% block css %}{% endblock %}
|
||||
<link rel="stylesheet" type="text/css" media="all" href="{% static "univnautes/univnautes.css" %}" />
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% block meta %}
|
||||
{% if redirect_url %} <meta http-equiv="refresh" content="{{ redirect_delay }}; URL={{ redirect_url }}" />{% endif %}
|
||||
{% endblock %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -28,6 +31,11 @@ erreur lors de l'ouverture de l'accès.
|
|||
avez maintenant accès au réseau.
|
||||
</h2>
|
||||
|
||||
{% if redirect_url %}
|
||||
<p>Vous allez être redirigé vers <a href="{{ redirect_url }}">{{ redirect_url }}</a>{% if redirect_delay %} dans
|
||||
{{ redirect_delay }} seconde(s) {% endif %}</p>
|
||||
{% endif %}
|
||||
|
||||
<p>
|
||||
Après avoir utilisé cet accès, n'oubliez pas de fermer votre navigateur, afin
|
||||
que la session de connexion à votre établissement soit bien clôturée.
|
||||
|
|
|
@ -24,6 +24,7 @@ urlpatterns = patterns('',
|
|||
url(r'^proxymap/(?P<z>[0-9]+)/(?P<x>[0-9]+)/(?P<y>[0-9]+)\.png$', 'sp.views.proxymap'),
|
||||
url(r'^accounts/logout/', 'sp.views.logout', name='logout'),
|
||||
url(r'^accounts/logoutlogin/', 'django.contrib.auth.views.logout_then_login', name='django_logout_then_login'),
|
||||
url(r'^accounts/login/', 'sp.views.login', name='login'),
|
||||
url(r'^accounts/', include('django.contrib.auth.urls')),
|
||||
url(r'^authsaml2/', include('authentic2.authsaml2.urls')),
|
||||
)
|
||||
|
|
|
@ -19,19 +19,36 @@
|
|||
from django.conf import settings
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.views import login as django_login
|
||||
from django.template import Template, Context
|
||||
import urllib2
|
||||
from django.http import HttpResponse
|
||||
from django.utils.http import urlencode
|
||||
from django.shortcuts import redirect
|
||||
import subprocess
|
||||
|
||||
from .pfconfigxml import get_tilesurl
|
||||
|
||||
from .pfconfigxml import get_tilesurl, get_redirect_params
|
||||
|
||||
class Homepage(TemplateView):
|
||||
'''Homepage View, displays a welcome message'''
|
||||
template_name = 'homepage.html'
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super(Homepage, self).get_context_data(*args, **kwargs)
|
||||
url, delay = get_redirect_params()
|
||||
if url == 'next_url':
|
||||
url = urllib2.unquote(self.request.COOKIES.get(url, ''))
|
||||
|
||||
url = Template(url).render(Context(context))
|
||||
context.update({'redirect_url': url,
|
||||
'redirect_delay': delay})
|
||||
return context
|
||||
|
||||
homepage = login_required(Homepage.as_view())
|
||||
|
||||
def login(request):
|
||||
response = django_login(request)
|
||||
response.set_cookie('next_url', request.GET.get('next'), path='/')
|
||||
return response
|
||||
|
||||
def proxymap(request, z, x, y):
|
||||
tiles_url = get_tilesurl() or settings.PROXYMAP_URL
|
||||
|
|
|
@ -65,6 +65,10 @@ $pconfig['defaultidps'] = base64_decode($a_sp['defaultidps']);
|
|||
$pconfig['geolocations'] = base64_decode($a_sp['geolocations']);
|
||||
$pconfig['geoinitialbounds'] = $a_sp['geoinitialbounds'];
|
||||
$pconfig['tilesurl'] = $a_sp['tilesurl'];
|
||||
$pconfig['redirect_url'] = $a_sp['redirect_url'];
|
||||
$pconfig['redirect_delay'] = $a_sp['redirect_delay'];
|
||||
if($pconfig['redirect_url']!='next_url')
|
||||
$pconfig['defined_redirect_url'] = $a_sp['redirect_url'];
|
||||
|
||||
$pgtitle = array(gettext("Services"),gettext("Captive portal"), "SAML 2.0 Service provider");
|
||||
$shortcut_section = "captiveportal";
|
||||
|
@ -92,8 +96,15 @@ if ($_POST) {
|
|||
$a_sp['geolocations'] = base64_encode($pconfig['geolocations']);
|
||||
$a_sp['geoinitialbounds'] = $pconfig['geoinitialbounds'];
|
||||
$a_sp['tilesurl'] = $pconfig['tilesurl'];
|
||||
$a_sp['redirect_url'] = $pconfig['redirect_url'];
|
||||
$a_sp['redirect_delay'] = $pconfig['redirect_delay'];
|
||||
if ($a_sp['redirect_url'] == 'defined_redirect_url')
|
||||
$a_sp['redirect_url'] = $pconfig['defined_redirect_url'];
|
||||
else
|
||||
$pconfig['defined_redirect_url'] = '';
|
||||
/* write config.xml */
|
||||
write_config();
|
||||
if ($a_sp['redirect_url'] != 'defined_redirect_url')
|
||||
|
||||
/* relaunch SP */
|
||||
mwexec_bg("/usr/local/univnautes/sp/rc.sh restart");
|
||||
|
@ -145,6 +156,30 @@ include("head.inc");
|
|||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncell"><?=gettext("After login redirect to"); ?></td>
|
||||
<td width="78%" class="vtable">
|
||||
<table>
|
||||
<tr>
|
||||
<td><input type="radio" name="redirect_url" value="next_url" <?php if($pconfig['redirect_url']=='next_url') echo "checked";?> /> user requested url</td>
|
||||
</tr>
|
||||
<tr><td>or</td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="radio" name="redirect_url" value="defined_redirect_url" <?php if ($pconfig['redirect_url'] && $pconfig['redirect_url']!='next_url') echo "checked";?> />
|
||||
<input type="url" name="defined_redirect_url" value="<?=htmlspecialchars($pconfig['defined_redirect_url']);?>" /> <br />
|
||||
<i><?=gettext("accepts variables in like in Django templates ('{{ varname }}')"); ?></i>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncell"><?=gettext("Redirect delay"); ?></td>
|
||||
<td width="78%" class="vtable">
|
||||
<input type="number" name="redirect_delay" min="0" max="60" value="<?=htmlspecialchars($pconfig['redirect_delay']);?>" /> seconds
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2" class="list" height="12"></td>
|
||||
|
|
Reference in New Issue