mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	fix broken "failed login" signal
This commit is contained in:
		
							parent
							
								
									3a2a20cefd
								
							
						
					
					
						commit
						4a02865697
					
				@ -1,6 +1,6 @@
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.contrib import auth
 | 
			
		||||
from django.contrib.auth.middleware import RemoteUserMiddleware
 | 
			
		||||
from django.contrib.auth.middleware import PersistentRemoteUserMiddleware
 | 
			
		||||
from django.contrib.auth.models import User
 | 
			
		||||
from django.utils.deprecation import MiddlewareMixin
 | 
			
		||||
from rest_framework import authentication
 | 
			
		||||
@ -37,7 +37,7 @@ class AngularApiAuthenticationOverride(authentication.BaseAuthentication):
 | 
			
		||||
            return None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class HttpRemoteUserMiddleware(RemoteUserMiddleware):
 | 
			
		||||
class HttpRemoteUserMiddleware(PersistentRemoteUserMiddleware):
 | 
			
		||||
    """This class allows authentication via HTTP_REMOTE_USER which is set for
 | 
			
		||||
    example by certain SSO applications.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
@ -12,22 +12,21 @@ def handle_failed_login(sender, credentials, request, **kwargs):
 | 
			
		||||
    client_ip, _ = ipware.get_client_ip(
 | 
			
		||||
        meta=request.META,
 | 
			
		||||
    )
 | 
			
		||||
    username = credentials.get("username") or "anonymous"
 | 
			
		||||
 | 
			
		||||
    if client_ip is None:
 | 
			
		||||
        logger.info(
 | 
			
		||||
            f"Login failed for user `{credentials['username']}`."
 | 
			
		||||
            " Unable to determine IP address.",
 | 
			
		||||
            f"Login failed for user `{username}`. Unable to determine IP address.",
 | 
			
		||||
        )
 | 
			
		||||
    else:
 | 
			
		||||
        if client_ip.is_global:
 | 
			
		||||
            # We got the client's IP address
 | 
			
		||||
            logger.info(
 | 
			
		||||
                f"Login failed for user `{credentials['username']}`"
 | 
			
		||||
                f" from IP `{client_ip}.`",
 | 
			
		||||
                f"Login failed for user `{username}` from IP `{client_ip}.`",
 | 
			
		||||
            )
 | 
			
		||||
        else:
 | 
			
		||||
            # The client's IP address is private
 | 
			
		||||
            logger.info(
 | 
			
		||||
                f"Login failed for user `{credentials['username']}`"
 | 
			
		||||
                f"Login failed for user `{username}`"
 | 
			
		||||
                f" from private IP `{client_ip}.`",
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user