Permalink
Browse files

notebook auth adjustments

* keyword -> password
* removed password alias
* add login.html as template
* new cookie key for each Server instance
  • Loading branch information...
1 parent 98bca96 commit f97967f9097b171bf270a90a2c94222543e95b8d @minrk minrk committed Aug 30, 2011
@@ -38,8 +38,11 @@
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 @@ def get(self):
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):
@@ -95,7 +95,7 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager, log):
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 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager, log):
'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 @@ def _ip_changed(self, name, old, new):
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 @@ def initialize(self, argv=None):
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 '
@@ -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>
+
+

0 comments on commit f97967f

Please sign in to comment.