web2py内置了很多登录验证器,常用的本地化认证auth,认证方法都在gluon/contrib/login_methods中
使用方法:
from gluon/contrib import 选用的方法
#注释后,启用auth自己的本地认证
auth.settings.login_methods=[方法及变量,]
web2py自定义登录验证方式钩子的实现,需要类似原有的方法,把认证放到modules目录下
示例custom_auth.py
def custom_auth(db,appname,auth,response,server="http://127.0.0.1"):
def rmis(参数)
return True/False
def custom_auth_login(username,
password,
server=server,db=db):
username,password会自动传入,其他的参数通过db.py设置登录方法传入
if rmis(参数):
登录成功
设置本地登录环境login_bare设置
return True #登录成功
else:
return False #登录失败
在db.py中调用登录:
from custom_auth import custom_auth
auth.settings.create_user_groups = False
auth.settings.allow_basic_login=True
#注释后,启用auth自己的本地认证
auth.settings.login_methods=[custom_auth(db=db,appname='',response1=response,auth=auth),]