social_auth: Take user to find_account if invalid subdomain is given.

This allows to also clean up some code that's not really useful.
This commit is contained in:
Mateusz Mandera 2020-02-15 17:08:09 +01:00 committed by Tim Abbott
parent 98a7cd85a2
commit efb3065158
5 changed files with 9 additions and 22 deletions

View File

@ -96,12 +96,6 @@ page can be easily identified in it's respective JavaScript file. -->
</div>
{% endif %}
{% if subdomain %}
<div class="alert">
{{ wrong_subdomain_error }}
</div>
{% endif %}
<button type="submit" name="button" class="full-width">
<img class="loader" src="/static/images/loader.svg" alt="" />
<span class="text">{{ _("Log in") }}</span>

View File

@ -885,7 +885,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
result = self.social_auth_test(account_data_dict,
subdomain='invalid', next='/user_uploads/image')
self.assertEqual(result.status_code, 302)
self.assertEqual(result.url, "/accounts/login/?subdomain=1")
self.assertEqual(result.url, "/accounts/find/")
def test_social_auth_invalid_email(self) -> None:
account_data_dict = self.get_account_data_dict(email="invalid", name=self.name)

View File

@ -18,7 +18,7 @@ from confirmation.models import Confirmation, create_confirmation_link, Multiuse
one_click_unsubscribe_link
from confirmation import settings as confirmation_settings
from zerver.forms import HomepageForm, WRONG_SUBDOMAIN_ERROR, check_subdomain_available
from zerver.forms import HomepageForm, check_subdomain_available
from zerver.decorator import do_two_factor_login
from zerver.views.auth import \
redirect_and_log_into_subdomain, start_two_factor_auth
@ -3489,10 +3489,6 @@ class DeactivateUserTest(ZulipTestCase):
self.assert_json_error(result, "Cannot deactivate the only user.")
class TestLoginPage(ZulipTestCase):
def test_login_page_wrong_subdomain_error(self) -> None:
result = self.client_get("/login/?subdomain=1")
self.assertIn(WRONG_SUBDOMAIN_ERROR, result.content.decode('utf8'))
@patch('django.http.HttpRequest.get_host')
def test_login_page_redirects_for_root_alias(self, mock_get_host: MagicMock) -> None:
mock_get_host.return_value = 'www.testserver'

View File

@ -22,7 +22,7 @@ from confirmation.models import Confirmation, create_confirmation_link
from zerver.context_processors import zulip_default_context, get_realm_from_request, \
login_context
from zerver.forms import HomepageForm, OurAuthenticationForm, \
WRONG_SUBDOMAIN_ERROR, DEACTIVATED_ACCOUNT_ERROR, ZulipPasswordResetForm, \
DEACTIVATED_ACCOUNT_ERROR, ZulipPasswordResetForm, \
AuthenticationTokenForm
from zerver.lib.mobile_auth_otp import otp_encrypt_api_key
from zerver.lib.push_notifications import push_notifications_enabled
@ -207,11 +207,6 @@ def maybe_send_to_registration(request: HttpRequest, email: str, full_name: str=
context.update(extra_context)
return render(request, 'zerver/accounts_home.html', context=context)
def redirect_to_subdomain_login_url() -> HttpResponseRedirect:
login_url = reverse('django.contrib.auth.views.login')
redirect_url = login_url + '?subdomain=1'
return HttpResponseRedirect(redirect_url)
def register_remote_user(request: HttpRequest, email: str,
full_name: str='',
mobile_flow_otp: Optional[str]=None,
@ -678,14 +673,13 @@ def add_dev_login_context(realm: Optional[Realm], context: Dict[str, Any]) -> No
context['direct_users'] = [u for u in users if not (u.is_realm_admin or u.is_guest)]
def update_login_page_context(request: HttpRequest, context: Dict[str, Any]) -> None:
for key in ('email', 'subdomain', 'already_registered', 'is_deactivated'):
for key in ('email', 'already_registered', 'is_deactivated'):
try:
context[key] = request.GET[key]
except KeyError:
pass
context['deactivated_account_error'] = DEACTIVATED_ACCOUNT_ERROR
context['wrong_subdomain_error'] = WRONG_SUBDOMAIN_ERROR
class TwoFactorLoginView(BaseTwoFactorLoginView):
extra_context = None # type: ExtraContext

View File

@ -1111,8 +1111,11 @@ def social_auth_finish(backend: Any,
email_not_associated = return_data.get("email_not_associated")
if invalid_realm:
from zerver.views.auth import redirect_to_subdomain_login_url
return redirect_to_subdomain_login_url()
# User has passed an invalid subdomain param - this shouldn't happen in the normal flow,
# unless the user manually edits the param. In any case, it's most appropriate to just take
# them to find_account, as there isn't even an appropriate subdomain to take them to the login
# form on.
return HttpResponseRedirect(reverse('zerver.views.registration.find_account'))
if inactive_user:
return redirect_deactivated_user_to_login()