Browse Source

added events system

php2python
Holger Frey 7 years ago
parent
commit
914b17e193
  1. 19
      ordr2/events.py
  2. 3
      ordr2/views/account.py

19
ordr2/events.py

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
from pyramid.events import subscriber
class UserLogIn(object):
def __init__(self, request, user):
self.request = request
self.user = user
@subscriber(UserLogIn)
def set_display_defaults(event):
defaults = {
'users': {
'first': True,
'last': True,
'email': True,
}
}
event.request.session['display'] = defaults

3
ordr2/views/account.py

@ -5,6 +5,7 @@ from pyramid.renderers import render @@ -5,6 +5,7 @@ from pyramid.renderers import render
from pyramid.security import remember, forget
from pyramid.view import view_config
from ordr2.events import UserLogIn
from ordr2.models import User, Role
from ordr2.schemas.account import RegistrationSchema, SettingsSchema
@ -39,6 +40,8 @@ def login(context, request): @@ -39,6 +40,8 @@ def login(context, request):
if user is not None:
if user.is_active and user.check_password(password):
headers = remember(request, user.id)
event = UserLogIn(request, user)
request.registry.notify(event)
return HTTPFound(
request.resource_path(request.root, 'orders'),
headers=headers