This commit is contained in:
yumoqing 2023-04-04 10:34:02 +08:00
parent 906be8d0be
commit e542cd9dc7
4 changed files with 32 additions and 3 deletions

View File

@ -87,9 +87,8 @@ class AuthAPI(AppLogger):
# print('-----------auth.get_auth() return None--------------') # print('-----------auth.get_auth() return None--------------')
user = await self.checkLogin(request) user = await self.checkLogin(request)
#raise web.HTTPFound(f'/login_form?from_path={path}') #raise web.HTTPFound(f'/login_form?from_path={path}')
user_perms = await self.getUserPermissions(user) is_ok = await self.checkUserPermission(user, path)
need_perm = await self.getPermissionNeed(path) if is_ok:
if need_perm in user_perms:
return await handler(request) return await handler(request)
# print(f'**{path} forbidden**') # print(f'**{path} forbidden**')
raise web.HTTPForbidden() raise web.HTTPForbidden()

View File

@ -12,3 +12,16 @@ def Success(data):
"status":"OK", "status":"OK",
"data":data "data":data
} }
def NeedLogin(path):
return {
"status":"need_login",
"data":path
}
def NoPermission(path):
return {
"status":"no_permission",
"data":path
}

View File

@ -19,6 +19,7 @@ from appPublic.folderUtils import folderInfo
from appPublic.uniqueID import setNode,getID from appPublic.uniqueID import setNode,getID
from appPublic.unicoding import unicoding,uDict,uObject from appPublic.unicoding import unicoding,uDict,uObject
from appPublic.Singleton import SingletonDecorator from appPublic.Singleton import SingletonDecorator
from appPublic.rc4 import password
from sqlor.dbpools import DBPools,runSQL,runSQLPaging from sqlor.dbpools import DBPools,runSQL,runSQLPaging
from sqlor.crud import CRUD from sqlor.crud import CRUD
@ -26,6 +27,7 @@ from sqlor.crud import CRUD
from .xlsxData import XLSXData from .xlsxData import XLSXData
from .uriop import URIOp from .uriop import URIOp
from .error import Success, Error, NeedLogin, NoPermission
from .serverenv import ServerEnv from .serverenv import ServerEnv
@ -160,3 +162,9 @@ def initEnv():
g.openfile = openfile g.openfile = openfile
g.CRUD = CRUD g.CRUD = CRUD
g.DBPools = DBPools g.DBPools = DBPools
g.Error = Error
g.Success = Success
g.NeedLogin = NeedLogin
g.NoPermission = NoPermission
g.password = password

View File

@ -8,6 +8,7 @@ import asyncio
from yarl import URL from yarl import URL
from aiohttp_auth import auth
from appPublic.http_client import Http_Client from appPublic.http_client import Http_Client
from functools import partial from functools import partial
from aiohttp_auth import auth from aiohttp_auth import auth
@ -199,7 +200,15 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
ns = multiDict2Dict(request.query) ns = multiDict2Dict(request.query)
return ns 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.i18n = serveri18n
self.y_env.remember_user = remember_user
self.y_env.get_user = get_user
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)