Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Login/out button cleanups #1079

Merged
merged 7 commits into from

3 participants

Stefan van der Walt Min RK Fernando Perez
Stefan van der Walt
  • Display a login button when viewing the notebook in read-only mode.
  • On the login page, focus on the password field by default.
  • Correctly style login / logout buttons.
  • In read-only mode, redirect to "/" after logout, not "/login".
Min RK
Owner

The login button should not appear in 'default' mode, where it does exactly nothing. Do you know why your PR disables the hidden logic that was there before?

Min RK
Owner

Also, what should happen in the case where read-only mode is the only one available (no password is set)? In your case, you can enter any password, and login just redirects you to the front page. This suggests that login was successful, but it obviously wasn't, as the login button remains (and login is impossible).

I should think that at the very least, trying to login should always fail, and ideally the login button should be disabled in this case as well.

Stefan van der Walt

@minrk The current logic is already broken; it never shows a login button in read-only mode. The problem is that we only make a distinction between read-only vs. non-read-only modes, whereas there is a third case: read-only but with the option to log in. So maybe we can give the read-only property some more states. I'll have a look at how to best accomplish this.

Stefan van der Walt

OK, I see we do have three states in there: None, True and False. I'll check for these separately.

Min RK
Owner

I think the existence of a non-empty password is the thing that tells you whether login is possible.

Stefan van der Walt

Yes, but we don't want to do that logic inside of the templates, if possible.

Stefan van der Walt

@minrk This is the basic idea I had in mind. There are different ways to implement it (e.g., have read_only return a string instead of True, False, None), but this seems to work for now.

Min RK
Owner

There is actually one more case to handle: no password set, and not read-only. This is by far the most common case, and should not draw any login/logout buttons.

Fernando Perez
Owner

@stefanv, this PR needs a rebase as it's now conflicting. Do you think you'll have time to finish it up before we cut the 0.12 RC? That basically means finish it today...

Stefan van der Walt
Fernando Perez
Owner

ok!

Stefan van der Walt

@fperez @minrk This change should make the logic a lot clearer. There are three states that need to be monitored, each now associated with a method:

  • Was the notebook started with the "read-only" flag (method: read_only)
  • Can the user log in, thereby making the notebook rw (method: login_available)
  • Is the current user logged in? (method: logged_in)

I also removed display logic from the javascript, and moved it to the template. Finally, the password field now receives automatic focus.

Min RK
Owner

Awesome, much cleaner than it was before, and I've tried every combination of being logged in / out having password defined / undefined, and readonly, and it seems to always behave how I expect.

The only thing that didn't seem perfect was the fact that login/logout buttons are still drawn on the login page. If that's an easy fix, go for it, otherwise I'm +1 on merging right now.

Stefan van der Walt

That's a trivial fix. Give me one second.

Stefan van der Walt

@minrk That should do it.

Stefan van der Walt stefanv Correctly set read_only meta name for use in javascript. Note that th…
…is has a different meaning than in the Python code: not whether the read-only flag was specified upon launch, but whether the notebook is in read-only mode and input should be disabled.
5fd0e96
Fernando Perez fperez merged commit 2bfc449 into from
Fernando Perez fperez referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 14, 2011
  1. Stefan van der Walt
  2. Stefan van der Walt
  3. Stefan van der Walt
  4. Stefan van der Walt
  5. Stefan van der Walt

    Split read-only logic into three functions: read_only, logged_in, and…

    stefanv authored
    … login_available. Move display logic from javascript into templates.
  6. Stefan van der Walt
  7. Stefan van der Walt

    Correctly set read_only meta name for use in javascript. Note that th…

    stefanv authored
    …is has a different meaning than in the Python code: not whether the read-only flag was specified upon launch, but whether the notebook is in read-only mode and input should be disabled.
This page is out of date. Refresh to see the latest.
53 IPython/frontend/html/notebook/handlers.py
View
@@ -137,17 +137,32 @@ def get_current_user(self):
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 @@ def get(self):
'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 @@ def _render(self, message=None):
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 @@ def get(self):
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 @@ def get(self, notebook_id):
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,
)
4 IPython/frontend/html/notebook/static/js/loginwidget.js
View
@@ -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
11 IPython/frontend/html/notebook/static/js/projectdashboardmain.js
View
@@ -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.
18 IPython/frontend/html/notebook/templates/layout.html
View
@@ -22,11 +22,19 @@
<div id="header">
<span id="ipython_notebook"><h1><img src='static/ipynblogo.png' alt='IPython Notebook'/></h1></span>
- <span id="login_widget">
- {% if current_user and current_user != 'anonymous' %}
- <button id="logout">Logout</button>
- {% end %}
- </span>
+
+ {% block login_widget %}
+
+ <span id="login_widget">
+ {% if logged_in %}
+ <button id="logout">Logout</button>
+ {% elif login_available and not logged_in %}
+ <button id="login">Login</button>
+ {% end %}
+ </span>
+
+ {% end %}
+
{% block header %}
{% end %}
</div>
20 IPython/frontend/html/notebook/templates/login.html
View
@@ -1,8 +1,26 @@
{% extends layout.html %}
{% block content_panel %}
+
+ {% if login_available %}
+
<form action="/login?next={{url_escape(next)}}" method="post">
- Password: <input type="password" name="password">
+ Password: <input type="password" name="password" id="focus">
<input type="submit" value="Sign in" id="signin">
</form>
+
+ {% end %}
+
+{% end %}
+
+{% block login_widget %}
+{% end %}
+
+{% block script %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ IPython.login_widget = new IPython.LoginWidget('span#login_widget');
+ $('#focus').focus();
+ });
+</script>
{% end %}
25 IPython/frontend/html/notebook/templates/logout.html
View
@@ -1,5 +1,28 @@
{% extends layout.html %}
{% block content_panel %}
-Proceed to the <a href="/login">login page</a>.
+ <ul>
+ {% if read_only or not login_available %}
+
+ Proceed to the <a href="/">list of notebooks</a>.</li>
+
+ {% else %}
+
+ Proceed to the <a href="/login">login page</a>.</li>
+
+ {% end %}
+
+ </ul>
+
+{% end %}
+
+{% block login_widget %}
+{% end %}
+
+{% block script %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ IPython.login_widget = new IPython.LoginWidget('span#login_widget');
+ });
+</script>
{% end %}
10 IPython/frontend/html/notebook/templates/notebook.html
View
@@ -29,8 +29,10 @@
<link rel="stylesheet" href="static/css/base.css" type="text/css" />
<link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
<link rel="stylesheet" href="static/css/renderedhtml.css" type="text/css" />
-
- <meta name="read_only" content="{{read_only}}"/>
+
+ {% comment In the notebook, the read-only flag is used to determine %}
+ {% comment whether to hide the side panels and switch off input %}
+ <meta name="read_only" content="{{read_only and not logged_in}}"/>
</head>
@@ -52,8 +54,10 @@
<span id="login_widget">
{% 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 %}
<button id="logout">Logout</button>
+ {% elif not logged_in and login_available %}
+ <button id="login">Login</button>
{% end %}
</span>
11 IPython/frontend/html/notebook/templates/projectdashboard.html
View
@@ -19,12 +19,19 @@
{% end %}
{% block content_panel %}
+ {% if logged_in or not read_only %}
+
<div id="content_toolbar">
- <span id="drag_info" class="hidden">Drag files onto the list to import notebooks.</span>
+ <span id="drag_info">Drag files onto the list to import
+ notebooks.</span>
+
<span id="notebooks_buttons">
- <button id="new_notebook" class="hidden">New Notebook</button>
+ <button id="new_notebook">New Notebook</button>
</span>
</div>
+
+ {% end %}
+
<div id="notebook_list">
<div id="project_name"><h2>{{project}}</h2></div>
</div>
Something went wrong with that request. Please try again.