Browse Source

added user notifications

php2python
Holger Frey 7 years ago
parent
commit
f0ee6c205e
  1. 29
      ordr2/events.py
  2. 25
      ordr2/templates/emails/activation.jinja2

29
ordr2/events.py

@ -1,5 +1,6 @@
from pyramid.events import NewRequest, subscriber from pyramid.events import NewRequest, subscriber
from pyramid.renderers import render
from pyramid_mailer.message import Message
class UserLogIn(object): class UserLogIn(object):
def __init__(self, request, user): def __init__(self, request, user):
@ -7,6 +8,16 @@ class UserLogIn(object):
self.user = user self.user = user
class UserNotification(object):
def __init__(self, request, user):
self.request = request
self.user = user
class AccountActivation(UserNotification):
pass
@subscriber(UserLogIn) @subscriber(UserLogIn)
@subscriber(NewRequest) @subscriber(NewRequest)
def set_display_defaults(event): def set_display_defaults(event):
@ -19,3 +30,19 @@ def set_display_defaults(event):
} }
} }
event.request.session['display'] = defaults 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)

25
ordr2/templates/emails/activation.jinja2

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ordr Account Activation</title>
<link href='http://fonts.googleapis.com/css?family=Anton&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{request.static_url('ordr2:static/css/email.css')}}" type="text/css" media="screen">
</head>
<body>
<h1>Hi there!</h1>
<p>
Your account {{ user.user_name }} has been activated.
<a href="{{ request.resource_url(request.root) }}">Log in and start ordering.</a>
</p>
<p class="signature">
Regards,
<br/>
<span class="brand">ordr</span>
</p>
<p class="footprint">
<small>Please don't respont to this email! This is an automatically generated notification by the system.</small>
<a href="http://distractedbysquirrels.com/" target="_blank" title="This software was originally written by Sebastian Sebald." class="icon-dbs"></a>
</p>
</body>
</html>