0001-don-t-use-context_instance-in-rendering-functions-25.patch
src/authentic2/auth2_auth/auth2_ssl/views.py | ||
---|---|---|
1 | 1 |
import logging |
2 | 2 | |
3 | 3 |
from django.utils.translation import ugettext as _ |
4 |
from django.shortcuts import render_to_response, render
|
|
4 |
from django.shortcuts import render |
|
5 | 5 |
from django.views.decorators.csrf import csrf_exempt |
6 | 6 |
from django.views.generic.base import TemplateView |
7 |
from django.template import RequestContext |
|
8 | 7 |
from django.template.loader import render_to_string |
9 | 8 |
from django.contrib import messages |
10 | 9 |
from django.contrib.auth.forms import AuthenticationForm |
... | ... | |
57 | 56 | |
58 | 57 |
# No SSL entries and no user session, redirect account linking page |
59 | 58 |
if not user and not request.user.is_authenticated(): |
60 |
return render_to_response('auth/account_linking_ssl.html', |
|
61 |
context_instance=RequestContext(request)) |
|
59 |
return render(request, 'auth/account_linking_ssl.html') |
|
62 | 60 | |
63 | 61 |
# No SSL entries but active user session, perform account linking |
64 | 62 |
if not user and request.user.is_authenticated(): |
... | ... | |
128 | 126 |
return render(request, 'auth/account_linking_ssl.html') |
129 | 127 | |
130 | 128 |
def profile(request, template_name='ssl/profile.html', *args, **kwargs): |
131 |
context_instance = kwargs.pop('context_instance', None) or \ |
|
132 |
RequestContext(request) |
|
129 |
context = kwargs.pop('context', {}) |
|
133 | 130 |
certificates = models.ClientCertificate.objects.filter(user=request.user) |
134 |
ctx = { 'certificates': certificates } |
|
135 |
return render_to_string(template_name, ctx, |
|
136 |
context_instance=context_instance) |
|
131 |
context.update({'certificates': certificates}) |
|
132 |
return render_to_string(template_name, context, request=request) |
|
137 | 133 | |
138 | 134 |
def delete_certificate(request, certificate_pk): |
139 | 135 |
qs = models.ClientCertificate.objects.filter(pk=certificate_pk) |
src/authentic2/auth_frontends.py | ||
---|---|---|
17 | 17 |
return 'password' |
18 | 18 | |
19 | 19 |
def login(self, request, *args, **kwargs): |
20 |
context_instance = kwargs.get('context_instance', None)
|
|
20 |
context = kwargs.get('context', {})
|
|
21 | 21 |
is_post = request.method == 'POST' and self.submit_name in request.POST |
22 | 22 |
data = request.POST if is_post else None |
23 | 23 |
form = forms.AuthenticationForm(request=request, data=data) |
... | ... | |
26 | 26 |
if app_settings.A2_USERNAME_LABEL: |
27 | 27 |
form.fields['username'].label = app_settings.A2_USERNAME_LABEL |
28 | 28 |
is_secure = request.is_secure |
29 |
context = { |
|
30 |
'submit_name': self.submit_name, |
|
31 |
} |
|
29 |
context['submit_name'] = self.submit_name |
|
32 | 30 |
if is_post: |
33 | 31 |
utils.csrf_token_check(request, form) |
34 | 32 |
if form.is_valid(): |
... | ... | |
39 | 37 |
return utils.login(request, form.get_user(), how, |
40 | 38 |
service_slug=request.GET.get(constants.SERVICE_FIELD_NAME)) |
41 | 39 |
context['form'] = form |
42 |
return render(request, 'authentic2/login_password_form.html', context, |
|
43 |
context_instance=context_instance) |
|
40 |
return render(request, 'authentic2/login_password_form.html', context) |
|
44 | 41 | |
45 | 42 |
def profile(self, request, *args, **kwargs): |
46 | 43 |
return views.login_password_profile(request, *args, **kwargs) |
src/authentic2/idp/interactions.py | ||
---|---|---|
1 | 1 |
from django.contrib.auth.decorators import login_required |
2 | 2 |
from django.http import HttpResponseRedirect |
3 |
from django.template import RequestContext |
|
4 |
from django.shortcuts import render_to_response |
|
3 |
from django.shortcuts import render |
|
5 | 4 | |
6 | 5 |
from authentic2.saml.models import LibertyProvider |
7 | 6 | |
... | ... | |
11 | 10 |
'''On a GET produce a form asking for consentment, |
12 | 11 |
On a POST handle the form and redirect to next''' |
13 | 12 |
if request.method == "GET": |
14 |
return render_to_response('interaction/consent_federation.html',
|
|
13 |
return render(request, 'interaction/consent_federation.html',
|
|
15 | 14 |
{'provider_id': request.GET.get('provider_id', ''), |
16 | 15 |
'nonce': request.GET.get('nonce', ''), |
17 |
'next': request.GET.get('next', '')}, |
|
18 |
context_instance=RequestContext(request)) |
|
16 |
'next': request.GET.get('next', '')}) |
|
19 | 17 |
else: |
20 | 18 |
next = '/' |
21 | 19 |
if 'next' in request.POST: |
... | ... | |
57 | 55 |
name = request.GET.get('provider_id', '') |
58 | 56 |
if provider: |
59 | 57 |
name = provider.name or name |
60 |
return render_to_response('interaction/consent_attributes.html',
|
|
58 |
return render(request, 'interaction/consent_attributes.html',
|
|
61 | 59 |
{'provider_id': name, |
62 | 60 |
'attributes': attributes, |
63 | 61 |
'allow_selection': request.session['allow_attributes_selection'], |
64 | 62 |
'nonce': request.GET.get('nonce', ''), |
65 |
'next': next}, |
|
66 |
context_instance=RequestContext(request)) |
|
63 |
'next': next}) |
|
67 | 64 | |
68 | 65 |
elif request.method == "POST": |
69 | 66 |
if request.session['allow_attributes_selection']: |
src/authentic2/registration_backend/views.py | ||
---|---|---|
14 | 14 |
from django.contrib.auth import get_user_model |
15 | 15 |
from django.forms import CharField, Form |
16 | 16 |
from django.core.urlresolvers import reverse_lazy |
17 |
from django.template import RequestContext |
|
18 | 17 |
from django.http import Http404, HttpResponseBadRequest |
19 | 18 | |
20 | 19 |
from authentic2.utils import (import_module_or_class, redirect, make_url, get_fields_and_labels, |
... | ... | |
92 | 91 |
return redirect(self.request, 'registration_complete') |
93 | 92 | |
94 | 93 |
def get_context_data(self, **kwargs): |
95 |
ctx = super(BaseRegistrationView, self).get_context_data(**kwargs) |
|
96 |
request_context = RequestContext(self.request) |
|
97 |
request_context.push(ctx) |
|
98 |
request_context['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
94 |
context = super(BaseRegistrationView, self).get_context_data(**kwargs) |
|
95 |
context['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
99 | 96 |
parameters = {'request': self.request, |
100 |
'context_instance': request_context}
|
|
97 |
'context': context}
|
|
101 | 98 |
blocks = [utils.get_backend_method(backend, 'registration', parameters) |
102 | 99 |
for backend in utils.get_backends('AUTH_FRONTENDS')] |
103 |
request_context['frontends'] = collections.OrderedDict((block['id'], block)
|
|
104 |
for block in blocks if block)
|
|
105 |
return request_context
|
|
100 |
context['frontends'] = collections.OrderedDict((block['id'], block) |
|
101 |
for block in blocks if block) |
|
102 |
return context |
|
106 | 103 | |
107 | 104 | |
108 | 105 |
class RegistrationView(cbv.ValidateCSRFMixin, BaseRegistrationView): |
src/authentic2/saml/common.py | ||
---|---|---|
9 | 9 |
import requests |
10 | 10 | |
11 | 11 |
from authentic2.compat_lasso import lasso |
12 |
from django.template import RequestContext |
|
13 | 12 |
from django.conf import settings |
14 | 13 |
from django.http import HttpResponseRedirect, Http404, HttpResponse |
15 |
from django.shortcuts import render_to_response
|
|
14 |
from django.shortcuts import render |
|
16 | 15 |
from django.core.exceptions import ValidationError |
17 | 16 | |
18 | 17 |
from authentic2.saml.models import (LibertyFederation, LibertyProvider, |
... | ... | |
181 | 180 | |
182 | 181 |
def return_saml2(request, profile, field_name, title=''): |
183 | 182 |
'''Helper to handle SAMLv2 bindings to emit request and responses''' |
184 |
context_instance = RequestContext(request) |
|
185 | 183 |
logger.debug('profile.msgBody: %r', profile.msgBody) |
186 | 184 |
logger.debug('profile.msgUrl: %r', profile.msgUrl) |
187 | 185 |
logger.debug('profile.msgRelayState: %r', profile.msgRelayState) |
188 | 186 |
logger.debug('field_name: %s', field_name) |
189 | 187 |
if profile.msgBody: |
190 | 188 |
if profile.msgUrl: |
191 |
return render_to_response( |
|
189 |
return render( |
|
190 |
request, |
|
192 | 191 |
'saml/post_form.html', |
193 | 192 |
{ |
194 | 193 |
'title': title, |
... | ... | |
196 | 195 |
'fieldname': field_name, |
197 | 196 |
'body': profile.msgBody, |
198 | 197 |
'relay_state': profile.msgRelayState |
199 |
}, |
|
200 |
context_instance=context_instance) |
|
198 |
}) |
|
201 | 199 |
return HttpResponse(profile.msgBody, content_type='text/xml') |
202 | 200 |
elif profile.msgUrl: |
203 | 201 |
return HttpResponseRedirect(profile.msgUrl) |
... | ... | |
503 | 501 |
back = '/' |
504 | 502 |
redirection_timeout = getattr(settings, 'REDIRECTION_TIMEOUT_AFTER_ERROR', |
505 | 503 |
2000) |
506 |
return render_to_response('error.html', |
|
507 |
{ |
|
508 |
'msg': message, |
|
509 |
'back': back, |
|
510 |
'redir_timeout': redirection_timeout |
|
511 |
}, |
|
512 |
context_instance=RequestContext(request)) |
|
504 |
return render(request, 'error.html', |
|
505 |
{ |
|
506 |
'msg': message, |
|
507 |
'back': back, |
|
508 |
'redir_timeout': redirection_timeout |
|
509 |
}) |
|
513 | 510 | |
514 | 511 | |
515 | 512 |
def redirect_next(request, next): |
src/authentic2/views.py | ||
---|---|---|
9 | 9 | |
10 | 10 |
from django.conf import settings |
11 | 11 |
from django.shortcuts import render_to_response, render |
12 |
from django.template import RequestContext |
|
13 | 12 |
from django.template.loader import render_to_string, select_template |
14 | 13 |
from django.views.generic.edit import UpdateView, FormView |
15 | 14 |
from django.views.generic import RedirectView, TemplateView |
... | ... | |
290 | 289 |
registration_url = utils.get_registration_url( |
291 | 290 |
request, service_slug=request.GET.get(constants.SERVICE_FIELD_NAME)) |
292 | 291 | |
293 |
context_instance = RequestContext(request, {
|
|
292 |
context = {
|
|
294 | 293 |
'cancel': nonce is not None, |
295 | 294 |
'can_reset_password': app_settings.A2_CAN_RESET_PASSWORD, |
296 | 295 |
'registration_authorized': getattr(settings, 'REGISTRATION_OPEN', True), |
297 | 296 |
'registration_url': registration_url, |
298 |
})
|
|
299 |
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
|
|
297 |
} |
|
298 |
context['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
300 | 299 | |
301 | 300 |
# Cancel button |
302 | 301 |
if request.method == "POST" \ |
... | ... | |
328 | 327 |
blocks.append(block) |
329 | 328 |
else: # New frontends API |
330 | 329 |
parameters = {'request': request, |
331 |
'context_instance': context_instance}
|
|
330 |
'context': context}
|
|
332 | 331 |
block = utils.get_backend_method(frontend, 'login', parameters) |
333 | 332 |
# If a login frontend method returns an HttpResponse with a status code != 200 |
334 | 333 |
# this response is returned. |
... | ... | |
348 | 347 |
if not 'form' in block: |
349 | 348 |
continue |
350 | 349 |
frontend = block['frontend'] |
351 |
context = {
|
|
350 |
context.update({
|
|
352 | 351 |
'submit_name': 'submit-%s' % fid, |
353 | 352 |
redirect_field_name: redirect_to, |
354 | 353 |
'form': block['form'] |
355 |
} |
|
354 |
})
|
|
356 | 355 |
if hasattr(frontend, 'get_context'): |
357 | 356 |
context.update(frontend.get_context()) |
358 | 357 |
sub_template_name = frontend.template() |
359 | 358 |
block['content'] = render_to_string( |
360 | 359 |
sub_template_name, context, |
361 |
context_instance=context_instance)
|
|
360 |
request=request)
|
|
362 | 361 | |
363 | 362 |
request.session.set_test_cookie() |
364 | 363 | |
365 | 364 |
# legacy context variable |
366 | 365 |
rendered_forms = [(block['name'], block['content']) for block in blocks] |
367 | ||
368 |
return render_to_response(template_name, { |
|
366 |
context.update({ |
|
369 | 367 |
'methods': rendered_forms, |
370 | 368 |
# new definition |
371 | 369 |
'blocks': collections.OrderedDict((block['id'], block) for block in blocks), |
372 | 370 |
redirect_field_name: redirect_to, |
373 |
}, context_instance=context_instance) |
|
371 |
}) |
|
372 |
return render(request, template_name, context) |
|
374 | 373 | |
375 | 374 | |
376 | 375 |
def service_list(request): |
... | ... | |
405 | 404 |
return super(ProfileView, self).dispatch(request, *args, **kwargs) |
406 | 405 | |
407 | 406 |
def get_context_data(self, **kwargs): |
408 |
ctx = super(ProfileView, self).get_context_data(**kwargs)
|
|
407 |
context = super(ProfileView, self).get_context_data(**kwargs)
|
|
409 | 408 |
frontends = utils.get_backends('AUTH_FRONTENDS') |
410 | 409 | |
411 | 410 |
request = self.request |
412 | 411 | |
413 |
context_instance = RequestContext(request, ctx) |
|
414 |
context_instance['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
412 |
context['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
415 | 413 |
if request.method == "POST": |
416 | 414 |
for frontend in frontends: |
417 | 415 |
if 'submit-%s' % frontend.id in request.POST: |
... | ... | |
481 | 479 | |
482 | 480 |
# Credentials management |
483 | 481 |
parameters = {'request': request, |
484 |
'context_instance': context_instance}
|
|
482 |
'context': context}
|
|
485 | 483 |
profiles = [utils.get_backend_method(frontend, 'profile', parameters) |
486 | 484 |
for frontend in frontends] |
487 | 485 |
# Old frontends data structure for templates |
... | ... | |
496 | 494 |
for idp_backend in idp_backends: |
497 | 495 |
if hasattr(idp_backend, 'federation_management'): |
498 | 496 |
federation_management.extend(idp_backend.federation_management(request)) |
499 |
context_instance.update({
|
|
497 |
context.update({ |
|
500 | 498 |
'frontends_block': blocks, |
501 | 499 |
'frontends_block_by_id': blocks_by_id, |
502 | 500 |
'profile': profile, |
... | ... | |
508 | 506 |
'allow_password_change': request.user.can_change_password(), |
509 | 507 |
'federation_management': federation_management, |
510 | 508 |
}) |
511 |
hooks.call_hooks('modify_context_data', self, context_instance)
|
|
512 |
return context_instance
|
|
509 |
hooks.call_hooks('modify_context_data', self, context) |
|
510 |
return context |
|
513 | 511 | |
514 | 512 |
profile = login_required(ProfileView.as_view()) |
515 | 513 | |
... | ... | |
583 | 581 | |
584 | 582 | |
585 | 583 |
def login_password_profile(request, *args, **kwargs): |
586 |
context_instance = kwargs.pop('context_instance', None) or RequestContext(request)
|
|
584 |
context = kwargs.pop('context', {})
|
|
587 | 585 |
can_change_password = app_settings.A2_REGISTRATION_CAN_CHANGE_PASSWORD |
588 | 586 |
has_usable_password = request.user.has_usable_password() |
587 |
context.update( |
|
588 |
{'can_change_password': can_change_password, |
|
589 |
'has_usable_password': has_usable_password}) |
|
589 | 590 |
return render_to_string(['auth/login_password_profile.html', |
590 | 591 |
'authentic2/login_password_profile.html'], |
591 |
{'can_change_password' : can_change_password, |
|
592 |
'has_usable_password' : has_usable_password}, |
|
593 |
context_instance=context_instance) |
|
592 |
context, request=request) |
|
594 | 593 | |
595 | 594 | |
596 | 595 |
class LoggedInView(View): |
src/authentic2_auth_oidc/auth_frontends.py | ||
---|---|---|
15 | 15 |
return 'oidc' |
16 | 16 | |
17 | 17 |
def login(self, request, *args, **kwargs): |
18 |
context_instance = kwargs.get('context_instance', None) |
|
19 |
ctx = { |
|
20 |
'providers': utils.get_providers(shown=True), |
|
21 |
} |
|
22 |
return render(request, 'authentic2_auth_oidc/login.html', ctx, |
|
23 |
context_instance=context_instance) |
|
18 |
context = kwargs.get('context', {}) |
|
19 |
context['providers'] = utils.get_providers(shown=True) |
|
20 |
return render(request, 'authentic2_auth_oidc/login.html', context) |
src/authentic2_auth_saml/auth_frontends.py | ||
---|---|---|
1 | 1 |
from django.utils.translation import gettext_noop |
2 | 2 |
from django.template.loader import render_to_string |
3 |
from django.template import RequestContext |
|
4 | 3 |
from django.shortcuts import render |
5 | 4 |
from mellon.utils import get_idp, get_idps |
6 | 5 | |
... | ... | |
19 | 18 |
return gettext_noop('SAML') |
20 | 19 | |
21 | 20 |
def login(self, request, *args, **kwargs): |
22 |
context_instance = kwargs.pop('context_instance', None) or RequestContext(request)
|
|
21 |
context = kwargs.pop('context', {})
|
|
23 | 22 |
submit_name = 'login-%s' % self.id |
23 |
context['submit_name'] = submit_name |
|
24 | 24 |
if request.method == 'POST' and submit_name in request.POST: |
25 | 25 |
return redirect_to_login(request, login_url='mellon_login') |
26 |
return render(request, 'authentic2_auth_saml/login.html', {'submit_name': submit_name}, |
|
27 |
context_instance=context_instance) |
|
26 |
return render(request, 'authentic2_auth_saml/login.html', context) |
|
28 | 27 | |
29 | 28 |
def profile(self, request, *args, **kwargs): |
30 |
context_instance = kwargs.pop('context_instance', None) or RequestContext(request)
|
|
29 |
context = kwargs.pop('context', {})
|
|
31 | 30 |
user_saml_identifiers = request.user.saml_identifiers.all() |
32 | 31 |
if not user_saml_identifiers: |
33 | 32 |
return '' |
34 | 33 |
for user_saml_identifier in user_saml_identifiers: |
35 | 34 |
user_saml_identifier.idp = get_idp(user_saml_identifier.issuer) |
35 |
context['user_saml_identifiers'] = user_saml_identifiers |
|
36 | 36 |
return render_to_string('authentic2_auth_saml/profile.html', |
37 |
{'user_saml_identifiers': user_saml_identifiers}, |
|
38 |
context_instance=context_instance) |
|
37 |
context, request=request) |
|
39 |
- |