From 51d715d00ab813d69971f46e166d5fcb0747d1e6 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 1 Jul 2012 12:04:10 +0200 Subject: [PATCH 1/2] allows password and prefix for notebook fixes #1997 --- IPython/frontend/html/notebook/handlers.py | 6 +++--- IPython/frontend/html/notebook/notebookapp.py | 19 ++++++++++--------- .../html/notebook/static/js/loginwidget.js | 4 ++-- .../html/notebook/templates/login.html | 2 +- .../html/notebook/templates/logout.html | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 06bfa883d..c4a755125 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -208,7 +208,7 @@ class LoginHandler(AuthenticatedHandler): def _render(self, message=None): self.render('login.html', - next=self.get_argument('next', default='/'), + next=self.get_argument('next', default=self.application.ipython_app.base_project_url), read_only=self.read_only, logged_in=self.logged_in, login_available=self.login_available, @@ -218,7 +218,7 @@ class LoginHandler(AuthenticatedHandler): def get(self): if self.current_user: - self.redirect(self.get_argument('next', default='/')) + self.redirect(self.get_argument('next', default=self.application.ipython_app.base_project_url)) else: self._render() @@ -231,7 +231,7 @@ class LoginHandler(AuthenticatedHandler): self._render(message={'error': 'Invalid password'}) return - self.redirect(self.get_argument('next', default='/')) + self.redirect(self.get_argument('next', default=self.application.ipython_app.base_project_url)) class LogoutHandler(AuthenticatedHandler): diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 7073ed92e..398d67e79 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -140,15 +140,6 @@ class NotebookWebApplication(web.Application): (r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler), (r"/clusters/%s" % _profile_regex, ClusterProfileHandler), ] - settings = dict( - template_path=os.path.join(os.path.dirname(__file__), "templates"), - static_path=os.path.join(os.path.dirname(__file__), "static"), - cookie_secret=os.urandom(1024), - login_url="/login", - ) - - # allow custom overrides for the tornado web app. - settings.update(settings_overrides) # Python < 2.6.5 doesn't accept unicode keys in f(**kwargs), and # base_project_url will always be unicode, which will in turn @@ -160,6 +151,16 @@ class NotebookWebApplication(web.Application): # and thus guaranteed to be ASCII: 'héllo' is really 'h%C3%A9llo'. base_project_url = py3compat.unicode_to_str(base_project_url, 'ascii') + settings = dict( + template_path=os.path.join(os.path.dirname(__file__), "templates"), + static_path=os.path.join(os.path.dirname(__file__), "static"), + cookie_secret=os.urandom(1024), + login_url="%s/login"%(base_project_url.rstrip('/')), + ) + + # allow custom overrides for the tornado web app. + settings.update(settings_overrides) + # prepend base_project_url onto the patterns that we match new_handlers = [] for handler in handlers: diff --git a/IPython/frontend/html/notebook/static/js/loginwidget.js b/IPython/frontend/html/notebook/static/js/loginwidget.js index 288772a94..1277180fc 100644 --- a/IPython/frontend/html/notebook/static/js/loginwidget.js +++ b/IPython/frontend/html/notebook/static/js/loginwidget.js @@ -29,10 +29,10 @@ var IPython = (function (IPython) { LoginWidget.prototype.bind_events = function () { var that = this; this.element.find("button#logout").click(function () { - window.location = "/logout"; + window.location = "logout"; }); this.element.find("button#login").click(function () { - window.location = "/login"; + window.location = "login"; }); }; diff --git a/IPython/frontend/html/notebook/templates/login.html b/IPython/frontend/html/notebook/templates/login.html index 34f2a0e1d..6c436b0e5 100644 --- a/IPython/frontend/html/notebook/templates/login.html +++ b/IPython/frontend/html/notebook/templates/login.html @@ -16,7 +16,7 @@
{% if login_available %} -
+ Password:
diff --git a/IPython/frontend/html/notebook/templates/logout.html b/IPython/frontend/html/notebook/templates/logout.html index e31f0ac1c..e27036fa8 100644 --- a/IPython/frontend/html/notebook/templates/logout.html +++ b/IPython/frontend/html/notebook/templates/logout.html @@ -23,9 +23,9 @@ {% end %} {% if read_only or not login_available %} - Proceed to the dashboard. + Proceed to the dashboard. {% else %} - Proceed to the login page. + Proceed to the login page. {% end %} From 3c743846a7db5c159e7f2f3591daf8fe2e5a8bad Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 1 Jul 2012 21:58:30 +0200 Subject: [PATCH 2/2] use full base_url in html and js --- IPython/frontend/html/notebook/static/js/loginwidget.js | 5 +++-- IPython/frontend/html/notebook/templates/login.html | 2 +- IPython/frontend/html/notebook/templates/logout.html | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/loginwidget.js b/IPython/frontend/html/notebook/static/js/loginwidget.js index 1277180fc..d0d739e3b 100644 --- a/IPython/frontend/html/notebook/static/js/loginwidget.js +++ b/IPython/frontend/html/notebook/static/js/loginwidget.js @@ -10,6 +10,7 @@ //============================================================================ var IPython = (function (IPython) { + var base_url = $('body').data('baseProjectUrl'); var LoginWidget = function (selector) { this.selector = selector; @@ -29,10 +30,10 @@ var IPython = (function (IPython) { LoginWidget.prototype.bind_events = function () { var that = this; this.element.find("button#logout").click(function () { - window.location = "logout"; + window.location = base_url+"logout"; }); this.element.find("button#login").click(function () { - window.location = "login"; + window.location = base_url+"login"; }); }; diff --git a/IPython/frontend/html/notebook/templates/login.html b/IPython/frontend/html/notebook/templates/login.html index 6c436b0e5..2ac7b653d 100644 --- a/IPython/frontend/html/notebook/templates/login.html +++ b/IPython/frontend/html/notebook/templates/login.html @@ -16,7 +16,7 @@
{% if login_available %} -
+ Password:
diff --git a/IPython/frontend/html/notebook/templates/logout.html b/IPython/frontend/html/notebook/templates/logout.html index e27036fa8..9ea495bb3 100644 --- a/IPython/frontend/html/notebook/templates/logout.html +++ b/IPython/frontend/html/notebook/templates/logout.html @@ -23,9 +23,9 @@ {% end %} {% if read_only or not login_available %} - Proceed to the dashboard. + Proceed to the dashboard. {% else %} - Proceed to the login page. + Proceed to the login page. {% end %}