From 3290fe1f97acbafac669dbf3012b3f33695e9076 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 10 Jul 2019 18:42:54 +0800 Subject: [PATCH] modify README.md --- ah.py | 19 ++++++++++++++++++- ahserver/auth_api.py | 2 -- ahserver/configuredServer.py | 12 ++---------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ah.py b/ah.py index 0e066fe..1c9a5d9 100644 --- a/ah.py +++ b/ah.py @@ -1,5 +1,22 @@ 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__': - server = ConfiguredServer() + server = ConfiguredServer(AuthAPI) server.run() diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index cd170af..18be00f 100644 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -55,8 +55,6 @@ class AuthAPI: raise web.HTTPForbidden() async def needAuth(self,path): - if path in ['/','/header.tmpl','footer.tmpl','/login','/login_form','/index.tmpl',]: - return False return False async def getPermissionNeed(self,path): diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index ef7ad43..7fe4b9e 100644 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -13,7 +13,7 @@ from .myTE import setupTemplateEngine from .globalEnv import initEnv class ConfiguredServer: - def __init__(self): + def __init__(self,auth_klass=AuthAPI): pp = ProgramPath() workdir = pp if len(sys.argv) > 1: @@ -24,7 +24,7 @@ class ConfiguredServer: initEnv() setupTemplateEngine() self.app = web.Application() - auth = AuthAPI() + auth = auth_klass() auth.setupAuth(self.app) self.configPath(config) @@ -47,11 +47,3 @@ class ConfiguredServer: res.setIndexes(config.website.indexes or []) 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