@app.route('/reset-password', methods=['POST'])
@cross_origin(supports_credentials=True)
def change_password():
    data = request.get_json()
    user = User.query.filter_by(passwordResetToken=str(data['token'])).first()
    if (not user):
        return (jsonify({'message': 'Token inválido!'}), 400)
    date_time_exp = datetime.datetime.strptime(user.passwordResetExpires, '%Y-%m-%d %H:%M:%S.%f')
    if (datetime.datetime.utcnow() > date_time_exp):
        return (jsonify({'message': 'Token expirado, gere um novo!'}), 400)
    if ((len(str(data['password'])) < 8) or (len(str(data['password'])) > 20)):
        return (jsonify({'message': 'Senha inválida!'}), 400)
    hashed_newpassword = generate_password_hash(data['password'], method='sha256')
    user.password = hashed_newpassword
    user.passwordResetToken = None
    user.passwordResetExpires = None
    db.session.commit()
    return (jsonify({'message': 'Senha trocada com sucesso!'}), 200)
@app.route('/reset-password', methods=['POST'])
@cross_origin(supports_credentials=True)
def change_password():
    data = request.get_json()
    user = User.query.filter_by(passwordResetToken=str(data['token'])).first()
    if (not user):
        return (jsonify({'message': 'Token inválido!'}), 400)
    date_time_exp = datetime.datetime.strptime(user.passwordResetExpires, '%Y-%m-%d %H:%M:%S.%f')
    if (datetime.datetime.utcnow() > date_time_exp):
        return (jsonify({'message': 'Token expirado, gere um novo!'}), 400)
    if ((len(str(data['password'])) < 8) or (len(str(data['password'])) > 20)):
        return (jsonify({'message': 'Senha inválida!'}), 400)
    hashed_newpassword = generate_password_hash(data['password'], method='sha256')
    user.password = hashed_newpassword
    user.passwordResetToken = None
    user.passwordResetExpires = None
    db.session.commit()
    return (jsonify({'message': 'Senha trocada com sucesso!'}), 200)