mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 07:23:00 +00:00
Redirect user to login page when not logged in
This commit is contained in:
@@ -461,6 +461,7 @@ class UserSpawnHandler(BaseHandler):
|
||||
redirect her to /user/alice/notebooks/mynotebook.ipynb, which should
|
||||
in turn call this function.
|
||||
"""
|
||||
|
||||
@gen.coroutine
|
||||
def get(self, name, user_path):
|
||||
current_user = self.get_current_user()
|
||||
@@ -488,11 +489,18 @@ class UserSpawnHandler(BaseHandler):
|
||||
if self.use_subdomains:
|
||||
target = current_user.host + target
|
||||
self.redirect(target)
|
||||
else:
|
||||
elif current_user:
|
||||
# logged in as a different user, redirect
|
||||
target = url_path_join(self.base_url, 'user', current_user.name,
|
||||
user_path or '')
|
||||
self.redirect(target)
|
||||
else:
|
||||
# not logged in, clear any cookies and reload
|
||||
self.clear_login_cookie()
|
||||
self.redirect(url_concat(
|
||||
self.settings['login_url'],
|
||||
{'next': self.request.uri},
|
||||
))
|
||||
|
||||
|
||||
class CSPReportHandler(BaseHandler):
|
||||
|
@@ -1,6 +1,6 @@
|
||||
"""Tests for HTML pages"""
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import urlencode, urlparse
|
||||
|
||||
import requests
|
||||
|
||||
@@ -165,6 +165,14 @@ def test_user_redirect(app):
|
||||
path = urlparse(r.url).path
|
||||
assert path == '/user/%s/test.ipynb' % name
|
||||
|
||||
r = get_page('/user/baduser/test.ipynb', app)
|
||||
r.raise_for_status()
|
||||
print(urlparse(r.url))
|
||||
path = urlparse(r.url).path
|
||||
assert path == '/hub/login'
|
||||
query = urlparse(r.url).query
|
||||
assert query == urlencode({'next': '/hub/user/baduser/test.ipynb'})
|
||||
|
||||
|
||||
def test_static_files(app):
|
||||
base_url = ujoin(public_url(app), app.hub.server.base_url)
|
||||
|
Reference in New Issue
Block a user