diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index caf4633..bea0b46 100755 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -16,6 +16,7 @@ from aiohttp_session.cookie_storage import EncryptedCookieStorage from aiohttp_session.redis_storage import RedisStorage from appPublic.jsonConfig import getConfig +from appPublic.dictObject import DictObject from appPublic.rsawrap import RSA from appPublic.log import info, debug, warning, error, critical, exception @@ -26,12 +27,21 @@ def get_client_ip(obj, request): request['client_ip'] = ip return ip +async def get_session_userinfo(request): + info = await auth.get_auth(request).split(':') + return DictObject(**{ + 'userid':info[0], + 'username':info[1], + 'userorgid':info[2] + }) + async def get_session_user(request): - userid = await auth.get_auth(request) + userid = await get_session_userinfo(request).userid return userid -async def user_login(request, userid): - await auth.remember(request, userid) +async def user_login(request, userid, username='', userorgid=''): + info = f'{userid}:{username}:{userorgid}' + await auth.remember(request, userinfo) async def user_logout(request): await auth.forget(request) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 86c0fa7..9f3bb3d 100755 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -57,7 +57,7 @@ from .dbadmin import DBAdmin from .filedownload import file_download, path_decode from .utils import unicode_escape from .filetest import current_fileno -from .auth_api import user_login, user_logout, get_session_user +from .auth_api import user_login, user_logout, get_session_user, get_session_userinfo def getHeaderLang(request): al = request.headers.get('Accept-Language') @@ -256,6 +256,18 @@ class ProcessorResource(StaticResource,Url2File): async def forget_user(): await user_logout(request) + async def get_username(): + info = await get_session_userinfo(request) + return info.username + + async def get_userinfo(): + info = await get_session_userinfo(request) + return info + + async def get_userorgid(): + info = await get_session_userinfo(request) + return info.userorgid + async def get_user(): return await get_session_user(request) @@ -273,6 +285,9 @@ class ProcessorResource(StaticResource,Url2File): self.y_env.remember_user = remember_user self.y_env.forget_user = forget_user self.y_env.get_user = get_user + self.y_env.get_username = get_username + self.y_env.get_userorgid = get_userorgid + self.y_env.get_userinfo = get_userinfo self.y_env.i18nDict = i18nDICT self.y_env.terminalType = getClientType(request) self.y_env.entire_url = partial(self.entireUrl,request)