Search code examples
pythonflaskeve

Custom requests bypassing token auth in EVE


I'm new to EVE framework, but already have some experience with flask and mongodb. I want to build a web app based on eve rest with token auth. So for example I have the case: I want to check if email exists in realtime when user filled out the form. The user info is in users collection, but I want to put users collection under token auth. So how should I handle custom request without token? Should it be handled through flask?

Maybe something like this:

@app.route('/_check_email', methods=['GET'])
def check_email():
    print request
    email = request.args.get('email', 0, type=str)
    accounts = app.data.driver.db['users']
    lookup = {'email': email}
    account = accounts.find_one(lookup)
    if not account:
        return jsonify(valid=True)
    else:
        return jsonify(valid=False)

Thanks!


Solution

  • You might want to wrap it all in a Flask Blueprint. See what's been done with Eve-Docs extension. Other than that, Eve is just a Flask subclass so you are free to play with it as you would do with Flask itself.