0011-add-support-for-django-1.11-in-views-21489.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) |
|
133 | 129 |
certificates = models.ClientCertificate.objects.filter(user=request.user) |
134 | 130 |
ctx = { 'certificates': certificates } |
135 |
return render_to_string(template_name, ctx, |
|
136 |
context_instance=context_instance) |
|
131 |
return render_to_string(template_name, context=ctx, request=request) |
|
137 | 132 | |
138 | 133 |
def delete_certificate(request, certificate_pk): |
139 | 134 |
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) |
|
21 | 20 |
is_post = request.method == 'POST' and self.submit_name in request.POST |
22 | 21 |
data = request.POST if is_post else None |
23 | 22 |
form = forms.AuthenticationForm(request=request, data=data) |
... | ... | |
39 | 38 |
return utils.login(request, form.get_user(), how, |
40 | 39 |
service_slug=request.GET.get(constants.SERVICE_FIELD_NAME)) |
41 | 40 |
context['form'] = form |
42 |
return render(request, 'authentic2/login_password_form.html', context, |
|
43 |
context_instance=context_instance) |
|
41 |
return render(request, 'authentic2/login_password_form.html', context=context) |
|
44 | 42 | |
45 | 43 |
def profile(self, request, *args, **kwargs): |
46 | 44 |
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', context=
|
|
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', context=
|
|
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/idp/saml/backend.py | ||
---|---|---|
123 | 123 |
url = '{0}?provider_id={1}&nonce={2}'.format( |
124 | 124 |
url, urllib.quote(provider_id), nonce) |
125 | 125 |
name = name or provider_id |
126 |
code = render_to_string('idp/saml/logout_fragment.html', { |
|
126 |
code = render_to_string('idp/saml/logout_fragment.html', context={
|
|
127 | 127 |
'needs_iframe': policy.needs_iframe_logout, |
128 | 128 |
'name': name, 'url': url, |
129 | 129 |
'iframe_timeout': policy.iframe_logout_timeout}) |
src/authentic2/idp/saml/saml2_endpoints.py | ||
---|---|---|
46 | 46 |
from authentic2.compat import get_user_model |
47 | 47 |
import authentic2.views as a2_views |
48 | 48 |
from authentic2.saml.models import (LibertyArtifact, |
49 |
LibertySession, LibertyFederation,
|
|
49 |
LibertySession, LibertyFederation, |
|
50 | 50 |
nameid2kwargs, saml2_urn_to_nidformat, |
51 | 51 |
nidformat_to_saml2_urn, save_key_values, get_and_delete_key_values, |
52 | 52 |
LibertyProvider, LibertyServiceProvider, SAMLAttribute, NAME_ID_FORMATS) |
... | ... | |
488 | 488 |
add_url += '?' + urllib.urlencode({ 'entity_id': provider_id }) |
489 | 489 |
return render(request, |
490 | 490 |
'idp/saml/unknown_provider.html', |
491 |
{ 'entity_id': provider_id, |
|
491 |
context={ 'entity_id': provider_id,
|
|
492 | 492 |
'add_url': add_url, |
493 | 493 |
}) |
494 | 494 |
else: |
... | ... | |
1566 | 1566 |
logger.info('return from redirect') |
1567 | 1567 |
relay_state = request.GET.get('RelayState') |
1568 | 1568 |
if not relay_state: |
1569 |
return error_redirect(request, N_('slo no relay state in response'),
|
|
1569 |
return error_redirect(request, N_('slo no relay state in response'), |
|
1570 | 1570 |
default_url=icon_url('ko')) |
1571 | 1571 |
logger.debug('relay_state %r', relay_state) |
1572 | 1572 |
try: |
src/authentic2/manager/user_views.py | ||
---|---|---|
7 | 7 |
from django.utils.encoding import force_bytes |
8 | 8 |
from django.utils.html import format_html |
9 | 9 |
from django.core.mail import EmailMultiAlternatives |
10 |
from django.template import loader
|
|
10 |
from django.template.loader import render_to_string
|
|
11 | 11 |
from django.core.urlresolvers import reverse |
12 | 12 |
from django.contrib.auth import get_user_model |
13 | 13 |
from django.contrib import messages |
... | ... | |
221 | 221 |
""" |
222 | 222 |
Sends a django.core.mail.EmailMultiAlternatives to `to_email`. |
223 | 223 |
""" |
224 |
subject = loader.render_to_string(subject_template_name, context)
|
|
224 |
subject = render_to_string(subject_template_name, context=context)
|
|
225 | 225 |
# Email subject *must not* contain newlines |
226 | 226 |
subject = ''.join(subject.splitlines()) |
227 |
body = loader.render_to_string(email_template_name, context)
|
|
227 |
body = render_to_string(email_template_name, context=context)
|
|
228 | 228 | |
229 | 229 |
email_message = EmailMultiAlternatives(subject, body, to=[to_email]) |
230 | 230 |
email_message.send() |
src/authentic2/middleware.py | ||
---|---|---|
220 | 220 |
if not some_message: |
221 | 221 |
return response |
222 | 222 |
return render(request, 'authentic2/display_message_and_continue.html', |
223 |
{'url': url, 'only_info': only_info}) |
|
223 |
context={'url': url, 'only_info': only_info})
|
|
224 | 224 | |
225 | 225 | |
226 | 226 |
class ServiceAccessControlMiddleware(object): |
src/authentic2/registration_backend/forms.py | ||
---|---|---|
6 | 6 |
from django.core.exceptions import ValidationError |
7 | 7 |
from django.utils.translation import ugettext_lazy as _, ugettext |
8 | 8 |
from django.forms import ModelForm, Form, CharField, PasswordInput, EmailField |
9 |
from django.utils.datastructures import SortedDict |
|
10 | 9 |
from django.db.models.fields import FieldDoesNotExist |
11 |
from django.forms.util import ErrorList |
|
10 |
from django.forms.utils import ErrorList
|
|
12 | 11 | |
13 | 12 |
from django.contrib.auth.models import BaseUserManager, Group |
14 | 13 |
from django.contrib.auth import forms as auth_forms, get_user_model, REDIRECT_FIELD_NAME |
15 | 14 |
from django.core.mail import send_mail |
16 | 15 |
from django.core import signing |
17 |
from django.template import RequestContext |
|
18 |
from django.template.loader import render_to_string |
|
19 | 16 |
from django.core.urlresolvers import reverse |
20 | 17 |
from django.core.validators import RegexValidator |
21 | 18 |
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(request,
|
|
192 | 190 |
'saml/post_form.html', |
193 |
{ |
|
191 |
context={
|
|
194 | 192 |
'title': title, |
195 | 193 |
'url': profile.msgUrl, |
196 | 194 |
'fieldname': field_name, |
197 | 195 |
'body': profile.msgBody, |
198 | 196 |
'relay_state': profile.msgRelayState |
199 |
}, |
|
200 |
context_instance=context_instance) |
|
197 |
}) |
|
201 | 198 |
return HttpResponse(profile.msgBody, content_type='text/xml') |
202 | 199 |
elif profile.msgUrl: |
203 | 200 |
return HttpResponseRedirect(profile.msgUrl) |
... | ... | |
503 | 500 |
back = '/' |
504 | 501 |
redirection_timeout = getattr(settings, 'REDIRECTION_TIMEOUT_AFTER_ERROR', |
505 | 502 |
2000) |
506 |
return render_to_response('error.html',
|
|
507 |
{ |
|
503 |
return render(request, 'error.html',
|
|
504 |
context={
|
|
508 | 505 |
'msg': message, |
509 | 506 |
'back': back, |
510 | 507 |
'redir_timeout': redirection_timeout |
511 |
}, |
|
512 |
context_instance=RequestContext(request)) |
|
508 |
}) |
|
513 | 509 | |
514 | 510 | |
515 | 511 |
def redirect_next(request, next): |
src/authentic2/utils.py | ||
---|---|---|
23 | 23 |
HASH_SESSION_KEY, BACKEND_SESSION_KEY, authenticate, |
24 | 24 |
get_user_model) |
25 | 25 |
from django import forms |
26 |
from django.forms.util import ErrorList |
|
26 |
from django.forms.utils import ErrorList
|
|
27 | 27 |
from django.forms.utils import to_current_timezone |
28 | 28 |
from django.utils import timezone |
29 | 29 |
from django.utils import html, http |
... | ... | |
36 | 36 |
from django.utils.formats import localize |
37 | 37 |
from django.contrib import messages |
38 | 38 |
from django.utils.functional import empty |
39 |
from django.template import RequestContext |
|
40 | 39 |
from django.utils.http import urlsafe_base64_encode |
41 | 40 |
from django.utils.encoding import force_bytes |
42 | 41 |
from django.shortcuts import render |
... | ... | |
594 | 593 |
user_or_email = user_or_email.email |
595 | 594 |
if not request: |
596 | 595 |
request = middleware.StoreRequestMiddleware().get_request() |
597 |
if request: |
|
598 |
ctx = RequestContext(request) |
|
599 |
ctx.update(context or {}) |
|
600 |
else: |
|
601 |
ctx = context or {} |
|
602 | 596 | |
603 | 597 |
subject_template_names = [template_name + '_subject.txt' for template_name in template_names] |
604 | 598 |
subject_template_names += legacy_subject_templates or [] |
605 |
subject = render_to_string(subject_template_names, ctx).strip()
|
|
599 |
subject = render_to_string(subject_template_names, context=context, request=request).strip()
|
|
606 | 600 | |
607 | 601 |
body_template_names = [template_name + '_body.txt' for template_name in template_names] |
608 | 602 |
body_template_names += legacy_body_templates or [] |
609 |
body = render_to_string(body_template_names, ctx)
|
|
603 |
body = render_to_string(body_template_names, context=context, request=request)
|
|
610 | 604 | |
611 | 605 |
html_body = None |
612 | 606 |
html_body_template_names = [template_name + '_body.html' for template_name in template_names] |
613 | 607 |
html_body_template_names += legacy_html_body_templates or [] |
614 | 608 |
if with_html: |
615 | 609 |
try: |
616 |
html_body = render_to_string(html_body_template_names, ctx)
|
|
610 |
html_body = render_to_string(html_body_template_names, context=context, request=request)
|
|
617 | 611 |
except TemplateDoesNotExist: |
618 | 612 |
html_body = None |
619 | 613 |
send_mail(subject, body, from_email or settings.DEFAULT_FROM_EMAIL, [user_or_email], |
src/authentic2/views.py | ||
---|---|---|
9 | 9 | |
10 | 10 |
import django |
11 | 11 |
from django.conf import settings |
12 |
from django.shortcuts import render_to_response, render |
|
13 |
from django.template import RequestContext |
|
14 |
from django.template.loader import render_to_string, select_template |
|
12 |
from django.shortcuts import render |
|
13 |
from django.template.loader import render_to_string |
|
15 | 14 |
from django.views.generic.edit import UpdateView, FormView |
16 |
from django.views.generic import RedirectView, TemplateView
|
|
15 |
from django.views.generic import TemplateView |
|
17 | 16 |
from django.views.generic.base import View |
18 | 17 |
from django.contrib.auth import SESSION_KEY |
19 | 18 |
from django import http, shortcuts |
20 |
from django.core import mail, signing
|
|
19 |
from django.core import signing |
|
21 | 20 |
from django.core.urlresolvers import reverse |
22 | 21 |
from django.core.exceptions import ValidationError |
23 | 22 |
from django.contrib import messages |
24 | 23 |
from django.utils.translation import ugettext as _ |
25 |
from django.utils.http import urlencode, same_origin |
|
26 | 24 |
from django.contrib.auth import logout as auth_logout |
27 | 25 |
from django.contrib.auth import REDIRECT_FIELD_NAME |
28 | 26 |
from django.http import (HttpResponseRedirect, HttpResponseForbidden, |
29 | 27 |
HttpResponse) |
30 |
from django.core.exceptions import PermissionDenied |
|
31 | 28 |
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie |
32 | 29 |
from django.views.decorators.cache import never_cache |
33 | 30 |
from django.contrib.auth.decorators import login_required |
... | ... | |
51 | 48 |
if not next.startswith('http'): |
52 | 49 |
next = '/%s%s' % (request.get_host(), next) |
53 | 50 |
logging.info('Redirect to %r' % next) |
54 |
return render_to_response(template_name, { 'next': next })
|
|
51 |
return render(request, template_name, context={ 'next': next })
|
|
55 | 52 | |
56 | 53 | |
57 | 54 |
def server_error(request, template_name='500.html'): |
... | ... | |
291 | 288 |
registration_url = utils.get_registration_url( |
292 | 289 |
request, service_slug=request.GET.get(constants.SERVICE_FIELD_NAME)) |
293 | 290 | |
294 |
context_instance = RequestContext(request, {
|
|
291 |
context = {
|
|
295 | 292 |
'cancel': nonce is not None, |
296 | 293 |
'can_reset_password': app_settings.A2_CAN_RESET_PASSWORD, |
297 | 294 |
'registration_authorized': getattr(settings, 'REGISTRATION_OPEN', True), |
298 | 295 |
'registration_url': registration_url, |
299 |
})
|
|
296 |
} |
|
300 | 297 |
if django.VERSION >= (1, 8, 0): |
301 |
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
|
|
298 |
context['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
302 | 299 | |
303 | 300 |
# Cancel button |
304 | 301 |
if request.method == "POST" \ |
... | ... | |
330 | 327 |
blocks.append(block) |
331 | 328 |
else: # New frontends API |
332 | 329 |
parameters = {'request': request, |
333 |
'context_instance': context_instance}
|
|
330 |
'context': context}
|
|
334 | 331 |
block = utils.get_backend_method(frontend, 'login', parameters) |
335 | 332 |
# If a login frontend method returns an HttpResponse with a status code != 200 |
336 | 333 |
# this response is returned. |
... | ... | |
359 | 356 |
context.update(frontend.get_context()) |
360 | 357 |
sub_template_name = frontend.template() |
361 | 358 |
block['content'] = render_to_string( |
362 |
sub_template_name, context, |
|
363 |
context_instance=context_instance)
|
|
359 |
sub_template_name, context=context,
|
|
360 |
request=request)
|
|
364 | 361 | |
365 | 362 |
request.session.set_test_cookie() |
366 | 363 | |
367 | 364 |
# legacy context variable |
368 | 365 |
rendered_forms = [(block['name'], block['content']) for block in blocks] |
369 | 366 | |
370 |
return render_to_response(template_name, {
|
|
367 |
return render(request, template_name, context={
|
|
371 | 368 |
'methods': rendered_forms, |
372 | 369 |
# new definition |
373 | 370 |
'blocks': collections.OrderedDict((block['id'], block) for block in blocks), |
374 | 371 |
redirect_field_name: redirect_to, |
375 |
}, context_instance=context_instance)
|
|
372 |
}) |
|
376 | 373 | |
377 | 374 | |
378 | 375 |
def service_list(request): |
... | ... | |
412 | 409 | |
413 | 410 |
request = self.request |
414 | 411 | |
415 |
context_instance = RequestContext(request, ctx)
|
|
412 |
context = ctx
|
|
416 | 413 |
if django.VERSION >= (1, 8, 0): |
417 |
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
|
|
414 |
context['add_to_blocks'] = collections.defaultdict(lambda: []) |
|
418 | 415 |
if request.method == "POST": |
419 | 416 |
for frontend in frontends: |
420 | 417 |
if 'submit-%s' % frontend.id in request.POST: |
... | ... | |
479 | 476 | |
480 | 477 |
# Credentials management |
481 | 478 |
parameters = {'request': request, |
482 |
'context_instance': context_instance}
|
|
479 |
'context': context}
|
|
483 | 480 |
profiles = [utils.get_backend_method(frontend, 'profile', parameters) |
484 | 481 |
for frontend in frontends] |
485 | 482 |
# Old frontends data structure for templates |
... | ... | |
494 | 491 |
for idp_backend in idp_backends: |
495 | 492 |
if hasattr(idp_backend, 'federation_management'): |
496 | 493 |
federation_management.extend(idp_backend.federation_management(request)) |
497 |
context_instance.update({
|
|
494 |
context.update({ |
|
498 | 495 |
'frontends_block': blocks, |
499 | 496 |
'frontends_block_by_id': blocks_by_id, |
500 | 497 |
'profile': profile, |
... | ... | |
504 | 501 |
'allow_password_change': app_settings.A2_REGISTRATION_CAN_CHANGE_PASSWORD, |
505 | 502 |
'federation_management': federation_management, |
506 | 503 |
}) |
507 |
hooks.call_hooks('modify_context_data', self, context_instance)
|
|
508 |
return context_instance
|
|
504 |
hooks.call_hooks('modify_context_data', self, context) |
|
505 |
return context |
|
509 | 506 | |
510 | 507 |
profile = login_required(ProfileView.as_view()) |
511 | 508 | |
... | ... | |
537 | 534 |
local_logout_done = False |
538 | 535 |
if request.user.is_authenticated(): |
539 | 536 |
if check_referer and not utils.check_referer(request): |
540 |
return render(request, 'authentic2/logout_confirm.html', ctx) |
|
537 |
return render(request, 'authentic2/logout_confirm.html', context=ctx)
|
|
541 | 538 |
do_local = do_local and 'local' in request.GET |
542 | 539 |
if not do_local: |
543 | 540 |
l = logout_list(request) |
... | ... | |
549 | 546 |
ctx['next_url'] = next_url |
550 | 547 |
ctx['logout_list'] = l |
551 | 548 |
ctx['message'] = _('Logging out from all your services') |
552 |
return render(request, template, ctx) |
|
549 |
return render(request, template, context=ctx)
|
|
553 | 550 |
# Get redirection targets for full logout with redirections |
554 | 551 |
# (needed before local logout) |
555 | 552 |
targets = redirect_logout_list(request) |
... | ... | |
579 | 576 | |
580 | 577 | |
581 | 578 |
def login_password_profile(request, *args, **kwargs): |
582 |
context_instance = kwargs.pop('context_instance', None) or RequestContext(request) |
|
583 | 579 |
can_change_password = app_settings.A2_REGISTRATION_CAN_CHANGE_PASSWORD |
584 | 580 |
has_usable_password = request.user.has_usable_password() |
585 | 581 |
return render_to_string(['auth/login_password_profile.html', |
586 | 582 |
'authentic2/login_password_profile.html'], |
587 |
{'can_change_password' : can_change_password, |
|
583 |
context={'can_change_password' : can_change_password,
|
|
588 | 584 |
'has_usable_password' : has_usable_password}, |
589 |
context_instance=context_instance)
|
|
585 |
request=request)
|
|
590 | 586 | |
591 | 587 | |
592 | 588 |
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 | 18 |
ctx = { |
20 | 19 |
'providers': utils.get_providers(shown=True), |
21 | 20 |
} |
22 |
return render(request, 'authentic2_auth_oidc/login.html', ctx, |
|
23 |
context_instance=context_instance) |
|
21 |
return render(request, 'authentic2_auth_oidc/login.html', context=ctx) |
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) |
|
23 | 21 |
submit_name = 'login-%s' % self.id |
24 | 22 |
if request.method == 'POST' and submit_name in request.POST: |
25 | 23 |
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) |
|
24 |
return render(request, 'authentic2_auth_saml/login.html', context={'submit_name': submit_name}) |
|
28 | 25 | |
29 | 26 |
def profile(self, request, *args, **kwargs): |
30 |
context_instance = kwargs.pop('context_instance', None) or RequestContext(request) |
|
31 | 27 |
user_saml_identifiers = request.user.saml_identifiers.all() |
32 | 28 |
if not user_saml_identifiers: |
33 | 29 |
return '' |
34 | 30 |
for user_saml_identifier in user_saml_identifiers: |
35 | 31 |
user_saml_identifier.idp = get_idp(user_saml_identifier.issuer) |
36 | 32 |
return render_to_string('authentic2_auth_saml/profile.html', |
37 |
{'user_saml_identifiers': user_saml_identifiers}, |
|
38 |
context_instance=context_instance) |
|
33 |
context={'user_saml_identifiers': user_saml_identifiers}, |
|
34 |
request=request) |
src/authentic2_idp_cas/__init__.py | ||
---|---|---|
28 | 28 |
'url': url, |
29 | 29 |
'iframe_timeout': use_iframe_timeout, |
30 | 30 |
} |
31 |
content = render_to_string('authentic2_idp_cas/logout_fragment.html', ctx) |
|
31 |
content = render_to_string('authentic2_idp_cas/logout_fragment.html', context=ctx)
|
|
32 | 32 |
fragments.append(content) |
33 |
return fragments |
|
33 |
return fragments |
src/authentic2_idp_oidc/__init__.py | ||
---|---|---|
30 | 30 |
fragments.append( |
31 | 31 |
render_to_string( |
32 | 32 |
'authentic2_idp_oidc/logout_fragment.html', |
33 |
ctx)) |
|
34 |
return fragments |
|
33 |
context=ctx)) |
|
34 |
return fragments |
src/authentic2_idp_oidc/views.py | ||
---|---|---|
5 | 5 |
import time |
6 | 6 | |
7 | 7 |
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed |
8 |
from django.utils.timezone import now, UTC
|
|
8 |
from django.utils.timezone import now, utc
|
|
9 | 9 |
from django.utils.http import urlencode |
10 | 10 |
from django.shortcuts import render |
11 | 11 |
from django.views.decorators.csrf import csrf_exempt |
... | ... | |
244 | 244 |
state=state, |
245 | 245 |
fragment=fragment) |
246 | 246 |
else: |
247 |
return render(request, 'authentic2_idp_oidc/authorization.html', |
|
247 |
return render(request, 'authentic2_idp_oidc/authorization.html', context=
|
|
248 | 248 |
{ |
249 | 249 |
'client': client, |
250 | 250 |
'scopes': scopes - set(['openid']), |
... | ... | |
254 | 254 |
client=client, user=request.user, scopes=u' '.join(scopes), |
255 | 255 |
state=state, nonce=nonce, redirect_uri=redirect_uri, |
256 | 256 |
expired=start + datetime.timedelta(seconds=30), |
257 |
auth_time=datetime.datetime.fromtimestamp(last_auth['when'], UTC()),
|
|
257 |
auth_time=datetime.datetime.fromtimestamp(last_auth['when'], utc),
|
|
258 | 258 |
session_key=request.session.session_key) |
259 | 259 |
logger.info(u'sending code %s for scopes %s for service %s', |
260 | 260 |
code.uuid, ' '.join(scopes), |
src/authentic2_idp_openid/views.py | ||
---|---|---|
7 | 7 |
import urlparse |
8 | 8 | |
9 | 9 |
from django.core.urlresolvers import reverse |
10 |
from django.shortcuts import render_to_response |
|
11 |
from django.template import RequestContext |
|
10 |
from django.shortcuts import render |
|
12 | 11 |
from django.utils.translation import ugettext as _ |
13 | 12 |
try: |
14 | 13 |
from django.views.decorators.csrf import csrf_exempt |
... | ... | |
209 | 208 |
types = [OPENID_IDP_2_0_TYPE,SREG_TYPE] |
210 | 209 |
local_ids = [] |
211 | 210 |
endpoints = [request.build_absolute_uri(reverse('openid-provider-root'))] |
212 |
return render_to_response('idp/openid/xrds.xml', {
|
|
211 |
return render(request, 'idp/openid/xrds.xml', context={
|
|
213 | 212 |
'host': request.build_absolute_uri('/'), |
214 | 213 |
'types': types, |
215 | 214 |
'endpoints': endpoints, |
216 | 215 |
'local_ids': local_ids, |
217 |
}, context_instance=RequestContext(request), mimetype=YADIS_CONTENT_TYPE)
|
|
216 |
}, mimetype=YADIS_CONTENT_TYPE) |
|
218 | 217 | |
219 | 218 |
class DecideForm(forms.Form): |
220 | 219 |
def __init__(self, sreg_request=None, *args, **kwargs): |
... | ... | |
274 | 273 |
except DiscoveryFailure: |
275 | 274 |
trust_root_valid = "DISCOVERY_FAILED" |
276 | 275 | |
277 |
return render_to_response('idp/openid/decide.html', {
|
|
276 |
return render(request, 'idp/openid/decide.html', context={
|
|
278 | 277 |
'title': _('Trust this site?'), |
279 | 278 |
'required': sreg_request.required, |
280 | 279 |
'optional': sreg_request.optional, |
281 | 280 |
'trust_root_valid': trust_root_valid, |
282 | 281 |
'form': form, |
283 |
}, context_instance=RequestContext(request))
|
|
282 |
}) |
|
284 | 283 | |
285 | 284 |
@openid_enabled |
286 | 285 |
def openid_discovery(request, id): |
287 | 286 |
'''HTML discovery page''' |
288 | 287 |
xrds_url = request.build_absolute_uri( |
289 | 288 |
reverse('openid-provider-identity-xrds', args=[id])) |
290 |
response = render_to_response('idp/openid/discovery.html', {
|
|
289 |
response = render(request, 'idp/openid/discovery.html', context={
|
|
291 | 290 |
'xrds': xrds_url, |
292 |
'openid_server': request.build_absolute_uri( |
|
293 |
reverse('openid-provider-root')) |
|
294 |
}, context_instance=RequestContext(request)) |
|
291 |
'openid_server': request.build_absolute_uri(reverse('openid-provider-root')) |
|
292 |
}) |
|
295 | 293 |
response['X-XRDS-Location'] = xrds_url |
296 | 294 |
return response |
297 | 295 | |
298 |
- |