# HG changeset patch # User Thierry Florac # Date 1427814814 -7200 # Node ID 31ad4c01e99e63a39b5a6da02cf566bb4dc3789a # Parent 7ed8fb9b132c41555ff1905429c373f964a82f59 Added mail notifications when registering local user diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/interfaces/notification.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_security/interfaces/notification.py Tue Mar 31 17:13:34 2015 +0200 @@ -0,0 +1,70 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from zope.annotation.interfaces import IAttributeAnnotatable + +# import packages +from zope.interface import Interface, invariant, Invalid +from zope.schema import TextLine, Text, Bool, Choice + +from pyams_security import _ + + +class INotificationSettings(IAttributeAnnotatable): + """Mailer notification settings interface""" + + enable_notifications = Bool(title=_("Enable notifications?"), + description=_("If 'no', mail notifications will be disabled"), + required=True, + default=False) + + mailer = Choice(title=_("Mailer utility"), + description=_("Mail delivery utility used to send notifications"), + required=False, + vocabulary="PyAMS mailer utilities") + + @invariant + def check_mailer(self): + if self.enable_notifications and not self.mailer: + raise Invalid(_("Notifications can't be enabled without mailer utility")) + + service_name = TextLine(title=_("Service name"), + description=_("Name of service as defined in registration mail subject"), + required=True) + + service_owner = TextLine(title=_("Service owner"), + description=_("Name of the entity providing this service, which will be visible " + "in notifications messages"), + required=True) + + sender_name = TextLine(title=_("Sender name"), + description=_("Visible name of registration mail sender"), + required=True) + + sender_email = TextLine(title=_("Sender email"), + description=_("Email address of registration mail sender"), + required=True) + + subject_prefix = TextLine(title=_("Subject prefix"), + description=_("This prefix will be inserted into subject prefix of each notification " + "message"), + required=False) + + signature = Text(title=_("Email signature"), + description=_("Text displayed in email footer"), + required=False) diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.mo Binary file src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.mo has changed diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.po --- a/src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.po Tue Mar 17 16:02:49 2015 +0100 +++ b/src/pyams_security/locales/fr/LC_MESSAGES/pyams_security.po Tue Mar 31 17:13:34 2015 +0200 @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE 1.0\n" -"POT-Creation-Date: 2015-03-03 16:44+0100\n" +"POT-Creation-Date: 2015-03-31 16:39+0200\n" "PO-Revision-Date: 2015-02-18 22:19+0100\n" "Last-Translator: Thierry Florac \n" "Language-Team: French\n" @@ -86,6 +86,7 @@ msgstr "Propriétés..." #: src/pyams_security/zmi/utility.py:185 +#: src/pyams_security/zmi/notification.py:58 #: src/pyams_security/zmi/plugin/social.py:79 #: src/pyams_security/zmi/plugin/userfolder.py:76 #: src/pyams_security/zmi/plugin/group.py:72 @@ -119,6 +120,14 @@ msgid "Given plug-in name doesn't exist!" msgstr "Le module indiqué n'existe pas !" +#: src/pyams_security/zmi/notification.py:45 +msgid "Notifications..." +msgstr "Notifications..." + +#: src/pyams_security/zmi/notification.py:59 +msgid "Notifications properties" +msgstr "Paramétrage des notifications" + #: src/pyams_security/zmi/security.py:41 msgid "Access rules..." msgstr "Règles d'accès..." @@ -794,16 +803,161 @@ "Vous ne pouvez pas activer les fonctions d'inscription libre sans " "sélectionner de dossier de stockage des utilisateurs" +#: src/pyams_security/interfaces/notification.py:31 +msgid "Enable notifications?" +msgstr "Activer les notifications ?" + +#: src/pyams_security/interfaces/notification.py:32 +msgid "If 'no', mail notifications will be disabled" +msgstr "Si 'non', les notifications par mail seront désactivées" + +#: src/pyams_security/interfaces/notification.py:36 +msgid "Mailer utility" +msgstr "Outil de messagerie" + +#: src/pyams_security/interfaces/notification.py:37 +msgid "Mail delivery utility used to send notifications" +msgstr "Nom de l'outil d'envoi de mail utilisé pour les notifications" + +#: src/pyams_security/interfaces/notification.py:46 +msgid "Service name" +msgstr "Nom du service" + +#: src/pyams_security/interfaces/notification.py:47 +msgid "Name of service as defined in registration mail subject" +msgstr "Ce nom sera inscrit dans le sujet des messages de notification" + +#: src/pyams_security/interfaces/notification.py:50 +msgid "Service owner" +msgstr "Propriétaire du service" + +#: src/pyams_security/interfaces/notification.py:51 +msgid "" +"Name of the entity providing this service, which will be visible in " +"notifications messages" +msgstr "" +"Nom de l'entité fournissant ce service, qui sera indiqué dans les messages " +"de notifications" + +#: src/pyams_security/interfaces/notification.py:55 +msgid "Sender name" +msgstr "Nom d'expéditeur" + +#: src/pyams_security/interfaces/notification.py:56 +msgid "Visible name of registration mail sender" +msgstr "Nom de l'expéditeur des messages de notifications" + +#: src/pyams_security/interfaces/notification.py:59 +msgid "Sender email" +msgstr "Adresse de l'expéditeur" + +#: src/pyams_security/interfaces/notification.py:60 +msgid "Email address of registration mail sender" +msgstr "Nom de l'adresse d'expédition des messages de notifications" + +#: src/pyams_security/interfaces/notification.py:63 +msgid "Subject prefix" +msgstr "Préfixe des sujets" + +#: src/pyams_security/interfaces/notification.py:64 +msgid "" +"This prefix will be inserted into subject prefix of each notification message" +msgstr "Ce préfixe sera inséré au début du sujet des messages de notification" + +#: src/pyams_security/interfaces/notification.py:68 +msgid "Email signature" +msgstr "Signature" + +#: src/pyams_security/interfaces/notification.py:69 +msgid "Text displayed in email footer" +msgstr "Ce texte sera affiché en pied des messages" + +#: src/pyams_security/interfaces/notification.py:44 +msgid "Notifications can't be enabled without mailer utility" +msgstr "" +"Les notifications ne peuvent pas être activées si vous ne séletionnez pas un " +"outil d'envoi de messages" + #: src/pyams_security/plugin/http.py:44 msgid "HTTP Basic credentials" msgstr "Authentification HTTP Basic" -#: src/pyams_security/plugin/userfolder.py:106 -#: src/pyams_security/plugin/userfolder.py:111 +#: src/pyams_security/plugin/userfolder.py:115 +#: src/pyams_security/plugin/userfolder.py:120 msgid "Can't activate profile with given params!" msgstr "" "Impossible de confirmer votre inscription avec les paramètres fournis !" +#: src/pyams_security/plugin/userfolder.py:249 +#, python-format +msgid "{prefix}Please confirm registration" +msgstr "{prefix}Veuillez confirmer votre inscription" + +#: src/pyams_security/plugin/templates/register-info.pt:7 +msgid "${header} Registration notice" +msgstr "${header} Inscription effectuée" + +#: src/pyams_security/plugin/templates/register-info.pt:11 +#: src/pyams_security/plugin/templates/register-message.pt:11 +msgid "Hello," +msgstr "Bonjour," + +#: src/pyams_security/plugin/templates/register-info.pt:12 +#: src/pyams_security/plugin/templates/register-message.pt:12 +msgid "${service_name} is a service provided by ${service_owner}." +msgstr "${service_name} est un service fourni par ${service_owner}." + +#: src/pyams_security/plugin/templates/register-info.pt:14 +msgid "" +"A new account has been created for your email address, that you may confirm " +"before being able to use the service." +msgstr "" +"Un nouveau compte a été créé pour votre adresse de messagerie, que vous devez confirmer " +"avant de pouvoir utiliser ce service." + +#: src/pyams_security/plugin/templates/register-info.pt:16 +msgid "The login what was given to your account is: ${login}." +msgstr "L'identifiant de connexion qui a été fourni pour votre compte est : ${login}." + +#: src/pyams_security/plugin/templates/register-info.pt:17 +#: src/pyams_security/plugin/templates/register-message.pt:15 +msgid "" +"To confirm your registration, please click on the following link and re-" +"enter your login credentials:" +msgstr "" +"Pour confirmer cette inscription, veuillez cliquer sur le lien ci-dessous et " +"re-saisir vos paramètres de connexion." + +#: src/pyams_security/plugin/templates/register-info.pt:24 +#: src/pyams_security/plugin/templates/register-message.pt:22 +msgid "" +"If you don't want to confirm this registration, please just ignore this " +"message and your registration information will be deleted within 30 days." +msgstr "" +"Si vous ne souhaitez pas confirmer cette inscription ou si celle-ci a été " +"faite sans votre consentement, il vous suffit d'ignorer ce message et votre " +"inscription sera supprimée automatiquement dans un délai de 30 jours." + +#: src/pyams_security/plugin/templates/register-info.pt:26 +#: src/pyams_security/plugin/templates/register-message.pt:24 +msgid "Thank you for using our services." +msgstr "Merci d'utiliser nos services." + +#: src/pyams_security/plugin/templates/register-message.pt:7 +msgid "${header} Please confirm registration" +msgstr "${header} Veuillez confirmer votre inscription" + +#: src/pyams_security/plugin/templates/register-message.pt:14 +msgid "" +"You have registered a new account that you may confirm before being able to " +"use the service." +msgstr "" +"Vous avez créé un nouveau compte que vous devez confirmer avant de pouvoir " +"utiliser ce service." + +#~ msgid "Mailer name" +#~ msgstr "Nom du service de mail" + #~ msgid "Add..." #~ msgstr "Ajouter..." diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/locales/pyams_security.pot --- a/src/pyams_security/locales/pyams_security.pot Tue Mar 17 16:02:49 2015 +0100 +++ b/src/pyams_security/locales/pyams_security.pot Tue Mar 31 17:13:34 2015 +0200 @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE 1.0\n" -"POT-Creation-Date: 2015-03-03 16:44+0100\n" +"POT-Creation-Date: 2015-03-31 16:39+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" @@ -86,6 +86,7 @@ msgstr "" #: ./src/pyams_security/zmi/utility.py:185 +#: ./src/pyams_security/zmi/notification.py:58 #: ./src/pyams_security/zmi/plugin/social.py:79 #: ./src/pyams_security/zmi/plugin/userfolder.py:76 #: ./src/pyams_security/zmi/plugin/group.py:72 @@ -119,6 +120,14 @@ msgid "Given plug-in name doesn't exist!" msgstr "" +#: ./src/pyams_security/zmi/notification.py:45 +msgid "Notifications..." +msgstr "" + +#: ./src/pyams_security/zmi/notification.py:59 +msgid "Notifications properties" +msgstr "" + #: ./src/pyams_security/zmi/security.py:41 msgid "Access rules..." msgstr "" @@ -752,11 +761,140 @@ msgid "You can't activate open registration without selecting a users folder" msgstr "" +#: ./src/pyams_security/interfaces/notification.py:31 +msgid "Enable notifications?" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:32 +msgid "If 'no', mail notifications will be disabled" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:36 +msgid "Mailer utility" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:37 +msgid "Mail delivery utility used to send notifications" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:46 +msgid "Service name" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:47 +msgid "Name of service as defined in registration mail subject" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:50 +msgid "Service owner" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:51 +msgid "" +"Name of the entity providing this service, which will be visible in " +"notifications messages" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:55 +msgid "Sender name" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:56 +msgid "Visible name of registration mail sender" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:59 +msgid "Sender email" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:60 +msgid "Email address of registration mail sender" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:63 +msgid "Subject prefix" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:64 +msgid "" +"This prefix will be inserted into subject prefix of each notification message" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:68 +msgid "Email signature" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:69 +msgid "Text displayed in email footer" +msgstr "" + +#: ./src/pyams_security/interfaces/notification.py:44 +msgid "Notifications can't be enabled without mailer utility" +msgstr "" + #: ./src/pyams_security/plugin/http.py:44 msgid "HTTP Basic credentials" msgstr "" -#: ./src/pyams_security/plugin/userfolder.py:106 -#: ./src/pyams_security/plugin/userfolder.py:111 +#: ./src/pyams_security/plugin/userfolder.py:115 +#: ./src/pyams_security/plugin/userfolder.py:120 msgid "Can't activate profile with given params!" msgstr "" + +#: ./src/pyams_security/plugin/userfolder.py:249 +#, python-format +msgid "{prefix}Please confirm registration" +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:7 +msgid "${header} Registration notice" +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:11 +#: ./src/pyams_security/plugin/templates/register-message.pt:11 +msgid "Hello," +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:12 +#: ./src/pyams_security/plugin/templates/register-message.pt:12 +msgid "${service_name} is a service provided by ${service_owner}." +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:14 +msgid "" +"A new account has been created for your email address, that you may confirm " +"before being able to use the service." +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:16 +msgid "The login what was given to your account is: ${login}." +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:17 +#: ./src/pyams_security/plugin/templates/register-message.pt:15 +msgid "" +"To confirm your registration, please click on the following link and re-enter" +" your login credentials:" +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:24 +#: ./src/pyams_security/plugin/templates/register-message.pt:22 +msgid "" +"If you don't want to confirm this registration, please just ignore this " +"message and your registration information will be deleted within 30 days." +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-info.pt:26 +#: ./src/pyams_security/plugin/templates/register-message.pt:24 +msgid "Thank you for using our services." +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-message.pt:7 +msgid "${header} Please confirm registration" +msgstr "" + +#: ./src/pyams_security/plugin/templates/register-message.pt:14 +msgid "" +"You have registered a new account that you may confirm before being able to " +"use the service." +msgstr "" diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/notification.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_security/notification.py Tue Mar 31 17:13:34 2015 +0200 @@ -0,0 +1,57 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_security.interfaces import ISecurityManager +from pyams_security.interfaces.notification import INotificationSettings +from zope.annotation.interfaces import IAnnotations + +# import packages +from persistent import Persistent +from pyams_utils.adapter import adapter_config +from pyams_utils.request import check_request +from zope.interface import implementer +from zope.lifecycleevent import ObjectCreatedEvent +from zope.schema.fieldproperty import FieldProperty + + +@implementer(INotificationSettings) +class NotificationSettings(Persistent): + """Notification settings""" + + enable_notifications = FieldProperty(INotificationSettings['enable_notifications']) + mailer = FieldProperty(INotificationSettings['mailer']) + service_name = FieldProperty(INotificationSettings['service_name']) + service_owner = FieldProperty(INotificationSettings['service_owner']) + sender_name = FieldProperty(INotificationSettings['sender_name']) + sender_email = FieldProperty(INotificationSettings['sender_email']) + subject_prefix = FieldProperty(INotificationSettings['subject_prefix']) + signature = FieldProperty(INotificationSettings['signature']) + + +NOTIFICATIONS_KEY = 'pyams_security.notifications' + + +@adapter_config(context=ISecurityManager, provides=INotificationSettings) +def SecurityNotificationSettingsFactory(context): + """Security manager notifications factory adapter""" + annotations = IAnnotations(context) + settings = annotations.get(NOTIFICATIONS_KEY) + if settings is None: + settings = annotations[NOTIFICATIONS_KEY] = NotificationSettings() + check_request().registry.notify(ObjectCreatedEvent(settings)) + return settings diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/plugin/templates/register-info.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_security/plugin/templates/register-info.pt Tue Mar 31 17:13:34 2015 +0200 @@ -0,0 +1,29 @@ + + + + <span tal:replace="settings.subject_prefix" i18n:name="header"></span> Registration notice + + + +

Hello,

+

is a service provided by + .

+

A new account has been created for your email address, that you may confirm before being able + to use the service.

+

The login what was given to your account is: .

+

To confirm your registration, please click on the following link and re-enter your login credentials:
+ +

+

If you don't want to confirm this registration, please just ignore this message and your registration information + will be deleted within 30 days.

+

Thank you for using our services.

+
+ + diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/plugin/templates/register-message.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_security/plugin/templates/register-message.pt Tue Mar 31 17:13:34 2015 +0200 @@ -0,0 +1,27 @@ + + + + <span tal:replace="settings.subject_prefix" i18n:name="header"></span> Please confirm registration + + + +

Hello,

+

is a service provided by + .

+

You have registered a new account that you may confirm before being able to use the service.

+

To confirm your registration, please click on the following link and re-enter your login credentials:
+ +

+

If you don't want to confirm this registration, please just ignore this message and your registration information + will be deleted within 30 days.

+

Thank you for using our services.

+
+ + diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/plugin/userfolder.py --- a/src/pyams_security/plugin/userfolder.py Tue Mar 17 16:02:49 2015 +0100 +++ b/src/pyams_security/plugin/userfolder.py Tue Mar 31 17:13:34 2015 +0200 @@ -9,6 +9,8 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from zope.component.interfaces import ISite +from pyams_utils.traversing import get_parent __docformat__ = 'restructuredtext' @@ -17,6 +19,7 @@ import base64 import hashlib import hmac +import os import random import sys from datetime import datetime @@ -24,16 +27,23 @@ # import interfaces from pyams_security.interfaces import ISecurityManager, IUsersFolderPlugin, ILocalUser, IPrincipalInfo +from pyams_security.interfaces.notification import INotificationSettings +from pyramid_chameleon.interfaces import IChameleonTranslate +from pyramid_mailer.interfaces import IMailer from zope.lifecycleevent.interfaces import IObjectAddedEvent from zope.password.interfaces import IPasswordManager from zope.schema.interfaces import IVocabularyRegistry # import packages +from chameleon.zpt.template import PageTemplateFile from persistent import Persistent from pyams_security.principal import PrincipalInfo from pyams_utils.adapter import adapter_config +from pyams_utils.html import html_to_text from pyams_utils.registry import query_utility, get_utility +from pyams_utils.request import check_request from pyramid.events import subscriber +from pyramid_mailer.message import Message, Attachment from zope.container.contained import Contained from zope.container.folder import Folder from zope.interface import implementer, provider, Invalid @@ -55,6 +65,7 @@ _password = FieldProperty(ILocalUser['password']) _password_salt = None password_manager = FieldProperty(ILocalUser['password_manager']) + wait_confirmation = FieldProperty(ILocalUser['wait_confirmation']) self_registered = FieldProperty(ILocalUser['self_registered']) activation_secret = FieldProperty(ILocalUser['activation_secret']) activation_hash = FieldProperty(ILocalUser['activation_hash']) @@ -215,8 +226,43 @@ @subscriber(IObjectAddedEvent, context_selector=ILocalUser) def handle_new_local_user(event): """Send a confirmation message when a new user is recorded""" + security = query_utility(ISecurityManager) + settings = INotificationSettings(security) + mailer = settings.mailer + if mailer is None: + return + if isinstance(mailer, str): + mailer = query_utility(IMailer, name=mailer) + if mailer is None: + return + request = check_request() + translate = request.localizer.translate user = event.object if user.self_registered: - pass + template_name = 'register-message.pt' + elif user.wait_confirmation: + template_name = 'register-info.pt' else: - pass + template_name = None + if template_name is not None: + template = PageTemplateFile(os.path.join(os.path.split(__file__)[0], 'templates', template_name), + translate=query_utility(IChameleonTranslate)) + site = get_parent(request.context, ISite) + html_body = template(request=request, context=user, site=site, settings=settings) + message = Message(subject=translate(_("{prefix}Please confirm registration")) + .format(prefix="{prefix} ".format(prefix=settings.subject_prefix) + if settings.subject_prefix else ''), + sender='{name} <{email}>'.format(name=settings.sender_name, + email=settings.sender_email), + recipients=("{firstname} {lastname} <{email}>".format(firstname=user.firstname, + lastname=user.lastname, + email=user.email), ), + html=Attachment(data=html_body, + content_type='text/html; charset=utf-8', + disposition='inline', + transfer_encoding='quoted-printable'), + body=Attachment(data=html_to_text(html_body), + content_type='text/plain; charset=utf-8', + disposition='inline', + transfer_encoding='quoted-printable')) + mailer.send(message) diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/views/login.py --- a/src/pyams_security/views/login.py Tue Mar 17 16:02:49 2015 +0100 +++ b/src/pyams_security/views/login.py Tue Mar 31 17:13:34 2015 +0200 @@ -122,7 +122,7 @@ status = {'status': 'redirect'} session = self.request.session if LOGIN_REFERER_KEY in session: - status['location'] = session[LOGIN_REFERER_KEY] + status['location'] = session[LOGIN_REFERER_KEY] or '/' del session[LOGIN_REFERER_KEY] return status diff -r 7ed8fb9b132c -r 31ad4c01e99e src/pyams_security/zmi/notification.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_security/zmi/notification.py Tue Mar 31 17:13:34 2015 +0200 @@ -0,0 +1,78 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_security.interfaces import ISecurityManager +from pyams_security.interfaces.notification import INotificationSettings +from pyams_security.zmi.interfaces import ISecurityManagerMenu +from pyams_skin.layer import IPyAMSLayer +from pyams_zmi.layer import IAdminLayer +from zope.component.interfaces import ISite + +# import packages +from pyams_form.form import AJAXEditForm +from pyams_pagelet.pagelet import pagelet_config +from pyams_skin.viewlet.menu import MenuItem +from pyams_utils.registry import query_utility +from pyams_viewlet.viewlet import viewlet_config +from pyams_zmi.form import AdminDialogEditForm +from pyramid.url import resource_url +from pyramid.view import view_config +from z3c.form import field + +from pyams_security import _ + + +@viewlet_config(name='notifications.menu', context=ISite, layer=IAdminLayer, manager=ISecurityManagerMenu, + permission='system.view', weight=2) +class SecurityManagerNotificationsMenuItem(MenuItem): + """Notifications properties menu item""" + + label = _("Notifications...") + url = 'notifications.html' + modal_target = True + + def get_url(self): + manager = query_utility(ISecurityManager) + return resource_url(manager, self.request, self.url) + + +@pagelet_config(name='notifications.html', context=ISecurityManager, layer=IPyAMSLayer, permission='system.view') +class SecurityManagerNotificationsEditForm(AdminDialogEditForm): + """Security manager notifications edit form""" + + title = _("System security manager") + legend = _("Notifications properties") + icon_css_class = 'fa fa-fw fa-envelope-o' + label_css_class = 'control-label col-md-5' + input_css_class = 'col-md-7' + + fields = field.Fields(INotificationSettings) + ajax_handler = 'notifications.json' + + def getContent(self): + return query_utility(ISecurityManager) + + def updateWidgets(self, prefix=None): + super(SecurityManagerNotificationsEditForm, self).updateWidgets(prefix) + self.widgets['signature'].label_css_class = 'textarea' + + +@view_config(name='notifications.json', context=ISecurityManager, request_type=IPyAMSLayer, + permission='system.manage', renderer='json', xhr=True) +class SecurityManagerNotificationsAJAXEditForm(AJAXEditForm, SecurityManagerNotificationsEditForm): + """Security manager notifications edit form, AJAX view"""