Skip to content

Commit

Permalink
Merge pull request #2073 from Carreau/fixes-1997
Browse files Browse the repository at this point in the history
Allows both password and prefix for notebook at the same time.
  • Loading branch information
Carreau committed Jul 12, 2012
2 parents 7cbe62f + 7dacc59 commit 93c6c0f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions IPython/frontend/html/notebook/handlers.py
Expand Up @@ -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,
Expand All @@ -218,7 +218,7 @@ def _render(self, message=None):

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()

Expand All @@ -231,7 +231,7 @@ def post(self):
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):
Expand Down
19 changes: 10 additions & 9 deletions IPython/frontend/html/notebook/notebookapp.py
Expand Up @@ -140,15 +140,6 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
(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
Expand All @@ -160,6 +151,16 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
# 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:
Expand Down
5 changes: 3 additions & 2 deletions IPython/frontend/html/notebook/static/js/loginwidget.js
Expand Up @@ -10,6 +10,7 @@
//============================================================================

var IPython = (function (IPython) {
var base_url = $('body').data('baseProjectUrl');

var LoginWidget = function (selector) {
this.selector = selector;
Expand All @@ -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";
});
};

Expand Down
2 changes: 1 addition & 1 deletion IPython/frontend/html/notebook/templates/login.html
Expand Up @@ -16,7 +16,7 @@
<div id="main_app">

{% if login_available %}
<form action="/login?next={{url_escape(next)}}" method="post">
<form action="{{base_project_url}}login?next={{url_escape(next)}}" method="post">
Password: <input type="password" class='ui-widget ui-widget-content' name="password" id="password_input">
<input type="submit" value="Log in" id="login_submit">
</form>
Expand Down
4 changes: 2 additions & 2 deletions IPython/frontend/html/notebook/templates/logout.html
Expand Up @@ -23,9 +23,9 @@
{% end %}

{% if read_only or not login_available %}
Proceed to the <a href="/">dashboard</a>.
Proceed to the <a href="{{base_project_url}}">dashboard</a>.
{% else %}
Proceed to the <a href="/login">login page</a>.
Proceed to the <a href="{{base_project_url}}login">login page</a>.
{% end %}


Expand Down

0 comments on commit 93c6c0f

Please sign in to comment.