Skip to content

Commit

Permalink
Allow admin to change any password
Browse files Browse the repository at this point in the history
  • Loading branch information
ogiorgis authored and djangoliv committed Jun 2, 2020
1 parent 5d34628 commit 385dcf1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions nativeauthenticator/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions nativeauthenticator/nativeauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 385dcf1

Please sign in to comment.