user module has same rest api methods like before

This commit is contained in:
iLLiCiTiT 2021-03-12 11:42:14 +01:00
parent aea8d1c2ff
commit d6567358de
2 changed files with 46 additions and 1 deletions

View file

@ -0,0 +1,36 @@
import json
from aiohttp.web_request import Request
from aiohttp.web_response import Response
class UserModuleRestApi:
def __init__(self, user_module, server_manager):
self.module = user_module
self.server_manager = server_manager
self.prefix = "/user"
self.register()
def register(self):
self.server_manager.add_route(
"GET",
self.prefix + "/username",
self.get_username
)
self.server_manager.add_route(
"GET",
self.prefix + "/show_widget",
self.show_user_widget
)
async def get_username(self, request):
return Response(
status=200,
body=json.dumps(self.module.cred, indent=4),
content_type="application/json"
)
async def show_user_widget(self, request):
self.module.action_show_widget.trigger()
return Response(status=200)

View file

@ -9,7 +9,8 @@ import appdirs
from .. import (
PypeModule,
ITrayModule
ITrayModule,
IWebServerRoutes
)
@ -46,6 +47,8 @@ class UserModule(PypeModule, ITrayModule):
self.widget_login = None
self.action_show_widget = None
self.rest_api_obj = None
def tray_init(self):
from .widget_user import UserWidget
self.widget_login = UserWidget(self)
@ -71,6 +74,12 @@ class UserModule(PypeModule, ITrayModule):
def get_user(self):
return self.cred.get("username") or getpass.getuser()
def webserver_initialization(self, server_manager):
"""Implementation of IWebServerRoutes interface."""
from .rest_api import UserModuleRestApi
self.rest_api_obj = UserModuleRestApi(self, server_manager)
def connect_with_modules(self, enabled_modules):
for module in enabled_modules:
if isinstance(module, IUserModule):