@app.route('/login', methods=['POST'])
@cross_origin(supports_credentials=True)
def login():
    auth = request.get_json()
    if ((not auth) or (not auth['email']) or (not auth['password'])):
        return (jsonify({'message': 'Email ou senha não foram preenchidos!'}), 401)
    user = User.query.filter_by(email=auth['email']).first()
    if (not user):
        return (jsonify({'message': 'Email não existe!'}), 401)
    if check_password_hash(user.password, auth['password']):
        token = jwt.encode({'public_id': user.public_id, 'exp': (datetime.datetime.utcnow() + datetime.timedelta(minutes=30))}, app.config['SECRET_KEY'])
        return (jsonify({'token': token.decode('UTF-8'), 'id': user.public_id, 'name': user.name, 'email': user.email}), 200)
    return (jsonify({'message': 'Senha incorreta'}), 401)
@app.route('/login', methods=['POST'])
@cross_origin(supports_credentials=True)
def login():
    auth = request.get_json()
    if ((not auth) or (not auth['email']) or (not auth['password'])):
        return (jsonify({'message': 'Email ou senha não foram preenchidos!'}), 401)
    user = User.query.filter_by(email=auth['email']).first()
    if (not user):
        return (jsonify({'message': 'Email não existe!'}), 401)
    if check_password_hash(user.password, auth['password']):
        token = jwt.encode({'public_id': user.public_id, 'exp': (datetime.datetime.utcnow() + datetime.timedelta(minutes=30))}, app.config['SECRET_KEY'])
        return (jsonify({'token': token.decode('UTF-8'), 'id': user.public_id, 'name': user.name, 'email': user.email}), 200)
    return (jsonify({'message': 'Senha incorreta'}), 401)