From fdb3608ddb8193c289c1dbd8b929144890c2e17f Mon Sep 17 00:00:00 2001 From: Leticia Portella Date: Tue, 25 Sep 2018 01:12:43 -0300 Subject: [PATCH] initial implementation on reset password url --- .../firstuseauthenticator.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/firstuseauthenticator/firstuseauthenticator.py b/firstuseauthenticator/firstuseauthenticator.py index 7325c06..dc44382 100644 --- a/firstuseauthenticator/firstuseauthenticator.py +++ b/firstuseauthenticator/firstuseauthenticator.py @@ -7,14 +7,25 @@ locally in a dbm file, and checked next time they log in. """ import dbm from jupyterhub.auth import Authenticator +from jupyterhub.handlers import BaseHandler from jupyterhub.orm import User -from tornado import gen +from tornado import gen, web from traitlets.traitlets import Unicode, Bool import bcrypt +class ResetPasswordHandler(BaseHandler): + """Render the reset password page.""" + + @web.authenticated + async def get(self): + + html = self.render_template('reset.html') + self.finish(html) + + class FirstUseAuthenticator(Authenticator): """ JupyterHub authenticator that lets users set password on first use. @@ -74,3 +85,12 @@ class FirstUseAuthenticator(Authenticator): """ with dbm.open(self.dbm_path, 'c', 0o600) as db: del db[user.name] + + def reset_password(self, data): + username = data['username'] + new_password = data['password'] + db[username] = bcrypt.hashpw(new_password.encode(), bcrypt.gensalt()) + return username + + def get_handlers(self, app): + return super().get_handlers(app) + [(r'/auth/change-password', ResetPasswordHandler)]