This commit is contained in:
yumoqing 2024-11-06 15:55:43 +08:00
parent ca0455f9fc
commit feeab18bc5

View File

@ -28,7 +28,10 @@ def get_client_ip(obj, request):
return ip return ip
async def get_session_userinfo(request): async def get_session_userinfo(request):
info = await auth.get_auth(request).split(':') d = await auth.get_auth(request)
if d is None:
return DictObject()
info = d.split(':')
return DictObject(**{ return DictObject(**{
'userid':info[0], 'userid':info[0],
'username':info[1], 'username':info[1],
@ -36,12 +39,12 @@ async def get_session_userinfo(request):
}) })
async def get_session_user(request): async def get_session_user(request):
userid = await get_session_userinfo(request).userid userinfo = await get_session_userinfo(request)
return userid return userinfo.userid
async def user_login(request, userid, username='', userorgid=''): async def user_login(request, userid, username='', userorgid=''):
info = f'{userid}:{username}:{userorgid}' info = f'{userid}:{username}:{userorgid}'
await auth.remember(request, userinfo) await auth.remember(request, info)
async def user_logout(request): async def user_logout(request):
await auth.forget(request) await auth.forget(request)