bugfix
This commit is contained in:
parent
92d0cd5b1c
commit
16742d02a9
@ -61,12 +61,12 @@ class AuthAPI:
|
|||||||
if login_method == 'password':
|
if login_method == 'password':
|
||||||
if await self.checkUserPassword(user_id,password):
|
if await self.checkUserPassword(user_id,password):
|
||||||
await auth.remember(request,user_id)
|
await auth.remember(request,user_id)
|
||||||
print('auth success,',user_id, password)
|
# print('auth success,',user_id, password)
|
||||||
return user_id
|
return user_id
|
||||||
print('auth failed')
|
# print('auth failed')
|
||||||
raise web.HTTPUnauthorized()
|
raise web.HTTPUnauthorized()
|
||||||
else:
|
else:
|
||||||
print('auth method unrecognized------------------------')
|
# print('auth method unrecognized------------------------')
|
||||||
raise web.HTTPUnauthorized()
|
raise web.HTTPUnauthorized()
|
||||||
|
|
||||||
async def logout(self,request):
|
async def logout(self,request):
|
||||||
@ -76,19 +76,19 @@ class AuthAPI:
|
|||||||
@web.middleware
|
@web.middleware
|
||||||
async def checkAuth(self,request,handler):
|
async def checkAuth(self,request,handler):
|
||||||
path = request.path
|
path = request.path
|
||||||
print(f'*****{path} checkAuth called********')
|
# print(f'*****{path} checkAuth called********')
|
||||||
if not await self.needAuth(path):
|
if not await self.needAuth(path):
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
user = await auth.get_auth(request)
|
user = await auth.get_auth(request)
|
||||||
if user is None:
|
if user is None:
|
||||||
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)
|
user_perms = await self.getUserPermissions(user)
|
||||||
need_perm = await self.getPermissionNeed(path)
|
need_perm = await self.getPermissionNeed(path)
|
||||||
if need_perm in user_perms:
|
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()
|
||||||
|
|
||||||
async def needAuth(self,path):
|
async def needAuth(self,path):
|
||||||
|
@ -47,7 +47,6 @@ class BaseProcessor:
|
|||||||
|
|
||||||
def __init__(self,path,resource):
|
def __init__(self,path,resource):
|
||||||
self.path = path
|
self.path = path
|
||||||
print('self.path=',self.path)
|
|
||||||
self.resource = resource
|
self.resource = resource
|
||||||
self.retResponse = None
|
self.retResponse = None
|
||||||
# self.last_modified = os.path.getmtime(path)
|
# self.last_modified = os.path.getmtime(path)
|
||||||
@ -82,7 +81,6 @@ class BaseProcessor:
|
|||||||
indent=4)
|
indent=4)
|
||||||
elif isinstance(self.content,DictObject):
|
elif isinstance(self.content,DictObject):
|
||||||
mydict = self.content.to_dict()
|
mydict = self.content.to_dict()
|
||||||
print('mydict=',mydict,type(mydict))
|
|
||||||
self.content = json.dumps(mydict, indent=4)
|
self.content = json.dumps(mydict, indent=4)
|
||||||
elif type(self.content) == type([]):
|
elif type(self.content) == type([]):
|
||||||
self.content = json.dumps(self.content,
|
self.content = json.dumps(self.content,
|
||||||
@ -103,13 +101,13 @@ class TemplateProcessor(BaseProcessor):
|
|||||||
def isMe(self,name):
|
def isMe(self,name):
|
||||||
return name=='tmpl'
|
return name=='tmpl'
|
||||||
|
|
||||||
async def path_call(self, request):
|
async def path_call(self, request, params={}):
|
||||||
await self.set_run_env(request)
|
await self.set_run_env(request)
|
||||||
path = self.path
|
path = self.path
|
||||||
url = self.resource.entireUrl(request, path)
|
url = self.resource.entireUrl(request, path)
|
||||||
ns = self.run_ns
|
ns = self.run_ns
|
||||||
|
ns.update(params)
|
||||||
te = self.run_ns['tmpl_engine']
|
te = self.run_ns['tmpl_engine']
|
||||||
print('****url=',url,'*****')
|
|
||||||
return te.render(url,**ns)
|
return te.render(url,**ns)
|
||||||
|
|
||||||
async def datahandle(self,request):
|
async def datahandle(self,request):
|
||||||
@ -146,7 +144,6 @@ class PythonScriptProcessor(BaseProcessor):
|
|||||||
|
|
||||||
def loadScript(self, path):
|
def loadScript(self, path):
|
||||||
data = ''
|
data = ''
|
||||||
print('path=',path)
|
|
||||||
with codecs.open(path,'rb','utf-8') as f:
|
with codecs.open(path,'rb','utf-8') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
b= ''.join(data.split('\r'))
|
b= ''.join(data.split('\r'))
|
||||||
@ -155,9 +152,10 @@ class PythonScriptProcessor(BaseProcessor):
|
|||||||
txt = "async def myfunc(request,**ns):\n" + '\n'.join(lines)
|
txt = "async def myfunc(request,**ns):\n" + '\n'.join(lines)
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
async def path_call(self, request):
|
async def path_call(self, request,params={}):
|
||||||
await self.set_run_env(request)
|
await self.set_run_env(request)
|
||||||
lenv = self.run_ns
|
lenv = self.run_ns
|
||||||
|
lenv.update(params)
|
||||||
del lenv['request']
|
del lenv['request']
|
||||||
txt = self.loadScript(self.real_path)
|
txt = self.loadScript(self.real_path)
|
||||||
exec(txt,lenv,lenv)
|
exec(txt,lenv,lenv)
|
||||||
@ -165,7 +163,6 @@ class PythonScriptProcessor(BaseProcessor):
|
|||||||
return await func(request,**lenv)
|
return await func(request,**lenv)
|
||||||
|
|
||||||
async def datahandle(self,request):
|
async def datahandle(self,request):
|
||||||
print('self.real_path=',self.real_path)
|
|
||||||
self.content = await self.path_call(request)
|
self.content = await self.path_call(request)
|
||||||
|
|
||||||
class MarkdownProcessor(BaseProcessor):
|
class MarkdownProcessor(BaseProcessor):
|
||||||
|
@ -30,7 +30,6 @@ async def file_download(request, filepath, content_type=None):
|
|||||||
r.content_type = 'application/octet-stream'
|
r.content_type = 'application/octet-stream'
|
||||||
r.content_disposition = 'attachment; filename=%s' % filename
|
r.content_disposition = 'attachment; filename=%s' % filename
|
||||||
r.enable_compression()
|
r.enable_compression()
|
||||||
print(filepath,filename)
|
|
||||||
return r
|
return r
|
||||||
if os.path.exists(filepath):
|
if os.path.exists(filepath):
|
||||||
length = os.path.getsize(filepath)
|
length = os.path.getsize(filepath)
|
||||||
@ -40,17 +39,14 @@ async def file_download(request, filepath, content_type=None):
|
|||||||
'Content-Disposition': 'attrachment;filename={}'.format(filename)
|
'Content-Disposition': 'attrachment;filename={}'.format(filename)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
print('downloading',filepath,'size',length)
|
|
||||||
await response.prepare(request)
|
await response.prepare(request)
|
||||||
cnt = 0
|
cnt = 0
|
||||||
with open(filepath, 'rb') as f:
|
with open(filepath, 'rb') as f:
|
||||||
chunk = f.read(10240000)
|
chunk = f.read(10240000)
|
||||||
cnt = cnt + len(chunk)
|
cnt = cnt + len(chunk)
|
||||||
await response.write(chunk)
|
await response.write(chunk)
|
||||||
print('write size=',cnt)
|
|
||||||
await response.fsyn()
|
await response.fsyn()
|
||||||
await response.write_eof()
|
await response.write_eof()
|
||||||
print('end')
|
|
||||||
return response
|
return response
|
||||||
raise HTTPNotFound
|
raise HTTPNotFound
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ class FunctionProcessor(BaseProcessor):
|
|||||||
|
|
||||||
async def path_call(self, request, path):
|
async def path_call(self, request, path):
|
||||||
path1 = request.path[len(self.config_opts['leading']):]
|
path1 = request.path[len(self.config_opts['leading']):]
|
||||||
print('path1=',path1)
|
|
||||||
args = []
|
args = []
|
||||||
if len(path1) > 0:
|
if len(path1) > 0:
|
||||||
if path1[0] == '/':
|
if path1[0] == '/':
|
||||||
@ -25,7 +24,6 @@ class FunctionProcessor(BaseProcessor):
|
|||||||
args = path1.split('/')
|
args = path1.split('/')
|
||||||
|
|
||||||
|
|
||||||
print('FunctionProcessor():args=',args)
|
|
||||||
rfname = self.config_opts['registerfunction']
|
rfname = self.config_opts['registerfunction']
|
||||||
ns = DictObject(**self.run_ns)
|
ns = DictObject(**self.run_ns)
|
||||||
rf = RegisterFunction()
|
rf = RegisterFunction()
|
||||||
|
@ -48,8 +48,6 @@ class TemplateEngine(Environment):
|
|||||||
def setupTemplateEngine():
|
def setupTemplateEngine():
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
subffixes = [ i[0] for i in config.website.processors if i[1] == 'tmpl' ]
|
subffixes = [ i[0] for i in config.website.processors if i[1] == 'tmpl' ]
|
||||||
print(subffixes)
|
|
||||||
# paths = [ os.path.abspath(p) for p,prefix in config.website.paths ]
|
|
||||||
loader = TmplLoader(config.website.paths,
|
loader = TmplLoader(config.website.paths,
|
||||||
config.website.indexes,
|
config.website.indexes,
|
||||||
subffixes,
|
subffixes,
|
||||||
|
@ -95,7 +95,6 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
|
|
||||||
def abspath(self, request, path:str):
|
def abspath(self, request, path:str):
|
||||||
url = self.entireUrl(request, path)
|
url = self.entireUrl(request, path)
|
||||||
print('url=',url, 'path=',path)
|
|
||||||
return self.url2file(url)
|
return self.url2file(url)
|
||||||
|
|
||||||
async def getPostData(self,request: Request) -> dict:
|
async def getPostData(self,request: Request) -> dict:
|
||||||
@ -228,11 +227,9 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
return await processor.handle(request)
|
return await processor.handle(request)
|
||||||
|
|
||||||
filepath = self.url2file(str(request.url))
|
filepath = self.url2file(str(request.url))
|
||||||
print('filepath=',filepath,str(request.url))
|
|
||||||
if filepath and self.isHtml(filepath):
|
if filepath and self.isHtml(filepath):
|
||||||
return await self.html_handle(request, filepath)
|
return await self.html_handle(request, filepath)
|
||||||
|
|
||||||
print(f'path={path} handler by StaticResource..')
|
|
||||||
if os.path.isdir(filepath):
|
if os.path.isdir(filepath):
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
if not config.website.allowListFolder:
|
if not config.website.allowListFolder:
|
||||||
@ -270,7 +267,6 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
host = '/'.join(str(request.url).split('/')[:3])
|
host = '/'.join(str(request.url).split('/')[:3])
|
||||||
path = url[len(host):].split('?')[0]
|
path = url[len(host):].split('?')[0]
|
||||||
real_path = self.abspath(request, path)
|
real_path = self.abspath(request, path)
|
||||||
print('real_path=', real_path)
|
|
||||||
if config.website.startswiths:
|
if config.website.startswiths:
|
||||||
for a in config.website.startswiths:
|
for a in config.website.startswiths:
|
||||||
if path.startswith(a.leading):
|
if path.startswith(a.leading):
|
||||||
@ -297,7 +293,7 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
async def path_call(self,request, path, params={}):
|
async def path_call(self,request, path, params={}):
|
||||||
url = self.entireUrl(request, path)
|
url = self.entireUrl(request, path)
|
||||||
processor = self.url2processor(request, url)
|
processor = self.url2processor(request, url)
|
||||||
return await processor.path_call(request)
|
return await processor.path_call(request, params=params)
|
||||||
|
|
||||||
def url_call(self,request, url,params={}):
|
def url_call(self,request, url,params={}):
|
||||||
processor = self.url2processor(request, url)
|
processor = self.url2processor(request, url)
|
||||||
@ -308,9 +304,7 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
return processor.content
|
return processor.content
|
||||||
long_url = self.entireUrl(request,url)
|
long_url = self.entireUrl(request,url)
|
||||||
hc = Http_Client()
|
hc = Http_Client()
|
||||||
print('url_call() called,long_url=',long_url)
|
|
||||||
x = hc(long_url,method=method,params=params)
|
x = hc(long_url,method=method,params=params)
|
||||||
print('url_call() call finished')
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def absUrl(self,request,url):
|
def absUrl(self,request,url):
|
||||||
|
@ -53,7 +53,6 @@ class RestEndpoint:
|
|||||||
|
|
||||||
class DBCrud(RestEndpoint):
|
class DBCrud(RestEndpoint):
|
||||||
def __init__(self, request,dbname,tablename, id=None):
|
def __init__(self, request,dbname,tablename, id=None):
|
||||||
print(f'***{dbname}*{tablename}*{id}************')
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.dbname = dbname
|
self.dbname = dbname
|
||||||
self.tablename = tablename
|
self.tablename = tablename
|
||||||
|
@ -30,27 +30,22 @@ class Url2File:
|
|||||||
paths = paths[3:]
|
paths = paths[3:]
|
||||||
f = os.path.join(self.path,*paths)
|
f = os.path.join(self.path,*paths)
|
||||||
real_path = os.path.abspath(f)
|
real_path = os.path.abspath(f)
|
||||||
print('0 - url2file():real_path=', real_path,'url=',url)
|
|
||||||
if os.path.isdir(real_path):
|
if os.path.isdir(real_path):
|
||||||
for idx in self.indexes:
|
for idx in self.indexes:
|
||||||
p = os.path.join(real_path,idx)
|
p = os.path.join(real_path,idx)
|
||||||
if os.path.isfile(p):
|
if os.path.isfile(p):
|
||||||
print('find it:',p, 'url=', url)
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
if os.path.isfile(real_path):
|
if os.path.isfile(real_path):
|
||||||
print('find it here:',real_path, 'url=', url)
|
|
||||||
return real_path
|
return real_path
|
||||||
|
|
||||||
if not self.inherit:
|
if not self.inherit:
|
||||||
print('1-real_path=', real_path, ' not exists')
|
|
||||||
return None
|
return None
|
||||||
items = url.split('/')
|
items = url.split('/')
|
||||||
if len(items) > 2:
|
if len(items) > 2:
|
||||||
del items[-2]
|
del items[-2]
|
||||||
url = '/'.join(items)
|
url = '/'.join(items)
|
||||||
return self.url2file(url)
|
return self.url2file(url)
|
||||||
print('2-real_path=', real_path, ' not exists')
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def relatedurl(self,url: str, name: str) -> str:
|
def relatedurl(self,url: str, name: str) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user