Skip to content
Snippets Groups Projects
Unverified Commit ebe2ee10 authored by George Babey's avatar George Babey Committed by GitHub
Browse files

Merge pull request #22813 from edx/ziafazal/ENT-2535

ENT-2535: Added link to error message displayed when TPA only user login from FPA form
parents 5356e7a6 60ce8037
No related branches found
Tags release-2021-03-16-09.35
No related merge requests found
......@@ -16,6 +16,7 @@ from django.contrib.auth import login as django_login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpRequest, HttpResponse
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt, csrf_protect, ensure_csrf_cookie
......@@ -292,11 +293,19 @@ def _check_user_auth_flow(site, user):
# If user belongs to allowed domain and not whitelisted then user must login through allowed domain SSO
if user_domain == allowed_domain and not AllowedAuthUser.objects.filter(site=site, email=user.email).exists():
msg = _(
u'As an {allowed_domain} user, You must login with your {allowed_domain} {provider} account.'
).format(
msg = Text(_(
u'As {allowed_domain} user, You must login with your {allowed_domain} '
u'{link_start}{provider} account{link_end}.'
)).format(
allowed_domain=allowed_domain,
provider=site.configuration.get_value('THIRD_PARTY_AUTH_ONLY_PROVIDER')
link_start=HTML("<a href='{tpa_provider_link}'>").format(
tpa_provider_link='{dashboard_url}?tpa_hint={tpa_hint}'.format(
dashboard_url=reverse('dashboard'),
tpa_hint=site.configuration.get_value('THIRD_PARTY_AUTH_HINT'),
)
),
provider=site.configuration.get_value('THIRD_PARTY_AUTH_ONLY_PROVIDER'),
link_end=HTML("</a>")
)
raise AuthFailedError(msg)
......
......@@ -616,6 +616,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
},
)
@ddt.unpack
@skip_unless_lms
def test_login_for_user_auth_flow(
self,
switch_enabled,
......@@ -629,6 +630,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
Verify that `login._check_user_auth_flow` works as expected.
"""
provider = 'Google'
provider_tpa_hint = 'saml-test'
username = 'batman'
user_email = '{username}@{domain}'.format(username=username, domain=user_domain)
user = self._create_user(username, user_email)
......@@ -636,6 +638,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
'SITE_NAME': allowed_domain,
'THIRD_PARTY_AUTH_ONLY_DOMAIN': allowed_domain,
'THIRD_PARTY_AUTH_ONLY_PROVIDER': provider,
'THIRD_PARTY_AUTH_HINT': provider_tpa_hint,
}
with ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY.override(switch_enabled):
......@@ -647,10 +650,14 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
else:
AllowedAuthUser.objects.filter(site=site, email=user.email).delete()
value = None if success else u'As an {0} user, You must login with your {0} {1} account.'.format(
allowed_domain,
provider
)
if success:
value = None
else:
value = u'As {0} user, You must login with your {0} <a href=\'{1}\'>{2} account</a>.'.format(
allowed_domain,
'{}?tpa_hint={}'.format(reverse("dashboard"), provider_tpa_hint),
provider,
)
response, __ = self._login_response(user.email, self.password)
self._assert_response(
response,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment