Compare commits

...

2 Commits

Author SHA1 Message Date
yumoqing
3ee8d5bbab Merge branch 'master' of git.kaiyuancloud.cn:yumoqing/ahserver 2024-11-05 18:32:21 +08:00
yumoqing
878864af85 bugfix 2024-11-05 18:31:56 +08:00
2 changed files with 29 additions and 4 deletions

View File

@ -16,6 +16,7 @@ from aiohttp_session.cookie_storage import EncryptedCookieStorage
from aiohttp_session.redis_storage import RedisStorage from aiohttp_session.redis_storage import RedisStorage
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
from appPublic.dictObject import DictObject
from appPublic.rsawrap import RSA from appPublic.rsawrap import RSA
from appPublic.log import info, debug, warning, error, critical, exception from appPublic.log import info, debug, warning, error, critical, exception
@ -26,12 +27,21 @@ def get_client_ip(obj, request):
request['client_ip'] = ip request['client_ip'] = ip
return 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): async def get_session_user(request):
userid = await auth.get_auth(request) userid = await get_session_userinfo(request).userid
return userid return userid
async def user_login(request, userid): async def user_login(request, userid, username='', userorgid=''):
await auth.remember(request, userid) info = f'{userid}:{username}:{userorgid}'
await auth.remember(request, userinfo)
async def user_logout(request): async def user_logout(request):
await auth.forget(request) await auth.forget(request)

View File

@ -57,7 +57,7 @@ from .dbadmin import DBAdmin
from .filedownload import file_download, path_decode from .filedownload import file_download, path_decode
from .utils import unicode_escape from .utils import unicode_escape
from .filetest import current_fileno 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): def getHeaderLang(request):
al = request.headers.get('Accept-Language') al = request.headers.get('Accept-Language')
@ -256,6 +256,18 @@ class ProcessorResource(StaticResource,Url2File):
async def forget_user(): async def forget_user():
await user_logout(request) 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(): async def get_user():
return await get_session_user(request) return await get_session_user(request)
@ -273,6 +285,9 @@ class ProcessorResource(StaticResource,Url2File):
self.y_env.remember_user = remember_user self.y_env.remember_user = remember_user
self.y_env.forget_user = forget_user self.y_env.forget_user = forget_user
self.y_env.get_user = get_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.i18nDict = i18nDICT
self.y_env.terminalType = getClientType(request) self.y_env.terminalType = getClientType(request)
self.y_env.entire_url = partial(self.entireUrl,request) self.y_env.entire_url = partial(self.entireUrl,request)