def app():
    app = Flask(__name__)
    app.debug = True
    app.config["API_RESOURCE_JSON"] = "testdata/resource.json"
    app.config["API_PERMISSION_JSON"] = "testdata/permission.json"

    def fn_user_role(token):
        user_id = token["id"]
        user_roles = ["访客", "普通用户", "管理员"]
        return user_roles[user_id]

    api = Api(app)
    auth = Auth(api, fn_user_role=fn_user_role)

    class User(Resource):

        schema_inputs = {"post": {"id": "int(0,2)&required"}}

        def get(self):
            return "ok"

        def post(self, id):
            return "ok", auth.gen_header({"id": id})

    api.add_resource(User)
    api.add_resource(Permission, auth=auth)
    app.api = api
    app.auth = auth
    return app
Example #2
0
import config

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from finance.utils import Auth

app = Flask(__name__)
app.config.from_object(config)
app.auth = Auth()

db = SQLAlchemy(app)

import finance.views.base  # noqa