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 @@ + + +
+ ++ 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. + +
+ +