diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 242d47b..f275d18 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -137,17 +137,32 @@ class AuthenticatedHandler(RequestHandler): if not self.application.password and not self.application.read_only: user_id = 'anonymous' return user_id - + + @property + def logged_in(self): + """Is a user currently logged in? + + """ + user = self.get_current_user() + return (user and not user == 'anonymous') + + @property + def login_available(self): + """May a user proceed to log in? + + This returns True if login capability is available, irrespective of + whether the user is already logged in or not. + + """ + return bool(self.application.password) + @property def read_only(self): - if self.application.read_only: - if self.application.password: - return self.get_current_user() is None - else: - return True - else: - return False - + """Is the notebook read-only? + + """ + return self.application.read_only + @property def ws_url(self): """websocket url matching the current request @@ -169,6 +184,8 @@ class ProjectDashboardHandler(AuthenticatedHandler): 'projectdashboard.html', project=project, base_project_url=u'/', base_kernel_url=u'/', read_only=self.read_only, + logged_in=self.logged_in, + login_available=self.login_available ) @@ -178,6 +195,8 @@ class LoginHandler(AuthenticatedHandler): self.render('login.html', next=self.get_argument('next', default='/'), read_only=self.read_only, + logged_in=self.logged_in, + login_available=self.login_available, message=message ) @@ -203,7 +222,17 @@ class LogoutHandler(AuthenticatedHandler): def get(self): self.clear_cookie('username') - self.render('logout.html', message={'info': 'Successfully logged out.'}) + if self.login_available: + message = {'info': 'Successfully logged out.'} + else: + message = {'warning': 'Cannot log out. Notebook authentication ' + 'is disabled.'} + + self.render('logout.html', + read_only=self.read_only, + logged_in=self.logged_in, + login_available=self.login_available, + message=message) class NewHandler(AuthenticatedHandler): @@ -219,6 +248,8 @@ class NewHandler(AuthenticatedHandler): base_project_url=u'/', base_kernel_url=u'/', kill_kernel=False, read_only=False, + logged_in=self.logged_in, + login_available=self.login_available, mathjax_url=self.application.ipython_app.mathjax_url, ) @@ -238,6 +269,8 @@ class NamedNotebookHandler(AuthenticatedHandler): base_project_url=u'/', base_kernel_url=u'/', kill_kernel=False, read_only=self.read_only, + logged_in=self.logged_in, + login_available=self.login_available, mathjax_url=self.application.ipython_app.mathjax_url, ) diff --git a/IPython/frontend/html/notebook/static/js/loginwidget.js b/IPython/frontend/html/notebook/static/js/loginwidget.js index 6ba8075..763118e 100644 --- a/IPython/frontend/html/notebook/static/js/loginwidget.js +++ b/IPython/frontend/html/notebook/static/js/loginwidget.js @@ -22,12 +22,16 @@ var IPython = (function (IPython) { LoginWidget.prototype.style = function () { this.element.find('button#logout').button(); + this.element.find('button#login').button(); }; LoginWidget.prototype.bind_events = function () { var that = this; this.element.find("button#logout").click(function () { window.location = "/logout"; }); + this.element.find("button#login").click(function () { + window.location = "/login"; + }); }; // Set module variables diff --git a/IPython/frontend/html/notebook/static/js/projectdashboardmain.js b/IPython/frontend/html/notebook/static/js/projectdashboardmain.js index a62caa3..516b406 100644 --- a/IPython/frontend/html/notebook/static/js/projectdashboardmain.js +++ b/IPython/frontend/html/notebook/static/js/projectdashboardmain.js @@ -28,18 +28,9 @@ $(document).ready(function () { $('div#right_panel').addClass('box-flex'); IPython.read_only = $('meta[name=read_only]').attr("content") == 'True'; - IPython.notebook_list = new IPython.NotebookList('div#notebook_list'); IPython.login_widget = new IPython.LoginWidget('span#login_widget'); - - if (IPython.read_only){ - // unhide login button if it's relevant - $('span#login_widget').removeClass('hidden'); - $('#drag_info').remove(); - } else { - $('#new_notebook').removeClass('hidden'); - $('#drag_info').removeClass('hidden'); - } + IPython.notebook_list.load_list(); // These have display: none in the css file and are made visible here to prevent FLOUC. diff --git a/IPython/frontend/html/notebook/templates/layout.html b/IPython/frontend/html/notebook/templates/layout.html index 7d6b5f5..8d5e4d2 100644 --- a/IPython/frontend/html/notebook/templates/layout.html +++ b/IPython/frontend/html/notebook/templates/layout.html @@ -22,11 +22,19 @@ diff --git a/IPython/frontend/html/notebook/templates/login.html b/IPython/frontend/html/notebook/templates/login.html index 08b71a6..4c5b2c0 100644 --- a/IPython/frontend/html/notebook/templates/login.html +++ b/IPython/frontend/html/notebook/templates/login.html @@ -1,8 +1,26 @@ {% extends layout.html %} {% block content_panel %} + + {% if login_available %} +
- Password: + Password:
+ + {% end %} + +{% end %} + +{% block login_widget %} +{% end %} + +{% block script %} + {% end %} diff --git a/IPython/frontend/html/notebook/templates/logout.html b/IPython/frontend/html/notebook/templates/logout.html index f3c7b53..8087508 100644 --- a/IPython/frontend/html/notebook/templates/logout.html +++ b/IPython/frontend/html/notebook/templates/logout.html @@ -1,5 +1,28 @@ {% extends layout.html %} {% block content_panel %} -Proceed to the login page. + + +{% end %} + +{% block login_widget %} +{% end %} + +{% block script %} + {% end %} diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 8e6e70d..ab160a1 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -29,8 +29,10 @@ - - + + {% comment In the notebook, the read-only flag is used to determine %} + {% comment whether to hide the side panels and switch off input %} + @@ -52,8 +54,10 @@ {% comment This is a temporary workaround to hide the logout button %} {% comment when appropriate until notebook.html is templated %} - {% if current_user and current_user != 'anonymous' %} + {% if logged_in %} + {% elif not logged_in and login_available %} + {% end %} diff --git a/IPython/frontend/html/notebook/templates/projectdashboard.html b/IPython/frontend/html/notebook/templates/projectdashboard.html index 631e2bd..d3036af 100644 --- a/IPython/frontend/html/notebook/templates/projectdashboard.html +++ b/IPython/frontend/html/notebook/templates/projectdashboard.html @@ -19,12 +19,19 @@ data-base-kernel-url={{base_kernel_url}} {% end %} {% block content_panel %} + {% if logged_in or not read_only %} +
- + Drag files onto the list to import + notebooks. + - +
+ + {% end %} +

{{project}}