mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
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:
committed by
Tim Abbott
parent
98a7cd85a2
commit
efb3065158
@@ -96,12 +96,6 @@ page can be easily identified in it's respective JavaScript file. -->
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if subdomain %}
|
|
||||||
<div class="alert">
|
|
||||||
{{ wrong_subdomain_error }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<button type="submit" name="button" class="full-width">
|
<button type="submit" name="button" class="full-width">
|
||||||
<img class="loader" src="/static/images/loader.svg" alt="" />
|
<img class="loader" src="/static/images/loader.svg" alt="" />
|
||||||
<span class="text">{{ _("Log in") }}</span>
|
<span class="text">{{ _("Log in") }}</span>
|
||||||
|
|||||||
@@ -885,7 +885,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
|
|||||||
result = self.social_auth_test(account_data_dict,
|
result = self.social_auth_test(account_data_dict,
|
||||||
subdomain='invalid', next='/user_uploads/image')
|
subdomain='invalid', next='/user_uploads/image')
|
||||||
self.assertEqual(result.status_code, 302)
|
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:
|
def test_social_auth_invalid_email(self) -> None:
|
||||||
account_data_dict = self.get_account_data_dict(email="invalid", name=self.name)
|
account_data_dict = self.get_account_data_dict(email="invalid", name=self.name)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from confirmation.models import Confirmation, create_confirmation_link, Multiuse
|
|||||||
one_click_unsubscribe_link
|
one_click_unsubscribe_link
|
||||||
from confirmation import settings as confirmation_settings
|
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.decorator import do_two_factor_login
|
||||||
from zerver.views.auth import \
|
from zerver.views.auth import \
|
||||||
redirect_and_log_into_subdomain, start_two_factor_auth
|
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.")
|
self.assert_json_error(result, "Cannot deactivate the only user.")
|
||||||
|
|
||||||
class TestLoginPage(ZulipTestCase):
|
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')
|
@patch('django.http.HttpRequest.get_host')
|
||||||
def test_login_page_redirects_for_root_alias(self, mock_get_host: MagicMock) -> None:
|
def test_login_page_redirects_for_root_alias(self, mock_get_host: MagicMock) -> None:
|
||||||
mock_get_host.return_value = 'www.testserver'
|
mock_get_host.return_value = 'www.testserver'
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from confirmation.models import Confirmation, create_confirmation_link
|
|||||||
from zerver.context_processors import zulip_default_context, get_realm_from_request, \
|
from zerver.context_processors import zulip_default_context, get_realm_from_request, \
|
||||||
login_context
|
login_context
|
||||||
from zerver.forms import HomepageForm, OurAuthenticationForm, \
|
from zerver.forms import HomepageForm, OurAuthenticationForm, \
|
||||||
WRONG_SUBDOMAIN_ERROR, DEACTIVATED_ACCOUNT_ERROR, ZulipPasswordResetForm, \
|
DEACTIVATED_ACCOUNT_ERROR, ZulipPasswordResetForm, \
|
||||||
AuthenticationTokenForm
|
AuthenticationTokenForm
|
||||||
from zerver.lib.mobile_auth_otp import otp_encrypt_api_key
|
from zerver.lib.mobile_auth_otp import otp_encrypt_api_key
|
||||||
from zerver.lib.push_notifications import push_notifications_enabled
|
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)
|
context.update(extra_context)
|
||||||
return render(request, 'zerver/accounts_home.html', context=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,
|
def register_remote_user(request: HttpRequest, email: str,
|
||||||
full_name: str='',
|
full_name: str='',
|
||||||
mobile_flow_otp: Optional[str]=None,
|
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)]
|
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:
|
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:
|
try:
|
||||||
context[key] = request.GET[key]
|
context[key] = request.GET[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
context['deactivated_account_error'] = DEACTIVATED_ACCOUNT_ERROR
|
context['deactivated_account_error'] = DEACTIVATED_ACCOUNT_ERROR
|
||||||
context['wrong_subdomain_error'] = WRONG_SUBDOMAIN_ERROR
|
|
||||||
|
|
||||||
class TwoFactorLoginView(BaseTwoFactorLoginView):
|
class TwoFactorLoginView(BaseTwoFactorLoginView):
|
||||||
extra_context = None # type: ExtraContext
|
extra_context = None # type: ExtraContext
|
||||||
|
|||||||
@@ -1111,8 +1111,11 @@ def social_auth_finish(backend: Any,
|
|||||||
email_not_associated = return_data.get("email_not_associated")
|
email_not_associated = return_data.get("email_not_associated")
|
||||||
|
|
||||||
if invalid_realm:
|
if invalid_realm:
|
||||||
from zerver.views.auth import redirect_to_subdomain_login_url
|
# User has passed an invalid subdomain param - this shouldn't happen in the normal flow,
|
||||||
return redirect_to_subdomain_login_url()
|
# 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:
|
if inactive_user:
|
||||||
return redirect_deactivated_user_to_login()
|
return redirect_deactivated_user_to_login()
|
||||||
|
|||||||
Reference in New Issue
Block a user