Django : intercept authentication to store session variable or cookie -
i working on project that's running on django. authenticate in multiple places. first, maintain standard authentication mechanism , continue using site administration. second, intercept login request in addition standard authentication, , check if user has authenticated on system , store session variable or cookie used later if authenticated. on logout remove session variable or cookie. second authentication mechanism should not affect first. in addition, if first succeeds , second fails, should have no affect on standard administration.
i have looked declaring custom authentication backend in settings authentication_backends tuple. understand, authenticates in order , stop authenticating once match made.
any guidance in regards appreciated.
if need set , unset cookie or session var can use signals sent authentication module (docs)
example:
from django.contrib.auth.signals import user_logged_in, user_logged_out def user_logged_in_hook(sender, **kwargs): # kwargs contain request , user objects print kwargs def user_logged_out_hook(sender, **kwargs): # kwargs contain request , user objects print kwargs user_logged_in.connect(user_logged_in_hook) user_logged_out.connect(user_logged_out_hook)
Comments
Post a Comment