Show More
@@ -35,13 +35,36 b' except ImportError:' | |||
|
35 | 35 | # Top-level handlers |
|
36 | 36 | #----------------------------------------------------------------------------- |
|
37 | 37 | |
|
38 | ||
|
39 | class NBBrowserHandler(web.RequestHandler): | |
|
38 | class BaseHandler(web.RequestHandler): | |
|
39 | def get_current_user(self): | |
|
40 | user_id = self.get_secure_cookie("user") | |
|
41 | keyword = self.get_secure_cookie("keyword") | |
|
42 | if self.application.keyword and self.application.keyword != keyword: | |
|
43 | return None | |
|
44 | if not user_id: | |
|
45 | user_id = 'anonymous' | |
|
46 | return user_id | |
|
47 | ||
|
48 | class NBBrowserHandler(BaseHandler): | |
|
49 | @web.authenticated | |
|
40 | 50 | def get(self): |
|
41 | 51 | nbm = self.application.notebook_manager |
|
42 | 52 | project = nbm.notebook_dir |
|
43 | 53 | self.render('nbbrowser.html', project=project) |
|
44 | 54 | |
|
55 | class LoginHandler(BaseHandler): | |
|
56 | def get(self): | |
|
57 | user_id = self.get_secure_cookie("user") | |
|
58 | self.write('<html><body><form action="/login" method="post">' | |
|
59 | 'Name: <input type="text" name="name" value=%s>' | |
|
60 | 'Keyword: <input type="text" name="keyword">' | |
|
61 | '<input type="submit" value="Sign in">' | |
|
62 | '</form></body></html>'%user_id) | |
|
63 | ||
|
64 | def post(self): | |
|
65 | self.set_secure_cookie("user", self.get_argument("name", default=u'')) | |
|
66 | self.set_secure_cookie("keyword", self.get_argument("keyword", default=u'')) | |
|
67 | self.redirect("/") | |
|
45 | 68 | |
|
46 | 69 | class NewHandler(web.RequestHandler): |
|
47 | 70 | def get(self): |
@@ -35,7 +35,7 b' from tornado import httpserver' | |||
|
35 | 35 | from tornado import web |
|
36 | 36 | |
|
37 | 37 | from .kernelmanager import MappingKernelManager |
|
38 | from .handlers import ( | |
|
38 | from .handlers import (LoginHandler, | |
|
39 | 39 | NBBrowserHandler, NewHandler, NamedNotebookHandler, |
|
40 | 40 | MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, |
|
41 | 41 | ShellHandler, NotebookRootHandler, NotebookHandler, RSTHandler |
@@ -80,6 +80,7 b' class NotebookWebApplication(web.Application):' | |||
|
80 | 80 | def __init__(self, ipython_app, kernel_manager, notebook_manager, log): |
|
81 | 81 | handlers = [ |
|
82 | 82 | (r"/", NBBrowserHandler), |
|
83 | (r"/login", LoginHandler), | |
|
83 | 84 | (r"/new", NewHandler), |
|
84 | 85 | (r"/%s" % _notebook_id_regex, NamedNotebookHandler), |
|
85 | 86 | (r"/kernels", MainKernelHandler), |
@@ -94,6 +95,8 b' class NotebookWebApplication(web.Application):' | |||
|
94 | 95 | settings = dict( |
|
95 | 96 | template_path=os.path.join(os.path.dirname(__file__), "templates"), |
|
96 | 97 | static_path=os.path.join(os.path.dirname(__file__), "static"), |
|
98 | cookie_secret="61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=", | |
|
99 | login_url="/login", | |
|
97 | 100 | ) |
|
98 | 101 | web.Application.__init__(self, handlers, **settings) |
|
99 | 102 | |
@@ -122,7 +125,8 b' aliases.update({' | |||
|
122 | 125 | 'keyfile': 'IPythonNotebookApp.keyfile', |
|
123 | 126 | 'certfile': 'IPythonNotebookApp.certfile', |
|
124 | 127 | 'ws-hostname': 'IPythonNotebookApp.ws_hostname', |
|
125 | 'notebook-dir': 'NotebookManager.notebook_dir' | |
|
128 | 'notebook-dir': 'NotebookManager.notebook_dir', | |
|
129 | 'keyword' : 'IPythonNotebookApp.keyword' | |
|
126 | 130 | }) |
|
127 | 131 | |
|
128 | 132 | notebook_aliases = [u'port', u'ip', u'keyfile', u'certfile', u'ws-hostname', |
@@ -185,6 +189,10 b' class IPythonNotebookApp(BaseIPythonApplication):' | |||
|
185 | 189 | help="""The full path to a private key file for usage with SSL/TLS.""" |
|
186 | 190 | ) |
|
187 | 191 | |
|
192 | keyword = Unicode(u'', config=True, | |
|
193 | help="""Keyword to use for web authentication""" | |
|
194 | ) | |
|
195 | ||
|
188 | 196 | def get_ws_url(self): |
|
189 | 197 | """Return the WebSocket URL for this server.""" |
|
190 | 198 | if self.certfile: |
@@ -241,6 +249,7 b' class IPythonNotebookApp(BaseIPythonApplication):' | |||
|
241 | 249 | ssl_options['keyfile'] = self.keyfile |
|
242 | 250 | else: |
|
243 | 251 | ssl_options = None |
|
252 | self.web_app.keyword = self.keyword | |
|
244 | 253 | self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options) |
|
245 | 254 | if ssl_options is None and not self.ip: |
|
246 | 255 | self.log.critical('WARNING: the notebook server is listening on all IP addresses ' |
General Comments 0
You need to be logged in to leave comments.
Login now