Record basic user login/logout events

This commit is contained in:
Lance Edgar 2017-08-04 16:48:33 -05:00
parent eaa47dbd8a
commit 82e8f49dd1

View file

@ -28,6 +28,8 @@ from __future__ import unicode_literals, absolute_import
import logging
from rattail import enum
from rattail.db import model
from rattail.util import prettify, NOTSET
from zope.interface import implementer
@ -45,6 +47,7 @@ def login_user(request, user, timeout=NOTSET):
Perform the steps necessary to login the given user. Note that this
returns a ``headers`` dict which you should pass to the redirect.
"""
user.record_event(enum.USER_EVENT_LOGIN)
headers = remember(request, user.uuid)
if timeout is NOTSET:
timeout = session_timeout_for_user(user)
@ -58,6 +61,9 @@ def logout_user(request):
Perform the logout action for the given request. Note that this returns a
``headers`` dict which you should pass to the redirect.
"""
user = request.user
if user:
user.record_event(enum.USER_EVENT_LOGOUT)
request.session.delete()
request.session.invalidate()
headers = forget(request)