remote_user_sso: Improve invalid email message.

Show a user friendly message to the user if email is invalid.
Currently we show a generic message:
"Your username or password is incorrect."
This commit is contained in:
Umair Khan
2017-04-07 11:21:29 +05:00
committed by Tim Abbott
parent 93aa478efb
commit 80b019629c
2 changed files with 13 additions and 0 deletions

View File

@@ -1309,6 +1309,13 @@ class TestZulipRemoteUserBackend(ZulipTestCase):
self.assertEqual(result.status_code, 302)
self.assertIs(get_session_dict_user(self.client.session), None)
def test_login_failure_due_to_invalid_email(self):
# type: () -> None
email = 'hamlet'
with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):
result = self.client_post('/accounts/login/sso/', REMOTE_USER=email)
self.assert_json_error_contains(result, "Enter a valid email address.", 400)
def test_login_failure_due_to_missing_field(self):
# type: () -> None
with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):

View File

@@ -106,6 +106,12 @@ def remote_user_sso(request):
except KeyError:
raise JsonableError(_("No REMOTE_USER set."))
# Django invokes authenticate methods by matching arguments, and this
# authentication flow will not invoke LDAP authentication because of
# this condition of Django so no need to check if LDAP backend is
# enabled.
validate_login_email(remote_user_to_email(remote_user))
user_profile = authenticate(remote_user=remote_user, realm_subdomain=get_subdomain(request))
return login_or_register_remote_user(request, remote_user, user_profile)