I want to add a custom pre-login signal (user_logging_in) that fires just before Django's login function is called. This is a snippet from our custom account app that may explain what I want:
from django.contrib.auth import login as real_login
def custom_login(....)
# Allow other apps to perform pre-login validation.
from . import signals
signals.user_logging_in.send(sender=None, request=request, user=user)
# Perform the login using Django's code.
real_login(request, user)
We have a custom licencing engine that we call to in our custom login function to validate the user's licence:
return validate_license(user, request, license, **kwargs)
So, if the user's licence has expired then they aren't actually logged in and are re-directed back to the login page. This validate_license function can return HTTP statuses as required.
The licence engine is currently tightly coupled into our custom account app.
I'm trying to work out if I can get the Licence engine to subscribe to the above custom signal so that I can decouple it from our account app. However I don't understand how I would get the Licence engine to influence the response sent to the browser.
Any suggestions greatly appreciated.
Thanks