Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Demo User.last_login handler #52

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ramses_example/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def encrypt(**kwargs):
return new_value


@registry.add
def set_last_login(event):
from datetime import datetime
from nefertari import engine
User = engine.get_document_cls('User')
login = event.fields['login'].new_value
field = 'email' if '@' in login else 'username'
user = User.get_item(**{field: login})
if user is not None:
user.update({'last_login': datetime.now()},
event.view.request)


def main(global_config, **settings):
config = Configurator(settings=settings)
config.include('ramses')
Expand Down
3 changes: 3 additions & 0 deletions schemas/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"_hidden_fields": ["password"],
"_nested_relationships": ["profile"],
"_auth_model": true,
"_event_handlers": {
"after_login": ["set_last_login"]
},
"required": ["username", "email", "password"],
"properties": {
"created_at": {
Expand Down