don't use context_instance in rendering functions (#25346)
This commit is contained in:
parent
cecdc9adfd
commit
64766b7016
|
@ -1,10 +1,9 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.shortcuts import render_to_response, render
|
from django.shortcuts import render
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from django.template import RequestContext
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
|
@ -57,8 +56,7 @@ def handle_request(request):
|
||||||
|
|
||||||
# No SSL entries and no user session, redirect account linking page
|
# No SSL entries and no user session, redirect account linking page
|
||||||
if not user and not request.user.is_authenticated():
|
if not user and not request.user.is_authenticated():
|
||||||
return render_to_response('auth/account_linking_ssl.html',
|
return render(request, 'auth/account_linking_ssl.html')
|
||||||
context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
# No SSL entries but active user session, perform account linking
|
# No SSL entries but active user session, perform account linking
|
||||||
if not user and request.user.is_authenticated():
|
if not user and request.user.is_authenticated():
|
||||||
|
@ -128,12 +126,10 @@ def post_account_linking(request):
|
||||||
return render(request, 'auth/account_linking_ssl.html')
|
return render(request, 'auth/account_linking_ssl.html')
|
||||||
|
|
||||||
def profile(request, template_name='ssl/profile.html', *args, **kwargs):
|
def profile(request, template_name='ssl/profile.html', *args, **kwargs):
|
||||||
context_instance = kwargs.pop('context_instance', None) or \
|
context = kwargs.pop('context', {})
|
||||||
RequestContext(request)
|
|
||||||
certificates = models.ClientCertificate.objects.filter(user=request.user)
|
certificates = models.ClientCertificate.objects.filter(user=request.user)
|
||||||
ctx = { 'certificates': certificates }
|
context.update({'certificates': certificates})
|
||||||
return render_to_string(template_name, ctx,
|
return render_to_string(template_name, context, request=request)
|
||||||
context_instance=context_instance)
|
|
||||||
|
|
||||||
def delete_certificate(request, certificate_pk):
|
def delete_certificate(request, certificate_pk):
|
||||||
qs = models.ClientCertificate.objects.filter(pk=certificate_pk)
|
qs = models.ClientCertificate.objects.filter(pk=certificate_pk)
|
||||||
|
|
|
@ -17,7 +17,7 @@ class LoginPasswordBackend(object):
|
||||||
return 'password'
|
return 'password'
|
||||||
|
|
||||||
def login(self, request, *args, **kwargs):
|
def login(self, request, *args, **kwargs):
|
||||||
context_instance = kwargs.get('context_instance', None)
|
context = kwargs.get('context', {})
|
||||||
is_post = request.method == 'POST' and self.submit_name in request.POST
|
is_post = request.method == 'POST' and self.submit_name in request.POST
|
||||||
data = request.POST if is_post else None
|
data = request.POST if is_post else None
|
||||||
form = forms.AuthenticationForm(request=request, data=data)
|
form = forms.AuthenticationForm(request=request, data=data)
|
||||||
|
@ -26,9 +26,7 @@ class LoginPasswordBackend(object):
|
||||||
if app_settings.A2_USERNAME_LABEL:
|
if app_settings.A2_USERNAME_LABEL:
|
||||||
form.fields['username'].label = app_settings.A2_USERNAME_LABEL
|
form.fields['username'].label = app_settings.A2_USERNAME_LABEL
|
||||||
is_secure = request.is_secure
|
is_secure = request.is_secure
|
||||||
context = {
|
context['submit_name'] = self.submit_name
|
||||||
'submit_name': self.submit_name,
|
|
||||||
}
|
|
||||||
if is_post:
|
if is_post:
|
||||||
utils.csrf_token_check(request, form)
|
utils.csrf_token_check(request, form)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -39,8 +37,7 @@ class LoginPasswordBackend(object):
|
||||||
return utils.login(request, form.get_user(), how,
|
return utils.login(request, form.get_user(), how,
|
||||||
service_slug=request.GET.get(constants.SERVICE_FIELD_NAME))
|
service_slug=request.GET.get(constants.SERVICE_FIELD_NAME))
|
||||||
context['form'] = form
|
context['form'] = form
|
||||||
return render(request, 'authentic2/login_password_form.html', context,
|
return render(request, 'authentic2/login_password_form.html', context)
|
||||||
context_instance=context_instance)
|
|
||||||
|
|
||||||
def profile(self, request, *args, **kwargs):
|
def profile(self, request, *args, **kwargs):
|
||||||
return views.login_password_profile(request, *args, **kwargs)
|
return views.login_password_profile(request, *args, **kwargs)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.template import RequestContext
|
from django.shortcuts import render
|
||||||
from django.shortcuts import render_to_response
|
|
||||||
|
|
||||||
from authentic2.saml.models import LibertyProvider
|
from authentic2.saml.models import LibertyProvider
|
||||||
|
|
||||||
|
@ -11,11 +10,10 @@ def consent_federation(request, nonce = '', next = None, provider_id = None):
|
||||||
'''On a GET produce a form asking for consentment,
|
'''On a GET produce a form asking for consentment,
|
||||||
On a POST handle the form and redirect to next'''
|
On a POST handle the form and redirect to next'''
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render_to_response('interaction/consent_federation.html',
|
return render(request, 'interaction/consent_federation.html',
|
||||||
{'provider_id': request.GET.get('provider_id', ''),
|
{'provider_id': request.GET.get('provider_id', ''),
|
||||||
'nonce': request.GET.get('nonce', ''),
|
'nonce': request.GET.get('nonce', ''),
|
||||||
'next': request.GET.get('next', '')},
|
'next': request.GET.get('next', '')})
|
||||||
context_instance=RequestContext(request))
|
|
||||||
else:
|
else:
|
||||||
next = '/'
|
next = '/'
|
||||||
if 'next' in request.POST:
|
if 'next' in request.POST:
|
||||||
|
@ -57,13 +55,12 @@ def consent_attributes(request, nonce = '', next = None, provider_id = None):
|
||||||
name = request.GET.get('provider_id', '')
|
name = request.GET.get('provider_id', '')
|
||||||
if provider:
|
if provider:
|
||||||
name = provider.name or name
|
name = provider.name or name
|
||||||
return render_to_response('interaction/consent_attributes.html',
|
return render(request, 'interaction/consent_attributes.html',
|
||||||
{'provider_id': name,
|
{'provider_id': name,
|
||||||
'attributes': attributes,
|
'attributes': attributes,
|
||||||
'allow_selection': request.session['allow_attributes_selection'],
|
'allow_selection': request.session['allow_attributes_selection'],
|
||||||
'nonce': request.GET.get('nonce', ''),
|
'nonce': request.GET.get('nonce', ''),
|
||||||
'next': next},
|
'next': next})
|
||||||
context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
elif request.method == "POST":
|
elif request.method == "POST":
|
||||||
if request.session['allow_attributes_selection']:
|
if request.session['allow_attributes_selection']:
|
||||||
|
|
|
@ -14,7 +14,6 @@ from django.views.generic.edit import FormView, CreateView
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.forms import CharField, Form
|
from django.forms import CharField, Form
|
||||||
from django.core.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.template import RequestContext
|
|
||||||
from django.http import Http404, HttpResponseBadRequest
|
from django.http import Http404, HttpResponseBadRequest
|
||||||
|
|
||||||
from authentic2.utils import (import_module_or_class, redirect, make_url, get_fields_and_labels,
|
from authentic2.utils import (import_module_or_class, redirect, make_url, get_fields_and_labels,
|
||||||
|
@ -92,16 +91,14 @@ class BaseRegistrationView(FormView):
|
||||||
return redirect(self.request, 'registration_complete')
|
return redirect(self.request, 'registration_complete')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super(BaseRegistrationView, self).get_context_data(**kwargs)
|
context = super(BaseRegistrationView, self).get_context_data(**kwargs)
|
||||||
request_context = RequestContext(self.request)
|
|
||||||
request_context.push(ctx)
|
|
||||||
parameters = {'request': self.request,
|
parameters = {'request': self.request,
|
||||||
'context_instance': request_context}
|
'context': context}
|
||||||
blocks = [utils.get_backend_method(backend, 'registration', parameters)
|
blocks = [utils.get_backend_method(backend, 'registration', parameters)
|
||||||
for backend in utils.get_backends('AUTH_FRONTENDS')]
|
for backend in utils.get_backends('AUTH_FRONTENDS')]
|
||||||
request_context['frontends'] = collections.OrderedDict((block['id'], block)
|
context['frontends'] = collections.OrderedDict((block['id'], block)
|
||||||
for block in blocks if block)
|
for block in blocks if block)
|
||||||
return request_context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class RegistrationView(cbv.ValidateCSRFMixin, BaseRegistrationView):
|
class RegistrationView(cbv.ValidateCSRFMixin, BaseRegistrationView):
|
||||||
|
|
|
@ -9,10 +9,9 @@ import datetime
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from authentic2.compat_lasso import lasso
|
from authentic2.compat_lasso import lasso
|
||||||
from django.template import RequestContext
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import HttpResponseRedirect, Http404, HttpResponse
|
from django.http import HttpResponseRedirect, Http404, HttpResponse
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from authentic2.saml.models import (LibertyFederation, LibertyProvider,
|
from authentic2.saml.models import (LibertyFederation, LibertyProvider,
|
||||||
|
@ -181,14 +180,14 @@ def return_saml2_request(request, profile, title=''):
|
||||||
|
|
||||||
def return_saml2(request, profile, field_name, title=''):
|
def return_saml2(request, profile, field_name, title=''):
|
||||||
'''Helper to handle SAMLv2 bindings to emit request and responses'''
|
'''Helper to handle SAMLv2 bindings to emit request and responses'''
|
||||||
context_instance = RequestContext(request)
|
|
||||||
logger.debug('profile.msgBody: %r', profile.msgBody)
|
logger.debug('profile.msgBody: %r', profile.msgBody)
|
||||||
logger.debug('profile.msgUrl: %r', profile.msgUrl)
|
logger.debug('profile.msgUrl: %r', profile.msgUrl)
|
||||||
logger.debug('profile.msgRelayState: %r', profile.msgRelayState)
|
logger.debug('profile.msgRelayState: %r', profile.msgRelayState)
|
||||||
logger.debug('field_name: %s', field_name)
|
logger.debug('field_name: %s', field_name)
|
||||||
if profile.msgBody:
|
if profile.msgBody:
|
||||||
if profile.msgUrl:
|
if profile.msgUrl:
|
||||||
return render_to_response(
|
return render(
|
||||||
|
request,
|
||||||
'saml/post_form.html',
|
'saml/post_form.html',
|
||||||
{
|
{
|
||||||
'title': title,
|
'title': title,
|
||||||
|
@ -196,8 +195,7 @@ def return_saml2(request, profile, field_name, title=''):
|
||||||
'fieldname': field_name,
|
'fieldname': field_name,
|
||||||
'body': profile.msgBody,
|
'body': profile.msgBody,
|
||||||
'relay_state': profile.msgRelayState
|
'relay_state': profile.msgRelayState
|
||||||
},
|
})
|
||||||
context_instance=context_instance)
|
|
||||||
return HttpResponse(profile.msgBody, content_type='text/xml')
|
return HttpResponse(profile.msgBody, content_type='text/xml')
|
||||||
elif profile.msgUrl:
|
elif profile.msgUrl:
|
||||||
return HttpResponseRedirect(profile.msgUrl)
|
return HttpResponseRedirect(profile.msgUrl)
|
||||||
|
@ -503,13 +501,12 @@ def error_page(request, message, back=None, logger=None, warning=False):
|
||||||
back = '/'
|
back = '/'
|
||||||
redirection_timeout = getattr(settings, 'REDIRECTION_TIMEOUT_AFTER_ERROR',
|
redirection_timeout = getattr(settings, 'REDIRECTION_TIMEOUT_AFTER_ERROR',
|
||||||
2000)
|
2000)
|
||||||
return render_to_response('error.html',
|
return render(request, 'error.html',
|
||||||
{
|
{
|
||||||
'msg': message,
|
'msg': message,
|
||||||
'back': back,
|
'back': back,
|
||||||
'redir_timeout': redirection_timeout
|
'redir_timeout': redirection_timeout
|
||||||
},
|
})
|
||||||
context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
|
|
||||||
def redirect_next(request, next):
|
def redirect_next(request, next):
|
||||||
|
|
|
@ -34,7 +34,6 @@ from django.core.urlresolvers import reverse, NoReverseMatch
|
||||||
from django.utils.formats import localize
|
from django.utils.formats import localize
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.functional import empty
|
from django.utils.functional import empty
|
||||||
from django.template import RequestContext
|
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
@ -592,11 +591,8 @@ def send_templated_mail(user_or_email, template_names, context=None, with_html=T
|
||||||
user_or_email = user_or_email.email
|
user_or_email = user_or_email.email
|
||||||
if not request:
|
if not request:
|
||||||
request = middleware.StoreRequestMiddleware().get_request()
|
request = middleware.StoreRequestMiddleware().get_request()
|
||||||
if request:
|
|
||||||
ctx = RequestContext(request)
|
ctx = context or {}
|
||||||
ctx.update(context or {})
|
|
||||||
else:
|
|
||||||
ctx = context or {}
|
|
||||||
|
|
||||||
subject_template_names = [template_name + '_subject.txt' for template_name in template_names]
|
subject_template_names = [template_name + '_subject.txt' for template_name in template_names]
|
||||||
subject_template_names += legacy_subject_templates or []
|
subject_template_names += legacy_subject_templates or []
|
||||||
|
@ -611,7 +607,7 @@ def send_templated_mail(user_or_email, template_names, context=None, with_html=T
|
||||||
html_body_template_names += legacy_html_body_templates or []
|
html_body_template_names += legacy_html_body_templates or []
|
||||||
if with_html:
|
if with_html:
|
||||||
try:
|
try:
|
||||||
html_body = render_to_string(html_body_template_names, ctx)
|
html_body = render_to_string(html_body_template_names, ctx, request=request)
|
||||||
except TemplateDoesNotExist:
|
except TemplateDoesNotExist:
|
||||||
html_body = None
|
html_body = None
|
||||||
send_mail(subject, body, from_email or settings.DEFAULT_FROM_EMAIL, [user_or_email],
|
send_mail(subject, body, from_email or settings.DEFAULT_FROM_EMAIL, [user_or_email],
|
||||||
|
|
|
@ -9,7 +9,6 @@ import collections
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.shortcuts import render_to_response, render
|
from django.shortcuts import render_to_response, render
|
||||||
from django.template import RequestContext
|
|
||||||
from django.template.loader import render_to_string, select_template
|
from django.template.loader import render_to_string, select_template
|
||||||
from django.views.generic.edit import UpdateView, FormView
|
from django.views.generic.edit import UpdateView, FormView
|
||||||
from django.views.generic import RedirectView, TemplateView
|
from django.views.generic import RedirectView, TemplateView
|
||||||
|
@ -290,12 +289,12 @@ def login(request, template_name='authentic2/login.html',
|
||||||
registration_url = utils.get_registration_url(
|
registration_url = utils.get_registration_url(
|
||||||
request, service_slug=request.GET.get(constants.SERVICE_FIELD_NAME))
|
request, service_slug=request.GET.get(constants.SERVICE_FIELD_NAME))
|
||||||
|
|
||||||
context_instance = RequestContext(request, {
|
context = {
|
||||||
'cancel': nonce is not None,
|
'cancel': nonce is not None,
|
||||||
'can_reset_password': app_settings.A2_USER_CAN_RESET_PASSWORD is not False,
|
'can_reset_password': app_settings.A2_USER_CAN_RESET_PASSWORD is not False,
|
||||||
'registration_authorized': getattr(settings, 'REGISTRATION_OPEN', True),
|
'registration_authorized': getattr(settings, 'REGISTRATION_OPEN', True),
|
||||||
'registration_url': registration_url,
|
'registration_url': registration_url,
|
||||||
})
|
}
|
||||||
|
|
||||||
# Cancel button
|
# Cancel button
|
||||||
if request.method == "POST" \
|
if request.method == "POST" \
|
||||||
|
@ -327,7 +326,7 @@ def login(request, template_name='authentic2/login.html',
|
||||||
blocks.append(block)
|
blocks.append(block)
|
||||||
else: # New frontends API
|
else: # New frontends API
|
||||||
parameters = {'request': request,
|
parameters = {'request': request,
|
||||||
'context_instance': context_instance}
|
'context': context}
|
||||||
block = utils.get_backend_method(frontend, 'login', parameters)
|
block = utils.get_backend_method(frontend, 'login', parameters)
|
||||||
# If a login frontend method returns an HttpResponse with a status code != 200
|
# If a login frontend method returns an HttpResponse with a status code != 200
|
||||||
# this response is returned.
|
# this response is returned.
|
||||||
|
@ -347,29 +346,29 @@ def login(request, template_name='authentic2/login.html',
|
||||||
if not 'form' in block:
|
if not 'form' in block:
|
||||||
continue
|
continue
|
||||||
frontend = block['frontend']
|
frontend = block['frontend']
|
||||||
context = {
|
context.update({
|
||||||
'submit_name': 'submit-%s' % fid,
|
'submit_name': 'submit-%s' % fid,
|
||||||
redirect_field_name: redirect_to,
|
redirect_field_name: redirect_to,
|
||||||
'form': block['form']
|
'form': block['form']
|
||||||
}
|
})
|
||||||
if hasattr(frontend, 'get_context'):
|
if hasattr(frontend, 'get_context'):
|
||||||
context.update(frontend.get_context())
|
context.update(frontend.get_context())
|
||||||
sub_template_name = frontend.template()
|
sub_template_name = frontend.template()
|
||||||
block['content'] = render_to_string(
|
block['content'] = render_to_string(
|
||||||
sub_template_name, context,
|
sub_template_name, context,
|
||||||
context_instance=context_instance)
|
request=request)
|
||||||
|
|
||||||
request.session.set_test_cookie()
|
request.session.set_test_cookie()
|
||||||
|
|
||||||
# legacy context variable
|
# legacy context variable
|
||||||
rendered_forms = [(block['name'], block['content']) for block in blocks]
|
rendered_forms = [(block['name'], block['content']) for block in blocks]
|
||||||
|
context.update({
|
||||||
return render_to_response(template_name, {
|
|
||||||
'methods': rendered_forms,
|
'methods': rendered_forms,
|
||||||
# new definition
|
# new definition
|
||||||
'blocks': collections.OrderedDict((block['id'], block) for block in blocks),
|
'blocks': collections.OrderedDict((block['id'], block) for block in blocks),
|
||||||
redirect_field_name: redirect_to,
|
redirect_field_name: redirect_to,
|
||||||
}, context_instance=context_instance)
|
})
|
||||||
|
return render(request, template_name, context)
|
||||||
|
|
||||||
|
|
||||||
def service_list(request):
|
def service_list(request):
|
||||||
|
@ -404,12 +403,11 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
|
||||||
return super(ProfileView, self).dispatch(request, *args, **kwargs)
|
return super(ProfileView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super(ProfileView, self).get_context_data(**kwargs)
|
context = super(ProfileView, self).get_context_data(**kwargs)
|
||||||
frontends = utils.get_backends('AUTH_FRONTENDS')
|
frontends = utils.get_backends('AUTH_FRONTENDS')
|
||||||
|
|
||||||
request = self.request
|
request = self.request
|
||||||
|
|
||||||
context_instance = RequestContext(request, ctx)
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
for frontend in frontends:
|
for frontend in frontends:
|
||||||
if 'submit-%s' % frontend.id in request.POST:
|
if 'submit-%s' % frontend.id in request.POST:
|
||||||
|
@ -479,7 +477,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
|
||||||
|
|
||||||
# Credentials management
|
# Credentials management
|
||||||
parameters = {'request': request,
|
parameters = {'request': request,
|
||||||
'context_instance': context_instance}
|
'context': context}
|
||||||
profiles = [utils.get_backend_method(frontend, 'profile', parameters)
|
profiles = [utils.get_backend_method(frontend, 'profile', parameters)
|
||||||
for frontend in frontends]
|
for frontend in frontends]
|
||||||
# Old frontends data structure for templates
|
# Old frontends data structure for templates
|
||||||
|
@ -494,7 +492,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
|
||||||
for idp_backend in idp_backends:
|
for idp_backend in idp_backends:
|
||||||
if hasattr(idp_backend, 'federation_management'):
|
if hasattr(idp_backend, 'federation_management'):
|
||||||
federation_management.extend(idp_backend.federation_management(request))
|
federation_management.extend(idp_backend.federation_management(request))
|
||||||
context_instance.update({
|
context.update({
|
||||||
'frontends_block': blocks,
|
'frontends_block': blocks,
|
||||||
'frontends_block_by_id': blocks_by_id,
|
'frontends_block_by_id': blocks_by_id,
|
||||||
'profile': profile,
|
'profile': profile,
|
||||||
|
@ -506,8 +504,8 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
|
||||||
'allow_password_change': request.user.can_change_password(),
|
'allow_password_change': request.user.can_change_password(),
|
||||||
'federation_management': federation_management,
|
'federation_management': federation_management,
|
||||||
})
|
})
|
||||||
hooks.call_hooks('modify_context_data', self, context_instance)
|
hooks.call_hooks('modify_context_data', self, context)
|
||||||
return context_instance
|
return context
|
||||||
|
|
||||||
profile = login_required(ProfileView.as_view())
|
profile = login_required(ProfileView.as_view())
|
||||||
|
|
||||||
|
@ -581,14 +579,15 @@ def logout(request, next_url=None, default_next_url='auth_homepage',
|
||||||
|
|
||||||
|
|
||||||
def login_password_profile(request, *args, **kwargs):
|
def login_password_profile(request, *args, **kwargs):
|
||||||
context_instance = kwargs.pop('context_instance', None) or RequestContext(request)
|
context = kwargs.pop('context', {})
|
||||||
can_change_password = app_settings.A2_REGISTRATION_CAN_CHANGE_PASSWORD
|
can_change_password = app_settings.A2_REGISTRATION_CAN_CHANGE_PASSWORD
|
||||||
has_usable_password = request.user.has_usable_password()
|
has_usable_password = request.user.has_usable_password()
|
||||||
|
context.update(
|
||||||
|
{'can_change_password': can_change_password,
|
||||||
|
'has_usable_password': has_usable_password})
|
||||||
return render_to_string(['auth/login_password_profile.html',
|
return render_to_string(['auth/login_password_profile.html',
|
||||||
'authentic2/login_password_profile.html'],
|
'authentic2/login_password_profile.html'],
|
||||||
{'can_change_password' : can_change_password,
|
context, request=request)
|
||||||
'has_usable_password' : has_usable_password},
|
|
||||||
context_instance=context_instance)
|
|
||||||
|
|
||||||
|
|
||||||
class LoggedInView(View):
|
class LoggedInView(View):
|
||||||
|
|
|
@ -15,9 +15,6 @@ class OIDCFrontend(object):
|
||||||
return 'oidc'
|
return 'oidc'
|
||||||
|
|
||||||
def login(self, request, *args, **kwargs):
|
def login(self, request, *args, **kwargs):
|
||||||
context_instance = kwargs.get('context_instance', None)
|
context = kwargs.get('context', {})
|
||||||
ctx = {
|
context['providers'] = utils.get_providers(shown=True)
|
||||||
'providers': utils.get_providers(shown=True),
|
return render(request, 'authentic2_auth_oidc/login.html', context)
|
||||||
}
|
|
||||||
return render(request, 'authentic2_auth_oidc/login.html', ctx,
|
|
||||||
context_instance=context_instance)
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.utils.translation import gettext_noop
|
from django.utils.translation import gettext_noop
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.template import RequestContext
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from mellon.utils import get_idp, get_idps
|
from mellon.utils import get_idp, get_idps
|
||||||
|
|
||||||
|
@ -19,20 +18,20 @@ class SAMLFrontend(object):
|
||||||
return gettext_noop('SAML')
|
return gettext_noop('SAML')
|
||||||
|
|
||||||
def login(self, request, *args, **kwargs):
|
def login(self, request, *args, **kwargs):
|
||||||
context_instance = kwargs.pop('context_instance', None) or RequestContext(request)
|
context = kwargs.pop('context', {})
|
||||||
submit_name = 'login-%s' % self.id
|
submit_name = 'login-%s' % self.id
|
||||||
|
context['submit_name'] = submit_name
|
||||||
if request.method == 'POST' and submit_name in request.POST:
|
if request.method == 'POST' and submit_name in request.POST:
|
||||||
return redirect_to_login(request, login_url='mellon_login')
|
return redirect_to_login(request, login_url='mellon_login')
|
||||||
return render(request, 'authentic2_auth_saml/login.html', {'submit_name': submit_name},
|
return render(request, 'authentic2_auth_saml/login.html', context)
|
||||||
context_instance=context_instance)
|
|
||||||
|
|
||||||
def profile(self, request, *args, **kwargs):
|
def profile(self, request, *args, **kwargs):
|
||||||
context_instance = kwargs.pop('context_instance', None) or RequestContext(request)
|
context = kwargs.pop('context', {})
|
||||||
user_saml_identifiers = request.user.saml_identifiers.all()
|
user_saml_identifiers = request.user.saml_identifiers.all()
|
||||||
if not user_saml_identifiers:
|
if not user_saml_identifiers:
|
||||||
return ''
|
return ''
|
||||||
for user_saml_identifier in user_saml_identifiers:
|
for user_saml_identifier in user_saml_identifiers:
|
||||||
user_saml_identifier.idp = get_idp(user_saml_identifier.issuer)
|
user_saml_identifier.idp = get_idp(user_saml_identifier.issuer)
|
||||||
|
context['user_saml_identifiers'] = user_saml_identifiers
|
||||||
return render_to_string('authentic2_auth_saml/profile.html',
|
return render_to_string('authentic2_auth_saml/profile.html',
|
||||||
{'user_saml_identifiers': user_saml_identifiers},
|
context, request=request)
|
||||||
context_instance=context_instance)
|
|
||||||
|
|
Loading…
Reference in New Issue