modify README.md

This commit is contained in:
yumoqing 2019-07-10 18:42:54 +08:00
parent 7c837b3afa
commit 3290fe1f97
3 changed files with 20 additions and 13 deletions

19
ah.py
View File

@ -1,5 +1,22 @@
from ahserver.configuredServer import ConfiguredServer from ahserver.configuredServer import ConfiguredServer
from ahserver.auth_api import AuthAPI
"""
need to implement your AuthAPI
class MyAuthAPI:
def needAuth(self,path):
return Fasle # do not need authentication
return True # need authentication
async def getPermissionNeed(self,path):
return 'admin'
async def checkUserPassword(self,user_id,password):
return True
async def getUserPermissions(self,user):
return ['admin','view']
"""
if __name__ == '__main__': if __name__ == '__main__':
server = ConfiguredServer() server = ConfiguredServer(AuthAPI)
server.run() server.run()

View File

@ -55,8 +55,6 @@ class AuthAPI:
raise web.HTTPForbidden() raise web.HTTPForbidden()
async def needAuth(self,path): async def needAuth(self,path):
if path in ['/','/header.tmpl','footer.tmpl','/login','/login_form','/index.tmpl',]:
return False
return False return False
async def getPermissionNeed(self,path): async def getPermissionNeed(self,path):

View File

@ -13,7 +13,7 @@ from .myTE import setupTemplateEngine
from .globalEnv import initEnv from .globalEnv import initEnv
class ConfiguredServer: class ConfiguredServer:
def __init__(self): def __init__(self,auth_klass=AuthAPI):
pp = ProgramPath() pp = ProgramPath()
workdir = pp workdir = pp
if len(sys.argv) > 1: if len(sys.argv) > 1:
@ -24,7 +24,7 @@ class ConfiguredServer:
initEnv() initEnv()
setupTemplateEngine() setupTemplateEngine()
self.app = web.Application() self.app = web.Application()
auth = AuthAPI() auth = auth_klass()
auth.setupAuth(self.app) auth.setupAuth(self.app)
self.configPath(config) self.configPath(config)
@ -47,11 +47,3 @@ class ConfiguredServer:
res.setIndexes(config.website.indexes or []) res.setIndexes(config.website.indexes or [])
self.app.router.register_resource(res) self.app.router.register_resource(res)
def addProcessors(self,config,resource):
for subfix,processorname in config.website.processors:
resource.addProcessor(subfix,processorname)
return resource
def addIndexes(self,res,indexes):
res.indexes = indexes
return res