From e542cd9dc78563120d82428e6d0dd27ad5284621 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 4 Apr 2023 10:34:02 +0800 Subject: [PATCH] bugfix --- ahserver/auth_api.py | 5 ++--- ahserver/error.py | 13 +++++++++++++ ahserver/globalEnv.py | 8 ++++++++ ahserver/processorResource.py | 9 +++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index 6b9c525..102e4a7 100644 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -87,9 +87,8 @@ class AuthAPI(AppLogger): # print('-----------auth.get_auth() return None--------------') user = await self.checkLogin(request) #raise web.HTTPFound(f'/login_form?from_path={path}') - user_perms = await self.getUserPermissions(user) - need_perm = await self.getPermissionNeed(path) - if need_perm in user_perms: + is_ok = await self.checkUserPermission(user, path) + if is_ok: return await handler(request) # print(f'**{path} forbidden**') raise web.HTTPForbidden() diff --git a/ahserver/error.py b/ahserver/error.py index df0768c..882b201 100644 --- a/ahserver/error.py +++ b/ahserver/error.py @@ -12,3 +12,16 @@ def Success(data): "status":"OK", "data":data } + +def NeedLogin(path): + return { + "status":"need_login", + "data":path + } + +def NoPermission(path): + return { + "status":"no_permission", + "data":path + } + diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 33d30c2..c03fb10 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -19,6 +19,7 @@ from appPublic.folderUtils import folderInfo from appPublic.uniqueID import setNode,getID from appPublic.unicoding import unicoding,uDict,uObject from appPublic.Singleton import SingletonDecorator +from appPublic.rc4 import password from sqlor.dbpools import DBPools,runSQL,runSQLPaging from sqlor.crud import CRUD @@ -26,6 +27,7 @@ from sqlor.crud import CRUD from .xlsxData import XLSXData from .uriop import URIOp +from .error import Success, Error, NeedLogin, NoPermission from .serverenv import ServerEnv @@ -160,3 +162,9 @@ def initEnv(): g.openfile = openfile g.CRUD = CRUD g.DBPools = DBPools + g.Error = Error + g.Success = Success + g.NeedLogin = NeedLogin + g.NoPermission = NoPermission + g.password = password + diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index bedf074..7fcff4b 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -8,6 +8,7 @@ import asyncio from yarl import URL +from aiohttp_auth import auth from appPublic.http_client import Http_Client from functools import partial from aiohttp_auth import auth @@ -199,7 +200,15 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): ns = multiDict2Dict(request.query) return ns + async def remember_user(userid): + await auth.remember(request, userid) + + async def get_user(): + return await auth.get_auth(request) + self.y_env.i18n = serveri18n + self.y_env.remember_user = remember_user + self.y_env.get_user = get_user self.y_env.i18nDict = i18nDICT self.y_env.terminalType = getClientType(request) self.y_env.entire_url = partial(self.entireUrl,request)