2018-12-10 12:47:51 +00:00
|
|
|
"""passbook audit signal listener"""
|
2019-03-03 19:13:54 +00:00
|
|
|
from django.contrib.auth.signals import user_logged_in, user_logged_out
|
2018-12-10 12:47:51 +00:00
|
|
|
from django.dispatch import receiver
|
|
|
|
|
2019-10-28 13:26:34 +00:00
|
|
|
from passbook.audit.models import Event
|
2018-12-10 13:21:42 +00:00
|
|
|
from passbook.core.signals import (invitation_created, invitation_used,
|
|
|
|
user_signed_up)
|
2018-12-10 12:47:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(user_logged_in)
|
|
|
|
def on_user_logged_in(sender, request, user, **kwargs):
|
|
|
|
"""Log successful login"""
|
2019-10-28 13:26:34 +00:00
|
|
|
Event.create(Event.ACTION_LOGIN, request)
|
2018-12-10 12:47:51 +00:00
|
|
|
|
|
|
|
@receiver(user_logged_out)
|
|
|
|
def on_user_logged_out(sender, request, user, **kwargs):
|
|
|
|
"""Log successfully logout"""
|
2019-10-28 13:26:34 +00:00
|
|
|
Event.create(Event.ACTION_LOGOUT, request)
|
2018-12-10 12:47:51 +00:00
|
|
|
|
2018-12-10 13:05:27 +00:00
|
|
|
@receiver(user_signed_up)
|
|
|
|
def on_user_signed_up(sender, request, user, **kwargs):
|
|
|
|
"""Log successfully signed up"""
|
2019-10-28 13:26:34 +00:00
|
|
|
Event.create(Event.ACTION_SIGN_UP, request)
|
2018-12-10 13:05:27 +00:00
|
|
|
|
2018-12-10 13:21:42 +00:00
|
|
|
@receiver(invitation_created)
|
|
|
|
def on_invitation_created(sender, request, invitation, **kwargs):
|
2018-12-10 13:49:15 +00:00
|
|
|
"""Log Invitation creation"""
|
2019-10-28 13:26:34 +00:00
|
|
|
Event.create(Event.ACTION_INVITE_CREATED, request,
|
2018-12-10 14:26:28 +00:00
|
|
|
invitation_uuid=invitation.uuid.hex)
|
2018-12-10 13:05:27 +00:00
|
|
|
|
2018-12-10 13:21:42 +00:00
|
|
|
@receiver(invitation_used)
|
|
|
|
def on_invitation_used(sender, request, invitation, **kwargs):
|
2018-12-10 13:49:15 +00:00
|
|
|
"""Log Invitation usage"""
|
2019-10-28 13:26:34 +00:00
|
|
|
Event.create(Event.ACTION_INVITE_USED, request,
|
2018-12-10 14:26:28 +00:00
|
|
|
invitation_uuid=invitation.uuid.hex)
|