add template locally

This commit is contained in:
Leticia Portella 2018-09-25 19:19:04 -03:00
parent fdb3608ddb
commit 5da66ecd32
4 changed files with 80 additions and 2 deletions

View File

@ -6,6 +6,8 @@ password for that account. It is hashed with bcrypt & stored
locally in a dbm file, and checked next time they log in.
"""
import dbm
import os
from jinja2 import ChoiceLoader, FileSystemLoader
from jupyterhub.auth import Authenticator
from jupyterhub.handlers import BaseHandler
from jupyterhub.orm import User
@ -16,12 +18,31 @@ from traitlets.traitlets import Unicode, Bool
import bcrypt
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'templates')
class ResetPasswordHandler(BaseHandler):
"""Render the reset password page."""
def __init__(self, *args, **kwargs):
self._loaded = False
super().__init__(*args, **kwargs)
def _register_template_path(self):
if self._loaded:
return
self.log.debug('Adding %s to template path', TEMPLATE_DIR)
loader = FileSystemLoader([TEMPLATE_DIR])
env = self.settings['jinja2_env']
previous_loader = env.loader
env.loader = ChoiceLoader([previous_loader, loader])
self._loaded = True
@web.authenticated
async def get(self):
self._register_template_path()
html = self.render_template('reset.html')
self.finish(html)

View File

@ -0,0 +1,54 @@
{% extends "page.html" %}
{% block main %}
<div class="container">
<form action="{{login_url}}?next={{next}}" method="post" role="form">
<div class="auth-form-header">
Sign in
</div>
<div class='auth-form-body'>
<p id='insecure-login-warning' class='hidden'>
Warning: JupyterHub seems to be served over an unsecured HTTP connection.
We strongly recommend enabling HTTPS for JupyterHub.
</p>
{% if login_error %}
<p class="login_error">
{{login_error}}
</p>
{% endif %}
<label for="username_input">Username:</label>
<input
id="username_input"
type="text"
autocapitalize="off"
autocorrect="off"
class="form-control"
name="username"
val="{{username}}"
tabindex="1"
autofocus="autofocus"
/>
<label for='password_input'>Password:</label>
<input
type="password"
class="form-control"
name="password"
id="password_input"
tabindex="2"
/>
<input
type="submit"
id="login_submit"
class='btn btn-jupyter'
value='Sign In'
tabindex="3"
/>
</div>
</form>
</div>
{% endblock %}

View File

@ -9,5 +9,8 @@ setup(
author_email='yuvipanda@gmail.com',
license='3 Clause BSD',
packages=find_packages(),
install_requires=['bcrypt']
install_requires=['bcrypt'],
package_data={
'': ['*.html'],
}
)