From 1af7f7d550d93b447a91f30cdb4b4881ac2fac86 Mon Sep 17 00:00:00 2001 From: Arksine Date: Thu, 13 May 2021 14:54:18 -0400 Subject: [PATCH] authorization: send websocket notifications when a user is created or deleted Signed-off-by: Eric Callahan --- moonraker/components/authorization.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/moonraker/components/authorization.py b/moonraker/components/authorization.py index d6ccbcd..fba7663 100644 --- a/moonraker/components/authorization.py +++ b/moonraker/components/authorization.py @@ -147,6 +147,8 @@ class Authorization: self.server.register_endpoint( "/access/oneshot_token", ['GET'], self._handle_token_request, protocol=['http']) + self.server.register_notification("authorization:user_created") + self.server.register_notification("authorization:user_deleted") async def _handle_apikey_request(self, web_request): action = web_request.get_action() @@ -281,6 +283,11 @@ class Authorization: refresh_token = self._generate_jwt( username, jwt_secret, token_type="refresh", exp_time=datetime.timedelta(days=self.login_timeout)) + if create: + IOLoop.current().call_later( + .005, self.server.send_event, + "authorization:user_created", + {'username': username}) return { 'username': username, 'token': token, @@ -303,6 +310,10 @@ class Authorization: if hashed_pass != user_info['password']: raise self.server.error("Invalid Password") del self.users[username] + IOLoop.current().call_later( + .005, self.server.send_event, + "authorization:user_deleted", + {'username': username}) return { "username": username, "action": "user_deleted"