diff --git a/zerver/context_processors.py b/zerver/context_processors.py index b1a737e3a4..d6bd7a1b8b 100644 --- a/zerver/context_processors.py +++ b/zerver/context_processors.py @@ -5,10 +5,7 @@ import ujson from zproject.backends import password_auth_enabled, dev_auth_enabled, google_auth_enabled def add_settings(request): - if hasattr(request.user, "realm"): - is_pw_auth_enabled = password_auth_enabled(request.user.realm) - else: - is_pw_auth_enabled = True + realm = request.user.realm if hasattr(request.user, "realm") else None return { 'full_navbar': settings.FULL_NAVBAR, # We use the not_enterprise variable name so that templates @@ -24,7 +21,7 @@ def add_settings(request): 'api_site_required': settings.EXTERNAL_API_PATH != "api.zulip.com", 'email_integration_enabled': settings.EMAIL_GATEWAY_BOT != "", 'email_gateway_example': settings.EMAIL_GATEWAY_EXAMPLE, - 'password_auth_enabled': is_pw_auth_enabled, + 'password_auth_enabled': password_auth_enabled(realm), 'dev_auth_enabled': dev_auth_enabled(), 'google_auth_enabled': google_auth_enabled(), } diff --git a/zproject/backends.py b/zproject/backends.py index 567236c8e6..32b017a1c5 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -14,12 +14,13 @@ from apiclient.sample_tools import client as googleapiclient from oauth2client.crypt import AppIdentityError def password_auth_enabled(realm): - if realm.domain == 'employees.customer16.invalid': - return False - elif realm.domain == 'zulip.com' and settings.DEPLOYED: - # the dropbox realm is SSO only, but the unit tests still need to be - # able to login - return False + if realm is not None: + if realm.domain == 'employees.customer16.invalid': + return False + elif realm.domain == 'zulip.com' and settings.DEPLOYED: + # the dropbox realm is SSO only, but the unit tests still need to be + # able to login + return False for backend in django.contrib.auth.get_backends(): if isinstance(backend, EmailAuthBackend):