Show More
@@ -139,22 +139,29 class AuthenticatedHandler(RequestHandler): | |||
|
139 | 139 | return user_id |
|
140 | 140 | |
|
141 | 141 | @property |
|
142 | def logged_in(self): | |
|
143 | """Is a user currently logged in? | |
|
144 | ||
|
145 | """ | |
|
146 | user = self.get_current_user() | |
|
147 | return (user and not user == 'anonymous') | |
|
148 | ||
|
149 | @property | |
|
150 | def login_available(self): | |
|
151 | """May a user proceed to log in? | |
|
152 | ||
|
153 | This returns True if login capability is available, irrespective of | |
|
154 | whether the user is already logged in or not. | |
|
155 | ||
|
156 | """ | |
|
157 | return bool(self.application.password) | |
|
158 | ||
|
159 | @property | |
|
142 | 160 | def read_only(self): |
|
143 | 161 | """Is the notebook read-only? |
|
144 | 162 | |
|
145 | None -- notebook is read-only, but the user can log-in to edit | |
|
146 | True -- notebook is read-only, no log-in available | |
|
147 | False -- no read-only mode available, user must log in | |
|
148 | ||
|
149 | 163 | """ |
|
150 | user = self.get_current_user() | |
|
151 | if user and user != 'anonymous': | |
|
152 | return False | |
|
153 | elif self.application.read_only: | |
|
154 | if self.application.password: | |
|
155 | return None | |
|
156 | else: | |
|
157 | return True | |
|
164 | return self.application.read_only | |
|
158 | 165 | |
|
159 | 166 | @property |
|
160 | 167 | def ws_url(self): |
@@ -177,6 +184,8 class ProjectDashboardHandler(AuthenticatedHandler): | |||
|
177 | 184 | 'projectdashboard.html', project=project, |
|
178 | 185 | base_project_url=u'/', base_kernel_url=u'/', |
|
179 | 186 | read_only=self.read_only, |
|
187 | logged_in=self.logged_in, | |
|
188 | login_available=self.login_available | |
|
180 | 189 | ) |
|
181 | 190 | |
|
182 | 191 | |
@@ -186,6 +195,8 class LoginHandler(AuthenticatedHandler): | |||
|
186 | 195 | self.render('login.html', |
|
187 | 196 | next=self.get_argument('next', default='/'), |
|
188 | 197 | read_only=self.read_only, |
|
198 | logged_in=self.logged_in, | |
|
199 | login_available=self.login_available, | |
|
189 | 200 | message=message |
|
190 | 201 | ) |
|
191 | 202 | |
@@ -211,7 +222,17 class LogoutHandler(AuthenticatedHandler): | |||
|
211 | 222 | |
|
212 | 223 | def get(self): |
|
213 | 224 | self.clear_cookie('username') |
|
214 | self.render('logout.html', message={'info': 'Successfully logged out.'}) | |
|
225 | if self.login_available: | |
|
226 | message = {'info': 'Successfully logged out.'} | |
|
227 | else: | |
|
228 | message = {'warning': 'Cannot log out. Notebook authentication ' | |
|
229 | 'is disabled.'} | |
|
230 | ||
|
231 | self.render('logout.html', | |
|
232 | read_only=self.read_only, | |
|
233 | logged_in=self.logged_in, | |
|
234 | login_available=self.login_available, | |
|
235 | message=message) | |
|
215 | 236 | |
|
216 | 237 | |
|
217 | 238 | class NewHandler(AuthenticatedHandler): |
@@ -227,6 +248,8 class NewHandler(AuthenticatedHandler): | |||
|
227 | 248 | base_project_url=u'/', base_kernel_url=u'/', |
|
228 | 249 | kill_kernel=False, |
|
229 | 250 | read_only=False, |
|
251 | logged_in=self.logged_in, | |
|
252 | login_available=self.login_available, | |
|
230 | 253 | mathjax_url=self.application.ipython_app.mathjax_url, |
|
231 | 254 | ) |
|
232 | 255 | |
@@ -246,6 +269,8 class NamedNotebookHandler(AuthenticatedHandler): | |||
|
246 | 269 | base_project_url=u'/', base_kernel_url=u'/', |
|
247 | 270 | kill_kernel=False, |
|
248 | 271 | read_only=self.read_only, |
|
272 | logged_in=self.logged_in, | |
|
273 | login_available=self.login_available, | |
|
249 | 274 | mathjax_url=self.application.ipython_app.mathjax_url, |
|
250 | 275 | ) |
|
251 | 276 |
@@ -28,18 +28,9 $(document).ready(function () { | |||
|
28 | 28 | $('div#right_panel').addClass('box-flex'); |
|
29 | 29 | |
|
30 | 30 | IPython.read_only = $('meta[name=read_only]').attr("content") == 'True'; |
|
31 | ||
|
32 | 31 | IPython.notebook_list = new IPython.NotebookList('div#notebook_list'); |
|
33 | 32 | IPython.login_widget = new IPython.LoginWidget('span#login_widget'); |
|
34 | ||
|
35 | if (IPython.read_only){ | |
|
36 | // unhide login button if it's relevant | |
|
37 | $('span#login_widget').removeClass('hidden'); | |
|
38 | $('#drag_info').remove(); | |
|
39 | } else { | |
|
40 | $('#new_notebook').removeClass('hidden'); | |
|
41 | $('#drag_info').removeClass('hidden'); | |
|
42 | } | |
|
33 | ||
|
43 | 34 | IPython.notebook_list.load_list(); |
|
44 | 35 | |
|
45 | 36 | // These have display: none in the css file and are made visible here to prevent FLOUC. |
@@ -23,9 +23,9 | |||
|
23 | 23 | <div id="header"> |
|
24 | 24 | <span id="ipython_notebook"><h1><img src='static/ipynblogo.png' alt='IPython Notebook'/></h1></span> |
|
25 | 25 | <span id="login_widget"> |
|
26 | {% if current_user and current_user != 'anonymous' %} | |
|
26 | {% if logged_in %} | |
|
27 | 27 | <button id="logout">Logout</button> |
|
28 | {% elif read_only is None %} | |
|
28 | {% elif login_available and not logged_in %} | |
|
29 | 29 | <button id="login">Login</button> |
|
30 | 30 | {% end %} |
|
31 | 31 | </span> |
@@ -1,10 +1,16 | |||
|
1 | 1 | {% extends layout.html %} |
|
2 | 2 | |
|
3 | 3 | {% block content_panel %} |
|
4 | ||
|
5 | {% if login_available %} | |
|
6 | ||
|
4 | 7 | <form action="/login?next={{url_escape(next)}}" method="post"> |
|
5 | 8 | Password: <input type="password" name="password" id="focus"> |
|
6 | 9 | <input type="submit" value="Sign in" id="signin"> |
|
7 | 10 | </form> |
|
11 | ||
|
12 | {% end %} | |
|
13 | ||
|
8 | 14 | {% end %} |
|
9 | 15 | |
|
10 | 16 | {% block script %} |
@@ -1,11 +1,19 | |||
|
1 | 1 | {% extends layout.html %} |
|
2 | 2 | |
|
3 | 3 | {% block content_panel %} |
|
4 | {% if current_user and current_user != 'anonymous' %} | |
|
5 | Proceed to the <a href="/">front page</a>. | |
|
6 | {% else %} | |
|
7 |
Proceed to the <a href="/ |
|
|
8 | {% end %} | |
|
4 | <ul> | |
|
5 | {% if read_only or not login_available %} | |
|
6 | ||
|
7 | Proceed to the <a href="/">list of notebooks</a>.</li> | |
|
8 | ||
|
9 | {% else %} | |
|
10 | ||
|
11 | Proceed to the <a href="/login">login page</a>.</li> | |
|
12 | ||
|
13 | {% end %} | |
|
14 | ||
|
15 | </ul> | |
|
16 | ||
|
9 | 17 | {% end %} |
|
10 | 18 | |
|
11 | 19 | {% block script %} |
@@ -52,9 +52,9 | |||
|
52 | 52 | <span id="login_widget"> |
|
53 | 53 | {% comment This is a temporary workaround to hide the logout button %} |
|
54 | 54 | {% comment when appropriate until notebook.html is templated %} |
|
55 | {% if current_user and current_user != 'anonymous' %} | |
|
55 | {% if logged_in %} | |
|
56 | 56 | <button id="logout">Logout</button> |
|
57 | {% elif read_only is None %} | |
|
57 | {% elif not logged_in and login_available %} | |
|
58 | 58 | <button id="login">Login</button> |
|
59 | 59 | {% end %} |
|
60 | 60 | </span> |
@@ -19,17 +19,19 data-base-kernel-url={{base_kernel_url}} | |||
|
19 | 19 | {% end %} |
|
20 | 20 | |
|
21 | 21 | {% block content_panel %} |
|
22 | {% if logged_in or not read_only %} | |
|
23 | ||
|
22 | 24 | <div id="content_toolbar"> |
|
23 |
<span id="drag_info" |
|
|
25 | <span id="drag_info">Drag files onto the list to import | |
|
24 | 26 | notebooks.</span> |
|
25 | 27 | |
|
26 | {% if read_only == False %} | |
|
27 |
< |
|
|
28 | <button id="new_notebook" class="hidden">New Notebook</button> | |
|
29 | </span> | |
|
30 | {% end %} | |
|
31 | ||
|
28 | <span id="notebooks_buttons"> | |
|
29 | <button id="new_notebook">New Notebook</button> | |
|
30 | </span> | |
|
32 | 31 | </div> |
|
32 | ||
|
33 | {% end %} | |
|
34 | ||
|
33 | 35 | <div id="notebook_list"> |
|
34 | 36 | <div id="project_name"><h2>{{project}}</h2></div> |
|
35 | 37 | </div> |
General Comments 0
You need to be logged in to leave comments.
Login now