mirror of https://github.com/zulip/zulip.git
login_redirects: Make redirects to narrows from login page work.
This commit is contained in:
parent
1e48dac8f3
commit
b62bdde303
|
@ -57,7 +57,13 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
if (window.location.hash.substring(0, 1) === "#") {
|
||||
document.login_form.action += window.location.hash;
|
||||
/* We append the location.hash to the formaction so that URL can be
|
||||
preserved after user is logged in. See this:
|
||||
https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */
|
||||
$("input[name='direct_email']").each(function () {
|
||||
var new_formaction = $(this).attr('formaction') + '/' + window.location.hash;
|
||||
$(this).attr('formaction', new_formaction);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
|
||||
{% if google_auth_enabled %}
|
||||
<div class="login-google">
|
||||
<form class="form-inline" action="{{ url('zerver.views.auth.start_google_oauth2') }}" method="get">
|
||||
<form id='google_login_form' class="form-inline" action="{{ url('zerver.views.auth.start_google_oauth2') }}" method="get">
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
<button class="login-social-button login-google-button full-width">{{ _('Log in with Google') }}</button>
|
||||
</form>
|
||||
|
@ -134,7 +134,7 @@
|
|||
|
||||
{% if github_auth_enabled %}
|
||||
<div class="login-github">
|
||||
<form class="form-inline github-wrapper" action="{{ url('login-social', args=('github',)) }}" method="get">
|
||||
<form id='social_login_form' class="form-inline github-wrapper" action="{{ url('login-social', args=('github',)) }}" method="get">
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
<button class="login-social-button login-github-button github">{{ _('Log in with GitHub') }}</button>
|
||||
</form>
|
||||
|
@ -157,7 +157,13 @@
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
if (window.location.hash.substring(0, 1) === "#") {
|
||||
document.login_form.action += window.location.hash;
|
||||
/* We append the location.hash to the formaction so that URL can be
|
||||
preserved after user is logged in. See this:
|
||||
https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */
|
||||
var email_formaction = $("#login_form").attr('action');
|
||||
$("#login_form").attr('action', email_formaction + '/' + window.location.hash);
|
||||
$("#google_login_form input[name='next']").attr('value', '/' + window.location.hash);
|
||||
$("#social_login_form input[name='next']").attr('value', '/' + window.location.hash);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -642,6 +642,12 @@ class GitHubAuthBackendTest(ZulipTestCase):
|
|||
self.assertIn('is_signup=0', result.url)
|
||||
self.assertIn('image_path', result.url)
|
||||
|
||||
result = self.client_get('/accounts/login/social/github',
|
||||
{'next': '/#narrow/stream/7-test-here'})
|
||||
self.assertIn(reverse('social:begin', args=['github']), result.url)
|
||||
self.assertIn('is_signup=0', result.url)
|
||||
self.assertIn('narrow', result.url)
|
||||
|
||||
def test_signup_url(self) -> None:
|
||||
result = self.client_get('/accounts/register/social/github')
|
||||
self.assertIn(reverse('social:begin', args=['github']), result.url)
|
||||
|
@ -830,6 +836,10 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
|
|||
self.assertEqual(res.status_code, 302)
|
||||
self.assertEqual(res.url, 'http://zulip.testserver/user_uploads/path_to_image')
|
||||
|
||||
res = test_redirect_to_next_url('/#narrow/stream/7-test-here')
|
||||
self.assertEqual(res.status_code, 302)
|
||||
self.assertEqual(res.url, 'http://zulip.testserver/#narrow/stream/7-test-here')
|
||||
|
||||
def test_log_into_subdomain(self) -> None:
|
||||
data = {'name': 'Full Name',
|
||||
'email': self.example_email("hamlet"),
|
||||
|
@ -1507,6 +1517,14 @@ class TestDevAuthBackend(ZulipTestCase):
|
|||
self.assertEqual(res.status_code, 302)
|
||||
self.assertEqual(res.url, 'http://zulip.testserver/user_uploads/path_to_image')
|
||||
|
||||
# In local Email based authentication we never make browser send the hash
|
||||
# to the backend. Rather we depend upon the browser's behaviour of persisting
|
||||
# hash anchors in between redirect requests. See below stackoverflow conversation
|
||||
# https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects
|
||||
res = do_local_login('/accounts/login/local/?next=#narrow/stream/7-test-here')
|
||||
self.assertEqual(res.status_code, 302)
|
||||
self.assertEqual(res.url, 'http://zulip.testserver')
|
||||
|
||||
def test_login_with_subdomain(self) -> None:
|
||||
user_profile = self.example_user('hamlet')
|
||||
email = user_profile.email
|
||||
|
|
Loading…
Reference in New Issue