audit: fix failed login events not being logged
This commit is contained in:
		@ -37,9 +37,7 @@
 | 
				
			|||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
                    </th>
 | 
					                    </th>
 | 
				
			||||||
                    <td role="cell">
 | 
					                    <td role="cell">
 | 
				
			||||||
                        <span>
 | 
					                        <code>{{ entry.context }}</code>
 | 
				
			||||||
                            {{ entry.context }}
 | 
					 | 
				
			||||||
                        </span>
 | 
					 | 
				
			||||||
                    </td>
 | 
					                    </td>
 | 
				
			||||||
                    <td role="cell">
 | 
					                    <td role="cell">
 | 
				
			||||||
                        <span>
 | 
					                        <span>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,35 +1,53 @@
 | 
				
			|||||||
"""passbook audit signal listener"""
 | 
					"""passbook audit signal listener"""
 | 
				
			||||||
from django.contrib.auth.signals import user_logged_in, user_logged_out
 | 
					from typing import Dict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.contrib.auth.signals import (
 | 
				
			||||||
 | 
					    user_logged_in,
 | 
				
			||||||
 | 
					    user_logged_out,
 | 
				
			||||||
 | 
					    user_login_failed,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
from django.dispatch import receiver
 | 
					from django.dispatch import receiver
 | 
				
			||||||
 | 
					from django.http import HttpRequest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from passbook.audit.models import Event, EventAction
 | 
					from passbook.audit.models import Event, EventAction
 | 
				
			||||||
 | 
					from passbook.core.models import User
 | 
				
			||||||
from passbook.core.signals import invitation_created, invitation_used, user_signed_up
 | 
					from passbook.core.signals import invitation_created, invitation_used, user_signed_up
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@receiver(user_logged_in)
 | 
					@receiver(user_logged_in)
 | 
				
			||||||
# pylint: disable=unused-argument
 | 
					# pylint: disable=unused-argument
 | 
				
			||||||
def on_user_logged_in(sender, request, user, **_):
 | 
					def on_user_logged_in(sender, request: HttpRequest, user: User, **_):
 | 
				
			||||||
    """Log successful login"""
 | 
					    """Log successful login"""
 | 
				
			||||||
    Event.new(EventAction.LOGIN).from_http(request)
 | 
					    Event.new(EventAction.LOGIN).from_http(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@receiver(user_logged_out)
 | 
					@receiver(user_logged_out)
 | 
				
			||||||
# pylint: disable=unused-argument
 | 
					# pylint: disable=unused-argument
 | 
				
			||||||
def on_user_logged_out(sender, request, user, **_):
 | 
					def on_user_logged_out(sender, request: HttpRequest, user: User, **_):
 | 
				
			||||||
    """Log successfully logout"""
 | 
					    """Log successfully logout"""
 | 
				
			||||||
    Event.new(EventAction.LOGOUT).from_http(request)
 | 
					    Event.new(EventAction.LOGOUT).from_http(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@receiver(user_login_failed)
 | 
				
			||||||
 | 
					# pylint: disable=unused-argument
 | 
				
			||||||
 | 
					def on_user_login_failed(
 | 
				
			||||||
 | 
					    sender, credentials: Dict[str, str], request: HttpRequest, **_
 | 
				
			||||||
 | 
					):
 | 
				
			||||||
 | 
					    """Failed Login"""
 | 
				
			||||||
 | 
					    credentials.pop("password")
 | 
				
			||||||
 | 
					    Event.new(EventAction.LOGIN_FAILED, **credentials).from_http(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@receiver(user_signed_up)
 | 
					@receiver(user_signed_up)
 | 
				
			||||||
# pylint: disable=unused-argument
 | 
					# pylint: disable=unused-argument
 | 
				
			||||||
def on_user_signed_up(sender, request, user, **_):
 | 
					def on_user_signed_up(sender, request: HttpRequest, user: User, **_):
 | 
				
			||||||
    """Log successfully signed up"""
 | 
					    """Log successfully signed up"""
 | 
				
			||||||
    Event.new(EventAction.SIGN_UP).from_http(request)
 | 
					    Event.new(EventAction.SIGN_UP).from_http(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@receiver(invitation_created)
 | 
					@receiver(invitation_created)
 | 
				
			||||||
# pylint: disable=unused-argument
 | 
					# pylint: disable=unused-argument
 | 
				
			||||||
def on_invitation_created(sender, request, invitation, **_):
 | 
					def on_invitation_created(sender, request: HttpRequest, invitation, **_):
 | 
				
			||||||
    """Log Invitation creation"""
 | 
					    """Log Invitation creation"""
 | 
				
			||||||
    Event.new(
 | 
					    Event.new(
 | 
				
			||||||
        EventAction.INVITE_CREATED, invitation_uuid=invitation.uuid.hex
 | 
					        EventAction.INVITE_CREATED, invitation_uuid=invitation.uuid.hex
 | 
				
			||||||
@ -38,7 +56,7 @@ def on_invitation_created(sender, request, invitation, **_):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@receiver(invitation_used)
 | 
					@receiver(invitation_used)
 | 
				
			||||||
# pylint: disable=unused-argument
 | 
					# pylint: disable=unused-argument
 | 
				
			||||||
def on_invitation_used(sender, request, invitation, **_):
 | 
					def on_invitation_used(sender, request: HttpRequest, invitation, **_):
 | 
				
			||||||
    """Log Invitation usage"""
 | 
					    """Log Invitation usage"""
 | 
				
			||||||
    Event.new(EventAction.INVITE_USED, invitation_uuid=invitation.uuid.hex).from_http(
 | 
					    Event.new(EventAction.INVITE_USED, invitation_uuid=invitation.uuid.hex).from_http(
 | 
				
			||||||
        request
 | 
					        request
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user