diff --git a/README.rst b/README.rst index 2058cc3..d67a3e0 100644 --- a/README.rst +++ b/README.rst @@ -219,6 +219,30 @@ Template settings if you omit some keys of the dictionnary, the default value for these keys is used. +* ``CAS_INFO_MESSAGES``: Messages displayed in info-boxes on the html pages of the default templates. + It is a dictionnary mapping message name to a message dict. A message dict has 3 keys: + + * ``message``: A unicode message to display, potentially wrapped around ugettex_lazy + * ``discardable``: A boolean, specify if the users can close the message info-box + * ``type``: One of info, success, info, warning, danger. The type of the info-box. + + ``CAS_INFO_MESSAGES`` contains by default one message, ``cas_explained``, which explain + roughly the purpose of a CAS. The default is:: + + { + "cas_explained": { + "message":_( + u"The Central Authentication Service grants you access to most of our websites by " + u"authenticating only once, so you don't need to type your credentials again unless " + u"your session expires or you logout." + ), + "discardable": True, + "type": "info", # one of info, success, info, warning, danger + }, + } + +* ``CAS_INFO_MESSAGES_ORDER``: A list of message names. Order in which info-box messages are + displayed. Use an empty list to disable messages display. The default is ``[]``. * ``CAS_LOGIN_TEMPLATE``: Path to the template showed on ``/login`` then the user is not autenticated. The default is ``"cas_server/login.html"``. * ``CAS_WARN_TEMPLATE``: Path to the template showed on ``/login?service=...`` then diff --git a/cas_server/default_settings.py b/cas_server/default_settings.py index 0ee1749..238fc0a 100644 --- a/cas_server/default_settings.py +++ b/cas_server/default_settings.py @@ -12,6 +12,7 @@ """Default values for the app's settings""" from django.conf import settings from django.contrib.staticfiles.templatetags.staticfiles import static +from django.utils.translation import ugettext_lazy as _ from importlib import import_module @@ -180,6 +181,32 @@ CAS_NEW_VERSION_EMAIL_WARNING = True #: You should not change it. CAS_NEW_VERSION_JSON_URL = "https://pypi.python.org/pypi/django-cas-server/json" + +#: Messages displayed in a info-box on the html pages of the default templates. +#: ``CAS_INFO_MESSAGES`` is a :class:`dict` mapping message name to a message :class:`dict`. +#: A message :class:`dict` has 3 keys: +#: * ``message``: A :class:`unicode`, the message to display, potentially wrapped around +#: ugettex_lazy +#: * ``discardable``: A :class:`bool`, specify if the users can close the message info-box +#: * ``type``: One of info, success, info, warning, danger. The type of the info-box. +#: ``CAS_INFO_MESSAGES`` contains by default one message, ``cas_explained``, which explain +#: roughly the purpose of a CAS. +CAS_INFO_MESSAGES = { + "cas_explained": { + "message": _( + u"The Central Authentication Service grants you access to most of our websites by " + u"authenticating only once, so you don't need to type your credentials again unless " + u"your session expires or you logout." + ), + "discardable": True, + "type": "info", # one of info, success, info, warning, danger + }, +} +#: :class:`list` of message names. Order in which info-box messages are displayed. +#: Let the list empty to disable messages display. +CAS_INFO_MESSAGES_ORDER = [] + + GLOBALS = globals().copy() for name, default_value in GLOBALS.items(): # only care about parameter begining by CAS_ diff --git a/cas_server/locale/fr/LC_MESSAGES/django.po b/cas_server/locale/fr/LC_MESSAGES/django.po index 644f814..049921a 100644 --- a/cas_server/locale/fr/LC_MESSAGES/django.po +++ b/cas_server/locale/fr/LC_MESSAGES/django.po @@ -23,7 +23,18 @@ msgstr "" msgid "Central Authentication Service" msgstr "Service Central d'Authentification" -#: forms.py:88 +#: default_settings.py:197 +msgid "" +"The Central Authentication Service grants you access to most of our websites " +"by authenticating only once, so you don't need to type your credentials " +"again unless your session expires or you logout." +msgstr "" +"Le Service Central d'Authentification permet, en vous authentifiant une " +"seule fois, d'accéder à la plupart de nos sites sans avoir à retaper votre " +"identifiant et votre mot de passe chaque fois que vous changez de site, " +"jusqu'à ce que votre session expire ou que vous vous déconnectiez." + +#: forms.py:84 msgid "Identity provider" msgstr "fournisseur d'identité" diff --git a/cas_server/static/cas_server/functions.js b/cas_server/static/cas_server/functions.js index 81a4add..8bbbeaa 100644 --- a/cas_server/static/cas_server/functions.js +++ b/cas_server/static/cas_server/functions.js @@ -31,14 +31,14 @@ function eraseCookie(name) { createCookie(name,"",-1); } -function alert_version(last_version){ +function discard_and_remember(id, cookie_name, token, days=10*365){ jQuery(function( $ ){ - $("#alert-version").click(function( e ){ + $(id).click(function( e ){ e.preventDefault(); - createCookie("cas-alert-version", last_version, 10*365); + createCookie(cookie_name, token, days); }); - if(readCookie("cas-alert-version") === last_version){ - $("#alert-version").parent().hide(); + if(readCookie(cookie_name) === token){ + $(id).parent().hide(); } }); } diff --git a/cas_server/templates/cas_server/base.html b/cas_server/templates/cas_server/base.html index 8a491ca..2a2d8e1 100644 --- a/cas_server/templates/cas_server/base.html +++ b/cas_server/templates/cas_server/base.html @@ -31,10 +31,16 @@
{% if auto_submit %}
{% endfor %} {% if auto_submit %}{% endif %} @@ -71,9 +77,17 @@ - {% if settings.CAS_NEW_VERSION_HTML_WARNING and upgrade_available %} - - {% endif %} + {% block javascript %}{% endblock %} diff --git a/cas_server/templates/cas_server/login.html b/cas_server/templates/cas_server/login.html index ff98c03..51aa19c 100644 --- a/cas_server/templates/cas_server/login.html +++ b/cas_server/templates/cas_server/login.html @@ -15,7 +15,7 @@ {% if auto_submit %}{% endif %} {% endblock %} -{% block javascript %}{% endblock %} +{% endblock %} diff --git a/cas_server/utils.py b/cas_server/utils.py index 19957c8..17ec5f9 100644 --- a/cas_server/utils.py +++ b/cas_server/utils.py @@ -64,6 +64,7 @@ def context(params): """ params["settings"] = settings params["message_levels"] = DEFAULT_MESSAGE_LEVELS + if settings.CAS_NEW_VERSION_HTML_WARNING: LAST_VERSION = last_version() params["VERSION"] = VERSION @@ -72,6 +73,28 @@ def context(params): params["upgrade_available"] = decode_version(VERSION) < decode_version(LAST_VERSION) else: params["upgrade_available"] = False + + if settings.CAS_INFO_MESSAGES_ORDER: + params["CAS_INFO_RENDER"] = [] + for msg_name in settings.CAS_INFO_MESSAGES_ORDER: + if msg_name in settings.CAS_INFO_MESSAGES: + try: + msg = settings.CAS_INFO_MESSAGES[msg_name].copy() + except AttributeError: + continue + if "message" in msg: + msg["name"] = msg_name + # use info as default infox type + msg["type"] = msg.get("type", "info") + # make box discardable by default + msg["discardable"] = msg.get("discardable", True) + msg_hash = ( + six.text_type(msg["message"]).encode("utf-8") + + msg["type"].encode("utf-8") + ) + # hash depend of the rendering language + msg["hash"] = hashlib.md5(msg_hash).hexdigest() + params["CAS_INFO_RENDER"].append(msg) return params