70 lines
1.5 KiB
Python
70 lines
1.5 KiB
Python
"""Package containing views."""
|
|
|
|
# vim: set tw=80 ts=4 sw=4 sts=4:
|
|
|
|
from flask_cors import CORS
|
|
from flask_jwt_extended import JWTManager
|
|
from flask_restplus import Api
|
|
|
|
from .accounts import ns as accounts_ns
|
|
from .operations import ns as operations_ns
|
|
from .scheduled_operations import ns as scheduled_operations_ns
|
|
from .users import ns as users_ns
|
|
|
|
# API initialization.
|
|
# pylint: disable=invalid-name
|
|
authorizations = {
|
|
'apikey': {
|
|
'type': 'apiKey',
|
|
'in': 'header',
|
|
'name': 'Authorization',
|
|
},
|
|
'basic': {
|
|
'type': 'basic',
|
|
}
|
|
}
|
|
|
|
# pylint: disable=invalid-name
|
|
api = Api(
|
|
title='Accountant API',
|
|
version='2.0',
|
|
description='This is the Accountant API.',
|
|
authorizations=authorizations,
|
|
prefix='/api'
|
|
)
|
|
|
|
|
|
api.add_namespace(accounts_ns)
|
|
api.add_namespace(operations_ns)
|
|
api.add_namespace(scheduled_operations_ns)
|
|
api.add_namespace(users_ns)
|
|
|
|
# pylint: disable=invalid-name
|
|
cors = CORS()
|
|
|
|
jwt = JWTManager()
|
|
|
|
|
|
@jwt.user_identity_loader
|
|
def user_identity_lookup(user):
|
|
"""Return information to be in token."""
|
|
return user.id
|
|
|
|
|
|
@jwt.expired_token_loader
|
|
def expired_token_callback():
|
|
"""Handler for expired token."""
|
|
api.abort(401, "Expired token.")
|
|
|
|
|
|
@jwt.unauthorized_loader
|
|
def unauthorized_callback(message):
|
|
"""Handler for unauthorized."""
|
|
api.abort(401, message)
|
|
|
|
|
|
@jwt.invalid_token_loader
|
|
def invalid_token_callback(message):
|
|
"""Handler for invalid token."""
|
|
api.abort(401, message)
|