Esempio n. 1
0
app.config['JWT_BLACKLIST_ENABLE'] = True
app.config['JWT_SECRET_KEY'] = 'IDontKnow'
#app.config['PROPAGATE_EXCEPTIONS'] = True
api = Api(app)
jwt = JWTManager(app)

api.add_resource(Hoteis, '/hoteis')
api.add_resource(Hotel, '/hoteis/<string:id>')
api.add_resource(Sites, '/sites')
api.add_resource(Site, '/site/<string:url>')
api.add_resource(Usuario, '/usuarios/<int:id>')
api.add_resource(UsuarioRegister, '/register')
api.add_resource(UsuarioLogin, '/login')
api.add_resource(UsuarioLogout, '/logout')

@app.before_first_request
def cria_banco():
    banco.create_all()

@jwt.token_in_blacklist_loader
def verifica_blacklist(token):
    return token['jti'] in BLACKLIST

@jwt.revoked_token_loader
def token_de_acesso_invalido():
    return jsonify({'message': 'You have been logged out with success'}), 401

if __name__ == '__main__':
    from sql_alchemy import banco
    banco.init_app(app)
    app.run(debug=True)
Esempio n. 2
0
@app.before_first_request  #verifica se existe banco e executa o create all se não existir
def create_db():
    banco.create_all()


@jwt.token_in_blacklist_loader  #determina que funcao verifique se o token esta na blacklist
def check_blacklist(token):
    return token['jti'] in BLACKLIST


@jwt.revoked_token_loader  #acesso revogado
def revoked_token():
    return jsonify(
        {'message': 'You have been logged out'}
    ), 401  #dicionario aqui em app não é reconhecido diretamente, por isso o uso do jsonify


api.add_resource(Clients, '/clients')
api.add_resource(Client, '/client/<string:email>')
api.add_resource(ClientRegister, '/signup')
api.add_resource(ClientLogin, '/login')
api.add_resource(ClientLogout, '/logout')
api.add_resource(addProduct, '/addProduct/<string:email>')
api.add_resource(showClientProduct,
                 '/showClientProduct/<string:email>/<string:id>')

if __name__ == '__main__':
    from sql_alchemy import banco
    banco.init_app(app)  #só executa se for chamado aqui
    app.run(debug=True)
Esempio n. 3
0
@_APP.before_first_request
def create_data_base():
    banco.create_all()


@_JWT.token_in_blacklist_loader
def verify_blacklist(token):
    return token['jti'] in BLACKLIST


@_JWT.revoked_token_loader
def token_invalidate():
    return jsonify({'message':
                    'You have been logged out.'}), server_code.UNAUTHORIZED


_API.add_resource(Hoteis, '/hoteis')
_API.add_resource(Hotel, '/hotel/<string:hotel_id>')
_API.add_resource(Usuario, '/usuario/<int:user_id>')
_API.add_resource(UsuarioRegister, '/cadastro')
_API.add_resource(Login, '/login')
_API.add_resource(Logout, '/logout')
_API.add_resource(Sites, '/sites')
_API.add_resource(Site, '/site/<string:url>')
_API.add_resource(UserConfirm, '/confirmacao/<int:user_id>')

if __name__ == '__main__':
    from sql_alchemy import banco
    banco.init_app(_APP)
    _APP.run(host="0.0.0.0", port=5000, debug=True)
Esempio n. 4
0
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///banco.db' # aqui pode mudar o tipo de banco para qualquer outro (PostgreSQL, MySQL,etc)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['JWT_SECRET_KEY'] = 'DontTellAnyone' # essa é a chave de criptografia
app.config['JWT_BLACKLIST_ENABLED'] = True
api = Api(app)
jwt = JWTManager(app)

@app.before_first_request
def cria_banco():
	banco.create_all()

@jwt.token_in_blacklist_loader
def verifica_blacklist(token):
	return token['jti'] in BLACKLIST

@jwt.revoked_token_loader
def token_de_acesso_invalidado():
	return jsonify({'message': 'You have been logged out.'}), 401 #unauthorized

api.add_resource(Hoteis, '/hoteis')
api.add_resource(Hotel, '/hoteis/<string:hotel_id>')
api.add_resource(User, '/usuarios/<int:user_id>')
api.add_resource(UserRegister, '/cadastro')
api.add_resource(UserLogin, '/login')
api.add_resource(UserLogout, '/logout')

if __name__ == '__main__':
	from sql_alchemy import banco
	banco.init_app(app) # só executa se for chamado pelo __main__
	app.run(debug=True,host= '0.0.0.0', port= 5000)  #local host
	#app.run(debug=True,host= '192.168.0.5', port= 5000)  #router host
Esempio n. 5
0
api = Api(app)
jwt = JWTManager(app)

@app.before_first_request #antes da primeiro requisição
def cria_banco():
	banco.create_all()

@jwt.token_in_blacklist_loader
def verifica_blacklist(token):
	return token['jti'] in BLACKLIST

@jwt.revoked_token_loader
def token_de_acesso_invalidado():
	return jsonify({'message': 'Você foi deslogado!'}), 401 #unauthorized #converter dict para json

api.add_resource(Hoteis, '/hoteis') #recurso importado
api.add_resource(Hotel, '/hoteis/<string:hotel_id>')
api.add_resource(User, '/usuarios/<int:user_id>')
api.add_resource(UserRegister, '/cadastro')
api.add_resource(UserLogin, '/login')
api.add_resource(UserLogout, '/logout')
api.add_resource(Sites, '/sites')
api.add_resource(Site, '/sites/<string:url>')
api.add_resource(UserConfirm, '/confirmacao/<int:user_id>')

if __name__ == '__main__': #se o nome for o principal, rode
    from sql_alchemy import banco
    banco.init_app(app) #só executa se chamar o app.py
    app.run(debug=True)
Esempio n. 6
0
def cria_banco():
    from sql_alchemy import banco
    banco.init_app(app)
    banco.create_all()