in pulseapi/users/utils.py [0:0]
def augmented_get_context_data(self, **kwargs):
"""
Patch allauth's LoginView.get_context_data class function
so that we can check for a recaptcha-related session value
if we're using recaptcha. Allauth only has post-processing
signals, so we're kind of left with monkey patching as the
only way to pre-process the login route.
"""
if settings.USE_RECAPTCHA:
request = self.request
session = request.session
if 'recaptcha_token' not in session:
raise PermissionDenied()
session_token = session['recaptcha_token']
# clear the token after reading it so someone can't just set a valid session and then
# bulk-load the allauth route with a hundred tabs.
session['recaptcha_token'] = None
if session_token is None:
raise PermissionDenied()
client_token = request.GET.get('token', None)
if client_token is None:
raise PermissionDenied()
if client_token != session_token:
raise PermissionDenied()
return __old_get_context_data(self, **kwargs)