##// END OF EJS Templates
Merge pull request #1079 from stefanv/htmlnotebook_login_button...
Fernando Perez -
r5726:2bfc4492 merge
parent child Browse files
Show More
@@ -137,17 +137,32 b' class AuthenticatedHandler(RequestHandler):'
137 if not self.application.password and not self.application.read_only:
137 if not self.application.password and not self.application.read_only:
138 user_id = 'anonymous'
138 user_id = 'anonymous'
139 return user_id
139 return user_id
140
140
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
141 @property
159 @property
142 def read_only(self):
160 def read_only(self):
143 if self.application.read_only:
161 """Is the notebook read-only?
144 if self.application.password:
162
145 return self.get_current_user() is None
163 """
146 else:
164 return self.application.read_only
147 return True
165
148 else:
149 return False
150
151 @property
166 @property
152 def ws_url(self):
167 def ws_url(self):
153 """websocket url matching the current request
168 """websocket url matching the current request
@@ -169,6 +184,8 b' class ProjectDashboardHandler(AuthenticatedHandler):'
169 'projectdashboard.html', project=project,
184 'projectdashboard.html', project=project,
170 base_project_url=u'/', base_kernel_url=u'/',
185 base_project_url=u'/', base_kernel_url=u'/',
171 read_only=self.read_only,
186 read_only=self.read_only,
187 logged_in=self.logged_in,
188 login_available=self.login_available
172 )
189 )
173
190
174
191
@@ -178,6 +195,8 b' class LoginHandler(AuthenticatedHandler):'
178 self.render('login.html',
195 self.render('login.html',
179 next=self.get_argument('next', default='/'),
196 next=self.get_argument('next', default='/'),
180 read_only=self.read_only,
197 read_only=self.read_only,
198 logged_in=self.logged_in,
199 login_available=self.login_available,
181 message=message
200 message=message
182 )
201 )
183
202
@@ -203,7 +222,17 b' class LogoutHandler(AuthenticatedHandler):'
203
222
204 def get(self):
223 def get(self):
205 self.clear_cookie('username')
224 self.clear_cookie('username')
206 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)
207
236
208
237
209 class NewHandler(AuthenticatedHandler):
238 class NewHandler(AuthenticatedHandler):
@@ -219,6 +248,8 b' class NewHandler(AuthenticatedHandler):'
219 base_project_url=u'/', base_kernel_url=u'/',
248 base_project_url=u'/', base_kernel_url=u'/',
220 kill_kernel=False,
249 kill_kernel=False,
221 read_only=False,
250 read_only=False,
251 logged_in=self.logged_in,
252 login_available=self.login_available,
222 mathjax_url=self.application.ipython_app.mathjax_url,
253 mathjax_url=self.application.ipython_app.mathjax_url,
223 )
254 )
224
255
@@ -238,6 +269,8 b' class NamedNotebookHandler(AuthenticatedHandler):'
238 base_project_url=u'/', base_kernel_url=u'/',
269 base_project_url=u'/', base_kernel_url=u'/',
239 kill_kernel=False,
270 kill_kernel=False,
240 read_only=self.read_only,
271 read_only=self.read_only,
272 logged_in=self.logged_in,
273 login_available=self.login_available,
241 mathjax_url=self.application.ipython_app.mathjax_url,
274 mathjax_url=self.application.ipython_app.mathjax_url,
242 )
275 )
243
276
@@ -22,12 +22,16 b' var IPython = (function (IPython) {'
22
22
23 LoginWidget.prototype.style = function () {
23 LoginWidget.prototype.style = function () {
24 this.element.find('button#logout').button();
24 this.element.find('button#logout').button();
25 this.element.find('button#login').button();
25 };
26 };
26 LoginWidget.prototype.bind_events = function () {
27 LoginWidget.prototype.bind_events = function () {
27 var that = this;
28 var that = this;
28 this.element.find("button#logout").click(function () {
29 this.element.find("button#logout").click(function () {
29 window.location = "/logout";
30 window.location = "/logout";
30 });
31 });
32 this.element.find("button#login").click(function () {
33 window.location = "/login";
34 });
31 };
35 };
32
36
33 // Set module variables
37 // Set module variables
@@ -28,18 +28,9 b' $(document).ready(function () {'
28 $('div#right_panel').addClass('box-flex');
28 $('div#right_panel').addClass('box-flex');
29
29
30 IPython.read_only = $('meta[name=read_only]').attr("content") == 'True';
30 IPython.read_only = $('meta[name=read_only]').attr("content") == 'True';
31
32 IPython.notebook_list = new IPython.NotebookList('div#notebook_list');
31 IPython.notebook_list = new IPython.NotebookList('div#notebook_list');
33 IPython.login_widget = new IPython.LoginWidget('span#login_widget');
32 IPython.login_widget = new IPython.LoginWidget('span#login_widget');
34
33
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 }
43 IPython.notebook_list.load_list();
34 IPython.notebook_list.load_list();
44
35
45 // These have display: none in the css file and are made visible here to prevent FLOUC.
36 // These have display: none in the css file and are made visible here to prevent FLOUC.
@@ -22,11 +22,19 b''
22
22
23 <div id="header">
23 <div id="header">
24 <span id="ipython_notebook"><h1><img src='static/ipynblogo.png' alt='IPython Notebook'/></h1></span>
24 <span id="ipython_notebook"><h1><img src='static/ipynblogo.png' alt='IPython Notebook'/></h1></span>
25 <span id="login_widget">
25
26 {% if current_user and current_user != 'anonymous' %}
26 {% block login_widget %}
27 <button id="logout">Logout</button>
27
28 {% end %}
28 <span id="login_widget">
29 </span>
29 {% if logged_in %}
30 <button id="logout">Logout</button>
31 {% elif login_available and not logged_in %}
32 <button id="login">Login</button>
33 {% end %}
34 </span>
35
36 {% end %}
37
30 {% block header %}
38 {% block header %}
31 {% end %}
39 {% end %}
32 </div>
40 </div>
@@ -1,8 +1,26 b''
1 {% extends layout.html %}
1 {% extends layout.html %}
2
2
3 {% block content_panel %}
3 {% block content_panel %}
4
5 {% if login_available %}
6
4 <form action="/login?next={{url_escape(next)}}" method="post">
7 <form action="/login?next={{url_escape(next)}}" method="post">
5 Password: <input type="password" name="password">
8 Password: <input type="password" name="password" id="focus">
6 <input type="submit" value="Sign in" id="signin">
9 <input type="submit" value="Sign in" id="signin">
7 </form>
10 </form>
11
12 {% end %}
13
14 {% end %}
15
16 {% block login_widget %}
17 {% end %}
18
19 {% block script %}
20 <script type="text/javascript">
21 $(document).ready(function() {
22 IPython.login_widget = new IPython.LoginWidget('span#login_widget');
23 $('#focus').focus();
24 });
25 </script>
8 {% end %}
26 {% end %}
@@ -1,5 +1,28 b''
1 {% extends layout.html %}
1 {% extends layout.html %}
2
2
3 {% block content_panel %}
3 {% block content_panel %}
4 Proceed to the <a href="/login">login page</a>.
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
17 {% end %}
18
19 {% block login_widget %}
20 {% end %}
21
22 {% block script %}
23 <script type="text/javascript">
24 $(document).ready(function() {
25 IPython.login_widget = new IPython.LoginWidget('span#login_widget');
26 });
27 </script>
5 {% end %}
28 {% end %}
@@ -29,8 +29,10 b''
29 <link rel="stylesheet" href="static/css/base.css" type="text/css" />
29 <link rel="stylesheet" href="static/css/base.css" type="text/css" />
30 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
30 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
31 <link rel="stylesheet" href="static/css/renderedhtml.css" type="text/css" />
31 <link rel="stylesheet" href="static/css/renderedhtml.css" type="text/css" />
32
32
33 <meta name="read_only" content="{{read_only}}"/>
33 {% comment In the notebook, the read-only flag is used to determine %}
34 {% comment whether to hide the side panels and switch off input %}
35 <meta name="read_only" content="{{read_only and not logged_in}}"/>
34
36
35 </head>
37 </head>
36
38
@@ -52,8 +54,10 b''
52 <span id="login_widget">
54 <span id="login_widget">
53 {% comment This is a temporary workaround to hide the logout button %}
55 {% comment This is a temporary workaround to hide the logout button %}
54 {% comment when appropriate until notebook.html is templated %}
56 {% comment when appropriate until notebook.html is templated %}
55 {% if current_user and current_user != 'anonymous' %}
57 {% if logged_in %}
56 <button id="logout">Logout</button>
58 <button id="logout">Logout</button>
59 {% elif not logged_in and login_available %}
60 <button id="login">Login</button>
57 {% end %}
61 {% end %}
58 </span>
62 </span>
59
63
@@ -19,12 +19,19 b' data-base-kernel-url={{base_kernel_url}}'
19 {% end %}
19 {% end %}
20
20
21 {% block content_panel %}
21 {% block content_panel %}
22 {% if logged_in or not read_only %}
23
22 <div id="content_toolbar">
24 <div id="content_toolbar">
23 <span id="drag_info" class="hidden">Drag files onto the list to import notebooks.</span>
25 <span id="drag_info">Drag files onto the list to import
26 notebooks.</span>
27
24 <span id="notebooks_buttons">
28 <span id="notebooks_buttons">
25 <button id="new_notebook" class="hidden">New Notebook</button>
29 <button id="new_notebook">New Notebook</button>
26 </span>
30 </span>
27 </div>
31 </div>
32
33 {% end %}
34
28 <div id="notebook_list">
35 <div id="notebook_list">
29 <div id="project_name"><h2>{{project}}</h2></div>
36 <div id="project_name"><h2>{{project}}</h2></div>
30 </div>
37 </div>
General Comments 0
You need to be logged in to leave comments. Login now