# Path: src/main.py
# def on_shutdown():


from flask_security.utils import verify_password
from flask_jwt import JWT, jwt_required
from .main import app, user_datastore
'''
    Authentication stuff for the REST API.
'''



def auth_handler(username, password):
    user = user_datastore.find_user(email=username)
    if username == user.email and verify_password(password, user.password):
        return user


def load_user(payload):
    user = user_datastore.find_user(id=payload['identity'])
    return user


@jwt_required()
def check_auth(*args, **kwargs):
    return True  # decorator does all the work ;-)



# Path: src/main.py
# def on_shutdown():


# Path: src/auth.py
from flask_security.utils import verify_password
from flask_jwt import JWT, jwt_required
from .main import app, user_datastore

'''
    Authentication stuff for the REST API.
'''



def auth_handler(username, password):
    user = user_datastore.find_user(email=username)
    if username == user.email and verify_password(password, user.password):
        return user


def load_user(payload):
    user = user_datastore.find_user(id=payload['identity'])
    return user


@jwt_required()
def check_auth(*args, **kwargs):
    return True  # decorator does all the work ;-)



jwt = JWT(app, auth_handler, load_user)