def signout():
    userToken = request.headers.get(
        'token'
    )  # Got THROUGH request.header() instead  #have to send in token as json string for now
    if database_helper.find_active_user(userToken):
        if database_helper.signout_user(userToken):
            return jsonify(success="true", message="Logout successfull")
        else:
            return jsonify(success=False, message="Couldnt log out")
    else:
        return jsonify(success=False, message="User not logged in")
def messagebyemail():
    email = request.args.get('email')
    userToken = request.headers.get('token')

    if database_helper.find_active_user(userToken):
        if email is None:
            return jsonify(success=False, message="Cant find email")
        else:
            #email = email[0]
            result = database_helper.message_by_email(email)
            return jsonify(success=True,
                           message="successfully found messages",
                           messages=result)
    else:
        return jsonify(success=False, message="User not logged in")
def find_by_email():
    email = request.args.get('email')
    userToken = request.headers.get('token')

    if database_helper.find_active_user(userToken):
        if email is None:
            return jsonify(success=False,
                           message="Cant find email with that token")
        else:
            result = database_helper.data_by_email(email)
            user = {
                'email': result[0],
                'firstname': result[1],
                'familyname': result[2],
                'gender': result[3],
                'city': result[4],
                'country': result[5]
            }
            return jsonify(success=True, message="Fetched data", data=user)
    else:
        return jsonify(success=False, message="User not logged in")
def data_token():
    token = request.headers.get(
        'token')  #Was old verision that used "args.get"
    if database_helper.find_active_user(token):
        email = database_helper.get_email_by_token(token)
        if email is None:
            return jsonify(success=False,
                           message="Cant find email with that token")
        else:
            result = database_helper.data_by_email(email)
            user = {
                'email': result[0],
                'firstname': result[1],
                'familyname': result[2],
                'gender': result[3],
                'city': result[4],
                'country': result[5]
            }
            return jsonify(success=True, message="Fetched data", data=user)
    else:
        return jsonify(success=False,
                       message="Cant find active user with that token")