在 Flask 初始化文件中,我有
app = Flask("myapp")
jwt = JWT(app, AuthController.staff_login, identity)
api.add_resource(StaffLogin, '/login')
StaffLogin
检查用户名/密码,然后依次调用AuthController.staff_login
class AuthController():
def __init__(self):
# TODO: Create a config.yaml
self.engine = create_engine(DefaultConfig.SQLALCHEMY_DATABASE_URI)
Base.metadata.create_all(self.engine)
DBSession = sessionmaker(bind=self.engine)
self.session = DBSession()
def staff_login(self, staff_name, staff_password):
result = self.session.query(Staff) # Irrelevant details of query removed
if Staff_Authentication.check_password(staff_password, query['staff_password']):
# Build login_response as JSON
return login_response
现在我需要这种格式的自定义登录响应
[
{
"projects": [
{
"project_id": 1,
"project_name": "omnipresence",
"project_root": "/path/to/project/files"
}
],
"staff_id": 13,
"staff_name": "adalovelace"
}
]
问题
我如何Flask-JWT
使用我的功能authenticate
?