mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	ux: Display error on login/registration if no auth backends are enabled.
Also makes a small tweak to CSS to ensure the styling is consistent on the two pages. Fixes #4525.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							2fafc6bec5
						
					
				
				
					commit
					47eb19331d
				
			@@ -68,7 +68,8 @@ html {
 | 
			
		||||
    width: auto;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.new-style .login-page-container .alert {
 | 
			
		||||
.new-style .login-page-container .alert,
 | 
			
		||||
.register-page-container .new-style .alert {
 | 
			
		||||
    margin: 0;
 | 
			
		||||
    text-align: left;
 | 
			
		||||
    font-size: 0.7em;
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,17 @@ $(function () {
 | 
			
		||||
            </div>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
            <div class="right-side">
 | 
			
		||||
                {% if no_auth_enabled %}
 | 
			
		||||
                <div class="alert">
 | 
			
		||||
                    <p>No authentication backends are enabled on this
 | 
			
		||||
                    server yet, so it is impossible to register!</p>
 | 
			
		||||
 | 
			
		||||
                    <p>See
 | 
			
		||||
                    the <a href="http://zulip.readthedocs.io/en/latest/prod-install.html#step-3-configure-zulip">Zulip
 | 
			
		||||
                    authentication documentation</a> to learn how to
 | 
			
		||||
                    configure authentication backends.</p>
 | 
			
		||||
                </div>
 | 
			
		||||
                {% else %}
 | 
			
		||||
                <form class="form-inline" id="send_confirm" name="email_form"
 | 
			
		||||
                    action="{{ current_url() }}" method="post">
 | 
			
		||||
                    {{ csrf_input }}
 | 
			
		||||
@@ -65,6 +76,8 @@ $(function () {
 | 
			
		||||
                    </a>
 | 
			
		||||
                </div>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
                {% endif %}
 | 
			
		||||
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -71,6 +71,17 @@ autofocus('#id_username');
 | 
			
		||||
        {% endif %}
 | 
			
		||||
 | 
			
		||||
        <div class="right-side">
 | 
			
		||||
            {% if no_auth_enabled %}
 | 
			
		||||
            <div class="alert">
 | 
			
		||||
                <p>No authentication backends are enabled on this
 | 
			
		||||
                server yet, so it is impossible to login!</p>
 | 
			
		||||
 | 
			
		||||
                <p>See
 | 
			
		||||
                the <a href="http://zulip.readthedocs.io/en/latest/prod-install.html#step-3-configure-zulip">Zulip
 | 
			
		||||
                authentication documentation</a> to learn how to
 | 
			
		||||
                configure authentication backends.</p>
 | 
			
		||||
            </div>
 | 
			
		||||
            {% else %}
 | 
			
		||||
            {% if password_auth_enabled %}
 | 
			
		||||
            <form name="login_form" id="login_form" method="post" class="login-form"
 | 
			
		||||
                  action="{{ url('django.contrib.auth.views.login') }}?next={{ next }}">
 | 
			
		||||
@@ -146,6 +157,7 @@ autofocus('#id_username');
 | 
			
		||||
                <a class="register-link float-right" href="/register/">Register</a>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </div>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        </div>
 | 
			
		||||
        {% endif %}
 | 
			
		||||
    </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -162,6 +162,7 @@ def check_html_templates(templates, all_dups):
 | 
			
		||||
        'templates/corporate/zephyr.html',
 | 
			
		||||
        'templates/zerver/api.html',
 | 
			
		||||
        'templates/zerver/apps.html',
 | 
			
		||||
        'templates/zerver/accounts_home.html',
 | 
			
		||||
        'templates/zerver/compose.html',
 | 
			
		||||
        'templates/zerver/emails/digest/digest_email.html',
 | 
			
		||||
        'templates/zerver/emails/find_team/find_team_email.html',
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,8 @@ from zproject.backends import (
 | 
			
		||||
    github_auth_enabled,
 | 
			
		||||
    google_auth_enabled,
 | 
			
		||||
    password_auth_enabled,
 | 
			
		||||
    auth_enabled_helper,
 | 
			
		||||
    AUTH_BACKEND_NAME_MAP
 | 
			
		||||
)
 | 
			
		||||
from zerver.lib.utils import get_subdomain
 | 
			
		||||
from zerver.lib.realm_icon import get_realm_icon_url
 | 
			
		||||
@@ -90,6 +92,7 @@ def zulip_default_context(request):
 | 
			
		||||
        'google_auth_enabled': google_auth_enabled(realm),
 | 
			
		||||
        'github_auth_enabled': github_auth_enabled(realm),
 | 
			
		||||
        'any_oauth_backend_enabled': any_oauth_backend_enabled(realm),
 | 
			
		||||
        'no_auth_enabled': not auth_enabled_helper(list(AUTH_BACKEND_NAME_MAP.keys()), realm),
 | 
			
		||||
        'development_environment': settings.DEVELOPMENT,
 | 
			
		||||
        'support_email': settings.ZULIP_ADMINISTRATOR,
 | 
			
		||||
        'find_team_link_disabled': settings.FIND_TEAM_LINK_DISABLED,
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,7 @@ from six.moves.http_cookies import SimpleCookie
 | 
			
		||||
import ujson
 | 
			
		||||
from zerver.lib.test_helpers import MockLDAP, unsign_subdomain_cookie
 | 
			
		||||
 | 
			
		||||
class AuthBackendTest(TestCase):
 | 
			
		||||
class AuthBackendTest(ZulipTestCase):
 | 
			
		||||
    email = u"hamlet@zulip.com"
 | 
			
		||||
 | 
			
		||||
    def get_username(self, email_to_username=None):
 | 
			
		||||
@@ -202,6 +202,26 @@ class AuthBackendTest(TestCase):
 | 
			
		||||
        with mock.patch('zproject.backends.password_auth_enabled', return_value=False):
 | 
			
		||||
            self.assertIsNone(EmailAuthBackend().authenticate(email, password))
 | 
			
		||||
 | 
			
		||||
    @override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipDummyBackend',))
 | 
			
		||||
    def test_no_backend_enabled(self):
 | 
			
		||||
        # type: () -> None
 | 
			
		||||
        result = self.client_get('/login/')
 | 
			
		||||
        self.assert_in_success_response(["No authentication backends are enabled"], result)
 | 
			
		||||
 | 
			
		||||
        result = self.client_get('/register/')
 | 
			
		||||
        self.assert_in_success_response(["No authentication backends are enabled"], result)
 | 
			
		||||
 | 
			
		||||
    @override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.GoogleMobileOauth2Backend',))
 | 
			
		||||
    def test_any_backend_enabled(self):
 | 
			
		||||
        # type: () -> None
 | 
			
		||||
 | 
			
		||||
        # testing to avoid false error messages.
 | 
			
		||||
        result = self.client_get('/login/')
 | 
			
		||||
        self.assert_not_in_success_response(["No Authentication Backend is enabled."], result)
 | 
			
		||||
 | 
			
		||||
        result = self.client_get('/register/')
 | 
			
		||||
        self.assert_not_in_success_response(["No Authentication Backend is enabled."], result)
 | 
			
		||||
 | 
			
		||||
    @override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.GoogleMobileOauth2Backend',))
 | 
			
		||||
    def test_google_backend(self):
 | 
			
		||||
        # type: () -> None
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user