##// END OF EJS Templates
Notebook: Store the username in a cookie whose name is unique....
Bradley M. Froehle -
Show More
@@ -146,13 +146,13 b' class AuthenticatedHandler(RequestHandler):'
146 """A RequestHandler with an authenticated user."""
146 """A RequestHandler with an authenticated user."""
147
147
148 def get_current_user(self):
148 def get_current_user(self):
149 user_id = self.get_secure_cookie("username")
149 user_id = self.get_secure_cookie(self.settings['cookie_name'])
150 # For now the user_id should not return empty, but it could eventually
150 # For now the user_id should not return empty, but it could eventually
151 if user_id == '':
151 if user_id == '':
152 user_id = 'anonymous'
152 user_id = 'anonymous'
153 if user_id is None:
153 if user_id is None:
154 # prevent extra Invalid cookie sig warnings:
154 # prevent extra Invalid cookie sig warnings:
155 self.clear_cookie('username')
155 self.clear_cookie(self.settings['cookie_name'])
156 if not self.application.password and not self.application.read_only:
156 if not self.application.password and not self.application.read_only:
157 user_id = 'anonymous'
157 user_id = 'anonymous'
158 return user_id
158 return user_id
@@ -242,7 +242,7 b' class LoginHandler(AuthenticatedHandler):'
242 pwd = self.get_argument('password', default=u'')
242 pwd = self.get_argument('password', default=u'')
243 if self.application.password:
243 if self.application.password:
244 if passwd_check(self.application.password, pwd):
244 if passwd_check(self.application.password, pwd):
245 self.set_secure_cookie('username', str(uuid.uuid4()))
245 self.set_secure_cookie(self.settings['cookie_name'], str(uuid.uuid4()))
246 else:
246 else:
247 self._render(message={'error': 'Invalid password'})
247 self._render(message={'error': 'Invalid password'})
248 return
248 return
@@ -253,7 +253,7 b' class LoginHandler(AuthenticatedHandler):'
253 class LogoutHandler(AuthenticatedHandler):
253 class LogoutHandler(AuthenticatedHandler):
254
254
255 def get(self):
255 def get(self):
256 self.clear_cookie('username')
256 self.clear_cookie(self.settings['cookie_name'])
257 if self.login_available:
257 if self.login_available:
258 message = {'info': 'Successfully logged out.'}
258 message = {'info': 'Successfully logged out.'}
259 else:
259 else:
@@ -427,7 +427,7 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler):'
427 self.on_message = self.on_first_message
427 self.on_message = self.on_first_message
428
428
429 def get_current_user(self):
429 def get_current_user(self):
430 user_id = self.get_secure_cookie("username")
430 user_id = self.get_secure_cookie(self.settings['cookie_name'])
431 if user_id == '' or (user_id is None and not self.application.password):
431 if user_id == '' or (user_id is None and not self.application.password):
432 user_id = 'anonymous'
432 user_id = 'anonymous'
433 return user_id
433 return user_id
@@ -28,6 +28,7 b' import socket'
28 import sys
28 import sys
29 import threading
29 import threading
30 import time
30 import time
31 import uuid
31 import webbrowser
32 import webbrowser
32
33
33 # Third party
34 # Third party
@@ -164,6 +165,7 b' class NotebookWebApplication(web.Application):'
164 static_handler_class = FileFindHandler,
165 static_handler_class = FileFindHandler,
165 cookie_secret=os.urandom(1024),
166 cookie_secret=os.urandom(1024),
166 login_url="%s/login"%(base_project_url.rstrip('/')),
167 login_url="%s/login"%(base_project_url.rstrip('/')),
168 cookie_name='username-%s' % uuid.uuid4(),
167 )
169 )
168
170
169 # allow custom overrides for the tornado web app.
171 # allow custom overrides for the tornado web app.
General Comments 0
You need to be logged in to leave comments. Login now