From f0ee6c205e8876b0709eee574f7c8b9d3e7eac74 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Sun, 1 Oct 2017 13:31:28 +0200 Subject: [PATCH] added user notifications --- ordr2/events.py | 29 +++++++++++++++++++++++- ordr2/templates/emails/activation.jinja2 | 25 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 ordr2/templates/emails/activation.jinja2 diff --git a/ordr2/events.py b/ordr2/events.py index f569fe9..936ecc1 100644 --- a/ordr2/events.py +++ b/ordr2/events.py @@ -1,5 +1,6 @@ from pyramid.events import NewRequest, subscriber - +from pyramid.renderers import render +from pyramid_mailer.message import Message class UserLogIn(object): def __init__(self, request, user): @@ -7,6 +8,16 @@ class UserLogIn(object): self.user = user +class UserNotification(object): + def __init__(self, request, user): + self.request = request + self.user = user + + +class AccountActivation(UserNotification): + pass + + @subscriber(UserLogIn) @subscriber(NewRequest) def set_display_defaults(event): @@ -19,3 +30,19 @@ def set_display_defaults(event): } } event.request.session['display'] = defaults + + +@subscriber(AccountActivation) +def account_activation_notification(event): + body = render( + 'ordr2:templates/emails/activation.jinja2', + {'user': event.user}, + event.request + ) + message = Message( + subject='[ordr] Your account was activated', + sender=event.request.registry.settings['mail.default_sender'], + recipients=[event.user.email], + html=body + ) + event.request.mailer.send(message) diff --git a/ordr2/templates/emails/activation.jinja2 b/ordr2/templates/emails/activation.jinja2 new file mode 100755 index 0000000..55ba4bf --- /dev/null +++ b/ordr2/templates/emails/activation.jinja2 @@ -0,0 +1,25 @@ + + + + + ordr Account Activation + + + + +

Hi there!

+

+ Your account {{ user.user_name }} has been activated. + Log in and start ordering. +

+

+ Regards, +
+ ordr +

+

+ Please don't respont to this email! This is an automatically generated notification by the system. + +

+ +