def login_page(self): session = self.get_session() content = b'' if session.authenticated: return server.HttpRedirect(self.server.settings.prefix + '/') if 'pw' in self.db: valid_pw = (self.server.settings.password_hash is not None and checkpw(self.db['pw'], self.server.settings.password_hash)) valid_token = self.server.verify_token(self.db['pw']) if valid_pw or valid_token: RequireAuthentication.authenticate(self) return server.HttpRedirect(self.server.settings.prefix + '/') else: content += b'<p><strong>Invalid password. Try again.' content += b'</strong></p>' else: content += b'<p>Please enter the password or the security token ' content += b'shown by Nengo when it was started:</p>' return server.HtmlResponse(content + b''' <form method="POST"><p> <label for="pw">Password: </label> <input type="password" name="pw" /> <input type="submit" value="Log in" /> </p></form> ''')
def browse(self): r = [b'<ul class="jqueryFileTree" style="display: none;">'] d = unquote(self.db['dir']) ex_tag = '//examples//' ex_html = b'<em>built-in examples</em>' if d == '.': r.append(b'<li class="directory collapsed examples_dir">' b'<a href="#" rel="' + ex_tag.encode('utf-8') + b'">' + ex_html + b'</a></li>') path = '.' elif d.startswith(ex_tag): path = os.path.join(nengo_gui.__path__[0], 'examples', d[len(ex_tag):]) else: path = os.path.join('.', d) for f in sorted(os.listdir(path)): ff = os.path.join(path, f).encode('utf-8') if os.path.isdir(os.path.join(path, f)): f = f.encode('utf-8') r.append(b'<li class="directory collapsed">' b'<a href="#" rel="' + ff + b'/">' + f + b'</a></li>') else: e = os.path.splitext(f)[1][1:] # get .ext and remove dot if e == 'py': e = e.encode('utf-8') f = f.encode('utf-8') r.append(b'<li class="file ext_' + e + b'">' b'<a href="#" rel="' + ff + b'">' + f + b'</a></li>') r.append(b'</ul>') return server.HtmlResponse(b''.join(r))
def login_page(self): session = self.get_session() content = b'' if 'pw' in self.db: if checkpw(self.db['pw'], self.server.settings.password_hash): session.authenticated = True session.login_host = self.headers.get('host', None) else: content += b'<p><strong>Invalid password. Try again.' content += b'</strong></p>' else: content += b'<p>Please enter the password:</p>' if session.authenticated: return server.HttpRedirect('/') return server.HtmlResponse(content + b''' <form method="POST"><p> <label for="pw">Password: </label> <input type="password" name="pw" /> <input type="submit" value="Log in" /> </p></form> ''')