notebook auth adjustments

* keyword -> password
* removed password alias
* add login.html as template
* new cookie key for each Server instance
This commit is contained in:
MinRK 2011-08-30 11:24:52 -07:00
parent 00986be4f8
commit dbfe19f6e2
3 changed files with 75 additions and 14 deletions

View File

@ -38,8 +38,11 @@ except ImportError:
class BaseHandler(web.RequestHandler):
def get_current_user(self):
user_id = self.get_secure_cookie("user")
keyword = self.get_secure_cookie("keyword")
if self.application.keyword and self.application.keyword != keyword:
if user_id is None:
self.clear_cookie('user')
self.clear_cookie('password')
password = self.get_secure_cookie("password")
if self.application.password and self.application.password != password:
return None
if not user_id:
user_id = 'anonymous'
@ -55,15 +58,16 @@ class NBBrowserHandler(BaseHandler):
class LoginHandler(BaseHandler):
def get(self):
user_id = self.get_secure_cookie("user")
self.write('<html><body><form action="/login" method="post">'
'Name: <input type="text" name="name" value=%s>'
'Keyword: <input type="password" name="keyword">'
'<input type="submit" value="Sign in">'
'</form></body></html>'%user_id)
if user_id is None:
self.clear_cookie('user')
self.clear_cookie('password')
user_id = ''
self.render('login.html', user_id=user_id)
def post(self):
self.set_secure_cookie("user", self.get_argument("name", default=u''))
self.set_secure_cookie("keyword", self.get_argument("keyword", default=u''))
self.set_secure_cookie("password", self.get_argument("password", default=u''))
self.redirect("/")
class NewHandler(web.RequestHandler):

View File

@ -95,7 +95,7 @@ class NotebookWebApplication(web.Application):
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
cookie_secret="61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
cookie_secret=os.urandom(1024),
login_url="/login",
)
web.Application.__init__(self, handlers, **settings)
@ -126,11 +126,10 @@ aliases.update({
'certfile': 'IPythonNotebookApp.certfile',
'ws-hostname': 'IPythonNotebookApp.ws_hostname',
'notebook-dir': 'NotebookManager.notebook_dir',
'keyword' : 'IPythonNotebookApp.keyword'
})
notebook_aliases = [u'port', u'ip', u'keyfile', u'certfile', u'ws-hostname',
u'notebook-dir', u'keyword']
u'notebook-dir']
#-----------------------------------------------------------------------------
# IPythonNotebookApp
@ -189,8 +188,8 @@ class IPythonNotebookApp(BaseIPythonApplication):
help="""The full path to a private key file for usage with SSL/TLS."""
)
keyword = Unicode(u'', config=True,
help="""Keyword to use for web authentication"""
password = Unicode(u'', config=True,
help="""Password to use for web authentication"""
)
def get_ws_url(self):
@ -249,7 +248,7 @@ class IPythonNotebookApp(BaseIPythonApplication):
ssl_options['keyfile'] = self.keyfile
else:
ssl_options = None
self.web_app.keyword = self.keyword
self.web_app.password = self.password
self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options)
if ssl_options is None and not self.ip:
self.log.critical('WARNING: the notebook server is listening on all IP addresses '

View File

@ -0,0 +1,58 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>IPython Notebook</title>
<link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
<!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
<!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.14.custom.css" type="text/css" />-->
<link rel="stylesheet" href="static/css/boilerplate.css" type="text/css" />
<link rel="stylesheet" href="static/css/layout.css" type="text/css" />
<link rel="stylesheet" href="static/css/base.css" type="text/css" />
</head>
<body>
<div id="header">
<span id="ipython_notebook"><h1>IPython Notebook</h1></span>
</div>
<div id="header_border"></div>
<div id="main_app">
<div id="app_hbox">
<div id="left_panel">
</div>
<div id="content_panel">
<form action="/login" method="post">
Name: <input type="text" name="name" value="{{user_id}}">
Password: <input type="password" name="password">
<input type="submit" value="Sign in">
</form>
</div>
<div id="right_panel">
</div>
</div>
</div>
<script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/notebooklist.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/nbbrowser_main.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>