diff --git a/nativeauthenticator/handlers.py b/nativeauthenticator/handlers.py index ecbf24a..89e2b8a 100644 --- a/nativeauthenticator/handlers.py +++ b/nativeauthenticator/handlers.py @@ -150,6 +150,26 @@ async def post(self): self.finish(html) +class ChangePasswordAdminHandler(LocalBase): + """Render the reset password page.""" + + @admin_only + async def get(self): + self._register_template_path() + html = self.render_template('change-password.html') + self.finish(html) + + @admin_only + async def post(self, user_name): + new_password = self.get_body_argument('password', strip=False) + self.authenticator.change_password(user_name, new_password) + + html = self.render_template( + 'change-password.html', + result_message='Your password has been changed successfully', + ) + self.finish(html) + class LoginHandler(LoginHandler, LocalBase): def _render(self, login_error=None, username=None): diff --git a/nativeauthenticator/nativeauthenticator.py b/nativeauthenticator/nativeauthenticator.py index b744f9f..f1bd923 100644 --- a/nativeauthenticator/nativeauthenticator.py +++ b/nativeauthenticator/nativeauthenticator.py @@ -9,8 +9,10 @@ from tornado import gen from traitlets import Bool, Integer, Unicode -from .handlers import (AuthorizationHandler, ChangeAuthorizationHandler, - ChangePasswordHandler, LoginHandler, SignUpHandler) +from .handlers import ( + AuthorizationHandler, ChangeAuthorizationHandler, ChangePasswordHandler, + ChangePasswordAdminHandler, LoginHandler, SignUpHandler, +) from .orm import UserInfo @@ -224,6 +226,7 @@ def get_handlers(self, app): (r'/authorize', AuthorizationHandler), (r'/authorize/([^/]*)', ChangeAuthorizationHandler), (r'/change-password', ChangePasswordHandler), + (r'/change-password/([^/]+)', ChangePasswordAdminHandler), ] return native_handlers