views: pass service parameter to show evaluation context (#42370)
This commit is contained in:
parent
0b57aa56e7
commit
018d3c8520
|
@ -316,22 +316,25 @@ def login(request, template_name='authentic2/login.html',
|
|||
parameters = {'request': request,
|
||||
'context': context}
|
||||
remote_addr = request.META.get('REMOTE_ADDR')
|
||||
service = request.GET.get('service')
|
||||
login_hint = set(request.session.get('login-hint', []))
|
||||
show_ctx = dict(remote_addr=remote_addr, login_hint=login_hint)
|
||||
if service and models.Service.objects.filter(slug=service).exists():
|
||||
show_ctx['service_slug'] = service
|
||||
# check if the authenticator has multiple instances
|
||||
if hasattr(authenticator, 'instances'):
|
||||
for instance_id, instance in authenticator.instances(**parameters):
|
||||
parameters['instance'] = instance
|
||||
parameters['instance_id'] = instance_id
|
||||
if not authenticator.shown(
|
||||
instance_id=instance_id,
|
||||
ctx=dict(remote_addr=remote_addr, login_hint=login_hint)):
|
||||
if not authenticator.shown(instance_id=instance_id,
|
||||
ctx=show_ctx):
|
||||
continue
|
||||
block = utils.get_authenticator_method(authenticator, 'login', parameters)
|
||||
# update block id in order to separate instances
|
||||
block['id'] = '%s_%s' % (block['id'], instance_id)
|
||||
auth_blocks.append(block)
|
||||
else:
|
||||
if authenticator.shown(ctx=dict(remote_addr=remote_addr, login_hint=login_hint)):
|
||||
if authenticator.shown(ctx=show_ctx):
|
||||
auth_blocks.append(utils.get_authenticator_method(authenticator, 'login', parameters))
|
||||
# If a login frontend method returns an HttpResponse with a status code != 200
|
||||
# this response is returned.
|
||||
|
|
|
@ -64,6 +64,14 @@ def test_login_with_conditionnal_enabled_authenticators(db, app, settings, caplo
|
|||
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
|
||||
response = app.get('/login/')
|
||||
assert 'name="login-password-submit"' not in response
|
||||
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == \'portal\''}}
|
||||
response = app.get('/login/', params={'service': 'portal'})
|
||||
assert 'name="login-password-submit"' not in response
|
||||
|
||||
# Create a service
|
||||
service = models.Service.objects.create(name='Service', slug='portal')
|
||||
response = app.get('/login/', params={'service': 'portal'})
|
||||
assert 'name="login-password-submit"' in response
|
||||
|
||||
|
||||
def test_registration_url_on_login_page(db, app):
|
||||
|
@ -231,4 +239,3 @@ def test_login_test_cookie(app, simple_user):
|
|||
resp = resp.form.submit(name='login-password-submit')
|
||||
# CSRF and test cookie checks failed
|
||||
assert 'Cookies are disabled' in resp
|
||||
|
||||
|
|
Loading…
Reference in New Issue