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 "" msgstr ""
"Project-Id-Version: cas_server\n" "Project-Id-Version: cas_server\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-17 19:21+0100\n" "POT-Creation-Date: 2015-12-26 15:31+0100\n"
"PO-Revision-Date: 2015-12-17 19:22+0100\n" "PO-Revision-Date: 2015-12-26 15:34+0100\n"
"Last-Translator: Valentin Samir <valentin.samir@crans.org>\n" "Last-Translator: Valentin Samir <valentin.samir@crans.org>\n"
"Language-Team: django <LL@li.org>\n" "Language-Team: django <LL@li.org>\n"
"Language: en\n" "Language: en\n"
@ -92,6 +92,9 @@ msgid ""
"some\\.server\\.com/path/.*$'.As it is a regular expression, special " "some\\.server\\.com/path/.*$'.As it is a regular expression, special "
"character must be escaped with a '\\'." "character must be escaped with a '\\'."
msgstr "" 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 #: models.py:198
msgid "user field" msgid "user field"
@ -210,7 +213,7 @@ msgstr ""
#: templates/cas_server/logged.html:10 #: templates/cas_server/logged.html:10
msgid "Log me out from all my sessions" msgid "Log me out from all my sessions"
msgstr "" msgstr "Log me out from all my sessions"
#: templates/cas_server/logged.html:13 #: templates/cas_server/logged.html:13
msgid "Logout" msgid "Logout"
@ -224,54 +227,80 @@ msgstr "Please loggin"
msgid "Login" msgid "Login"
msgstr "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 #: templates/cas_server/warn.html:7
msgid "Connect to the service" msgid "Connect to the service"
msgstr "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" msgid "Invalid login ticket"
msgstr "Invalid login ticket, please retry to login" msgstr "Invalid login ticket, please retry to login"
#: views.py:292 #: views.py:325
#, python-format #, python-format
msgid "Authentication has been required by service %(name)s (%(url)s)" msgid "Authentication has been required by service %(name)s (%(url)s)"
msgstr "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 #, python-format
msgid "Service %(url)s non allowed." msgid "Service %(url)s non allowed."
msgstr "Service %(url)s non allowed." msgstr "Service %(url)s non allowed."
#: views.py:333 #: views.py:366
msgid "Username non allowed" msgid "Username non allowed"
msgstr "Username non allowed" msgstr "Username non allowed"
#: views.py:340 #: views.py:373
msgid "User charateristics non allowed" msgid "User charateristics non allowed"
msgstr "User charateristics non allowed" msgstr "User charateristics non allowed"
#: views.py:347 #: views.py:380
#, python-format #, python-format
msgid "The attribut %(field)s is needed to use that service" msgid "The attribut %(field)s is needed to use that service"
msgstr "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 #, python-format
msgid "Authentication renewal required by service %(name)s (%(url)s)." msgid "Authentication renewal required by service %(name)s (%(url)s)."
msgstr "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 #, python-format
msgid "Authentication required by service %(name)s (%(url)s)." msgid "Authentication required by service %(name)s (%(url)s)."
msgstr "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 #, python-format
msgid "Service %s non allowed" msgid "Service %s non allowed"
msgstr "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 "" msgstr ""
"Project-Id-Version: cas_server\n" "Project-Id-Version: cas_server\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-17 19:21+0100\n" "POT-Creation-Date: 2015-12-26 15:31+0100\n"
"PO-Revision-Date: 2015-12-17 19:22+0100\n" "PO-Revision-Date: 2015-12-26 15:34+0100\n"
"Last-Translator: Valentin Samir <valentin.samir@crans.org>\n" "Last-Translator: Valentin Samir <valentin.samir@crans.org>\n"
"Language-Team: django <LL@li.org>\n" "Language-Team: django <LL@li.org>\n"
"Language: fr\n" "Language: fr\n"
@ -236,61 +236,89 @@ msgstr "Merci de se connecter"
msgid "Login" msgid "Login"
msgstr "Connexion" 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 #: templates/cas_server/warn.html:7
msgid "Connect to the service" msgid "Connect to the service"
msgstr "Se connecter au 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" msgid "Invalid login ticket"
msgstr "Ticket de connexion invalide, merci de réessayé de vous connecter" msgstr "Ticket de connexion invalide, merci de réessayé de vous connecter"
#: views.py:292 #: views.py:325
#, python-format #, python-format
msgid "Authentication has been required by service %(name)s (%(url)s)" msgid "Authentication has been required by service %(name)s (%(url)s)"
msgstr "" msgstr ""
"Une demande d'authentification a été émise pour le service %(name)s " "Une demande d'authentification a été émise pour le service %(name)s "
"(%(url)s)." "(%(url)s)."
#: views.py:326 #: views.py:359
#, python-format #, python-format
msgid "Service %(url)s non allowed." msgid "Service %(url)s non allowed."
msgstr "le service %(url)s n'est pas autorisé." msgstr "le service %(url)s n'est pas autorisé."
#: views.py:333 #: views.py:366
msgid "Username non allowed" msgid "Username non allowed"
msgstr "Nom d'utilisateur non authorisé" msgstr "Nom d'utilisateur non authorisé"
#: views.py:340 #: views.py:373
msgid "User charateristics non allowed" msgid "User charateristics non allowed"
msgstr "Caractéristique utilisateur non autorisée" msgstr "Caractéristique utilisateur non autorisée"
#: views.py:347 #: views.py:380
#, python-format #, python-format
msgid "The attribut %(field)s is needed to use that service" msgid "The attribut %(field)s is needed to use that service"
msgstr "L'attribut %(field)s est nécessaire pour se connecter à ce service" msgstr "L'attribut %(field)s est nécessaire pour se connecter à ce service"
#: views.py:417 #: views.py:450
#, python-format #, python-format
msgid "Authentication renewal required by service %(name)s (%(url)s)." msgid "Authentication renewal required by service %(name)s (%(url)s)."
msgstr "Demande de réauthentification pour le 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 #, python-format
msgid "Authentication required by service %(name)s (%(url)s)." msgid "Authentication required by service %(name)s (%(url)s)."
msgstr "Authentification requise par le service %(name)s (%(url)s)." msgstr "Authentification requise par le service %(name)s (%(url)s)."
#: views.py:431 #: views.py:464
#, python-format #, python-format
msgid "Service %s non allowed" msgid "Service %s non allowed"
msgstr "Le service %s n'est pas autorisé" 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 "" #~ msgid ""
#~ "A ProxyGrantingTicket can be delivered to the service in order to " #~ "A ProxyGrantingTicket can be delivered to the service in order to "
#~ "authenticate for the user on a backend service" #~ "authenticate for the user on a backend service"

View file

@ -3,6 +3,6 @@
{% load staticfiles %} {% load staticfiles %}
{% load i18n %} {% load i18n %}
{% block content %} {% 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 %} {% endblock %}

View file

@ -64,6 +64,7 @@ class LogoutMixin(object):
"""destroy CAS session utils""" """destroy CAS session utils"""
def logout(self, all=False): def logout(self, all=False):
"""effectively destroy CAS session""" """effectively destroy CAS session"""
session_nb = 0
username = self.request.session.get("username") username = self.request.session.get("username")
if username: if username:
if all: if all:
@ -79,6 +80,7 @@ class LogoutMixin(object):
self.request.session.flush() self.request.session.flush()
user.logout(self.request) user.logout(self.request)
user.delete() user.delete()
session_nb += 1
except models.User.DoesNotExist: except models.User.DoesNotExist:
# if user not found in database, flush the session anyway # if user not found in database, flush the session anyway
self.request.session.flush() self.request.session.flush()
@ -90,7 +92,9 @@ class LogoutMixin(object):
session.flush() session.flush()
user.logout(self.request) user.logout(self.request)
user.delete() user.delete()
session_nb += 1
logger.info("User %s logged out" % username) logger.info("User %s logged out" % username)
return session_nb
class LogoutView(View, LogoutMixin): class LogoutView(View, LogoutMixin):
@ -109,7 +113,7 @@ class LogoutView(View, LogoutMixin):
"""methode called on GET request on this view""" """methode called on GET request on this view"""
logger.info("logout requested") logger.info("logout requested")
self.init_get(request) 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 service is set, redirect to service after logout
if self.service: if self.service:
list(messages.get_messages(request)) # clean messages before leaving the django app list(messages.get_messages(request)) # clean messages before leaving the django app
@ -119,20 +123,49 @@ class LogoutView(View, LogoutMixin):
return HttpResponseRedirect(self.url) return HttpResponseRedirect(self.url)
# else redirect to login page # else redirect to login page
else: 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: 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: if self.ajax:
url = reverse("cas_server:login") 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) return JsonResponse(request, data)
else: else:
return redirect("cas_server:login") return redirect("cas_server:login")
else: else:
if self.ajax: if self.ajax:
data = {'status': 'success', 'detail': 'logout'} data = {'status': 'success', 'detail': 'logout', 'session_nb': session_nb}
return JsonResponse(request, data) return JsonResponse(request, data)
else: else:
return render(request, settings.CAS_LOGOUT_TEMPLATE) return render(
request,
settings.CAS_LOGOUT_TEMPLATE,
{'logout_msg': logout_msg}
)
class LoginView(View, LogoutMixin): class LoginView(View, LogoutMixin):