On logout display the number of sessions we are logged out from (none, 1, more).

This commit is contained in:
Valentin Samir 2015-12-26 15:37:46 +01:00
parent 5e63f39f9b
commit 10c53a8096
6 changed files with 132 additions and 42 deletions

View file

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: cas_server\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-17 19:21+0100\n"
"PO-Revision-Date: 2015-12-17 19:22+0100\n"
"POT-Creation-Date: 2015-12-26 15:31+0100\n"
"PO-Revision-Date: 2015-12-26 15:34+0100\n"
"Last-Translator: Valentin Samir <valentin.samir@crans.org>\n"
"Language-Team: django <LL@li.org>\n"
"Language: en\n"
@ -92,6 +92,9 @@ msgid ""
"some\\.server\\.com/path/.*$'.As it is a regular expression, special "
"character must be escaped with a '\\'."
msgstr ""
"A regular expression matching services. Will usually looks like '^https://"
"some\\.server\\.com/path/.*$'.As it is a regular expression, special "
"character must be escaped with a '\\'."
#: models.py:198
msgid "user field"
@ -210,7 +213,7 @@ msgstr ""
#: templates/cas_server/logged.html:10
msgid "Log me out from all my sessions"
msgstr ""
msgstr "Log me out from all my sessions"
#: templates/cas_server/logged.html:13
msgid "Logout"
@ -224,54 +227,80 @@ msgstr "Please loggin"
msgid "Login"
msgstr "Login"
#: templates/cas_server/logout.html:6 views.py:123
msgid "Successfully logout"
msgstr ""
"<h3>Logout successful</h3>You have successfully logged out of the Central "
"Authentication Service.</br>For security reasons, exit your web browser."
#: templates/cas_server/warn.html:7
msgid "Connect to the service"
msgstr "Connect to the service"
#: views.py:197
#: views.py:128
msgid ""
"<h3>Logout successful</h3>You have successfully logged out from the Central "
"Authentication Service. For security reasons, exit your web browser."
msgstr ""
"<h3>Logout successful</h3>You have successfully logged out from the Central "
"Authentication Service. For security reasons, exit your web browser."
#: views.py:134
#, python-format
msgid ""
"<h3>Logout successful</h3>You have successfully logged out from %s sessions "
"of the Central Authentication Service. For security reasons, exit your web "
"browser."
msgstr ""
"<h3>Logout successful</h3>You have successfully logged out from %s sessions "
"of the Central Authentication Service. For security reasons, exit your web "
"browser."
#: views.py:141
msgid ""
"<h3>Logout successful</h3>You were already logged out from the Central "
"Authentication Service. For security reasons, exit your web browser."
msgstr ""
"<h3>Logout successful</h3>You were already logged out from the Central "
"Authentication Service. For security reasons, exit your web browser."
#: views.py:230
msgid "Invalid login ticket"
msgstr "Invalid login ticket, please retry to login"
#: views.py:292
#: views.py:325
#, python-format
msgid "Authentication has been required by service %(name)s (%(url)s)"
msgstr "Authentication has been required by service %(name)s (%(url)s)"
#: views.py:326
#: views.py:359
#, python-format
msgid "Service %(url)s non allowed."
msgstr "Service %(url)s non allowed."
#: views.py:333
#: views.py:366
msgid "Username non allowed"
msgstr "Username non allowed"
#: views.py:340
#: views.py:373
msgid "User charateristics non allowed"
msgstr "User charateristics non allowed"
#: views.py:347
#: views.py:380
#, python-format
msgid "The attribut %(field)s is needed to use that service"
msgstr "The attribut %(field)s is needed to use that service"
#: views.py:417
#: views.py:450
#, python-format
msgid "Authentication renewal required by service %(name)s (%(url)s)."
msgstr "Authentication renewal required by service %(name)s (%(url)s)."
#: views.py:424
#: views.py:457
#, python-format
msgid "Authentication required by service %(name)s (%(url)s)."
msgstr "Authentication required by service %(name)s (%(url)s)."
#: views.py:431
#: views.py:464
#, python-format
msgid "Service %s non allowed"
msgstr "Service %s non allowed"
#~ msgid "Successfully logout"
#~ msgstr ""
#~ "<h3>Logout successful</h3>You have successfully logged out of the Central "
#~ "Authentication Service.</br>For security reasons, exit your web browser."

View file

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: cas_server\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-17 19:21+0100\n"
"PO-Revision-Date: 2015-12-17 19:22+0100\n"
"POT-Creation-Date: 2015-12-26 15:31+0100\n"
"PO-Revision-Date: 2015-12-26 15:34+0100\n"
"Last-Translator: Valentin Samir <valentin.samir@crans.org>\n"
"Language-Team: django <LL@li.org>\n"
"Language: fr\n"
@ -236,61 +236,89 @@ msgstr "Merci de se connecter"
msgid "Login"
msgstr "Connexion"
#: templates/cas_server/logout.html:6 views.py:123
msgid "Successfully logout"
msgstr ""
"<h3>Déconnexion réussie</h3>\n"
"Vous vous êtes déconnecté(e) du Service Central d'Authentification.<br/>Pour "
"des raisons de sécurité, veuillez fermer votre navigateur."
#: templates/cas_server/warn.html:7
msgid "Connect to the service"
msgstr "Se connecter au service"
#: views.py:197
#: views.py:128
msgid ""
"<h3>Logout successful</h3>You have successfully logged out from the Central "
"Authentication Service. For security reasons, exit your web browser."
msgstr ""
"<h3>Déconnexion réussie</h3>Vous vous êtes déconnecté(e) du Service Central "
"d'Authentification. Pour des raisons de sécurité, veuillez fermer votre "
"navigateur."
#: views.py:134
#, python-format
msgid ""
"<h3>Logout successful</h3>You have successfully logged out from %s sessions "
"of the Central Authentication Service. For security reasons, exit your web "
"browser."
msgstr ""
"<h3>Déconnexion réussie</h3>Vous vous êtes déconnecté(e) de %s sessions du "
"Service Central d'Authentification. Pour des raisons de sécurité, veuillez "
"fermer votre navigateur."
#: views.py:141
msgid ""
"<h3>Logout successful</h3>You were already logged out from the Central "
"Authentication Service. For security reasons, exit your web browser."
msgstr ""
"<h3>Déconnexion réussie</h3>Vous étiez déjà déconnecté(e) du Service Central "
"d'Authentification. Pour des raisons de sécurité, veuillez fermer votre "
"navigateur."
#: views.py:230
msgid "Invalid login ticket"
msgstr "Ticket de connexion invalide, merci de réessayé de vous connecter"
#: views.py:292
#: views.py:325
#, python-format
msgid "Authentication has been required by service %(name)s (%(url)s)"
msgstr ""
"Une demande d'authentification a été émise pour le service %(name)s "
"(%(url)s)."
#: views.py:326
#: views.py:359
#, python-format
msgid "Service %(url)s non allowed."
msgstr "le service %(url)s n'est pas autorisé."
#: views.py:333
#: views.py:366
msgid "Username non allowed"
msgstr "Nom d'utilisateur non authorisé"
#: views.py:340
#: views.py:373
msgid "User charateristics non allowed"
msgstr "Caractéristique utilisateur non autorisée"
#: views.py:347
#: views.py:380
#, python-format
msgid "The attribut %(field)s is needed to use that service"
msgstr "L'attribut %(field)s est nécessaire pour se connecter à ce service"
#: views.py:417
#: views.py:450
#, python-format
msgid "Authentication renewal required by service %(name)s (%(url)s)."
msgstr "Demande de réauthentification pour le service %(name)s (%(url)s)."
#: views.py:424
#: views.py:457
#, python-format
msgid "Authentication required by service %(name)s (%(url)s)."
msgstr "Authentification requise par le service %(name)s (%(url)s)."
#: views.py:431
#: views.py:464
#, python-format
msgid "Service %s non allowed"
msgstr "Le service %s n'est pas autorisé"
#~ msgid "Successfully logout"
#~ msgstr ""
#~ "<h3>Déconnexion réussie</h3>\n"
#~ "Vous vous êtes déconnecté(e) du Service Central d'Authentification.<br/"
#~ ">Pour des raisons de sécurité, veuillez fermer votre navigateur."
#~ msgid ""
#~ "A ProxyGrantingTicket can be delivered to the service in order to "
#~ "authenticate for the user on a backend service"

View file

@ -3,6 +3,6 @@
{% load staticfiles %}
{% load i18n %}
{% block content %}
<div class="alert alert-success" role="alert">{% trans "Successfully logout" %}</div>
<div class="alert alert-success" role="alert">{{logout_msg|safe}}</div>
{% endblock %}

View file

@ -64,6 +64,7 @@ class LogoutMixin(object):
"""destroy CAS session utils"""
def logout(self, all=False):
"""effectively destroy CAS session"""
session_nb = 0
username = self.request.session.get("username")
if username:
if all:
@ -79,6 +80,7 @@ class LogoutMixin(object):
self.request.session.flush()
user.logout(self.request)
user.delete()
session_nb += 1
except models.User.DoesNotExist:
# if user not found in database, flush the session anyway
self.request.session.flush()
@ -90,7 +92,9 @@ class LogoutMixin(object):
session.flush()
user.logout(self.request)
user.delete()
session_nb += 1
logger.info("User %s logged out" % username)
return session_nb
class LogoutView(View, LogoutMixin):
@ -109,7 +113,7 @@ class LogoutView(View, LogoutMixin):
"""methode called on GET request on this view"""
logger.info("logout requested")
self.init_get(request)
self.logout(self.request.GET.get("all"))
session_nb = self.logout(self.request.GET.get("all"))
# if service is set, redirect to service after logout
if self.service:
list(messages.get_messages(request)) # clean messages before leaving the django app
@ -119,20 +123,49 @@ class LogoutView(View, LogoutMixin):
return HttpResponseRedirect(self.url)
# else redirect to login page
else:
if session_nb == 1:
logout_msg = _(
"<h3>Logout successful</h3>"
"You have successfully logged out from the Central Authentication Service. "
"For security reasons, exit your web browser."
)
elif session_nb > 1:
logout_msg = _(
"<h3>Logout successful</h3>"
"You have successfully logged out from %s sessions of the Central "
"Authentication Service. "
"For security reasons, exit your web browser."
) % session_nb
else:
logout_msg = _(
"<h3>Logout successful</h3>"
"You were already logged out from the Central Authentication Service. "
"For security reasons, exit your web browser."
)
if settings.CAS_REDIRECT_TO_LOGIN_AFTER_LOGOUT:
messages.add_message(request, messages.SUCCESS, _(u'Successfully logout'))
messages.add_message(request, messages.SUCCESS, logout_msg)
if self.ajax:
url = reverse("cas_server:login")
data = {'status': 'success', 'detail': 'logout', 'url': url}
data = {
'status': 'success',
'detail': 'logout',
'url': url,
'session_nb': session_nb
}
return JsonResponse(request, data)
else:
return redirect("cas_server:login")
else:
if self.ajax:
data = {'status': 'success', 'detail': 'logout'}
data = {'status': 'success', 'detail': 'logout', 'session_nb': session_nb}
return JsonResponse(request, data)
else:
return render(request, settings.CAS_LOGOUT_TEMPLATE)
return render(
request,
settings.CAS_LOGOUT_TEMPLATE,
{'logout_msg': logout_msg}
)
class LoginView(View, LogoutMixin):