auth = None if os.getenv('AUTH_TYPE') == 'auth': from api.v1.auth.auth import Auth auth = Auth() elif os.getenv('AUTH_TYPE') == 'basic_auth': from api.v1.auth.basic_auth import BasicAuth auth = BasicAuth() elif getenv('AUTH_TYPE') == 'session_auth': from api.v1.auth.session_auth import SessionAuth auth = SessionAuth() elif getenv('AUTH_TYPE') == 'session_exp_auth': from api.v1.auth.session_exp_auth import SessionExpAuth auth = SessionExpAuth() elif getenv('AUTH_TYPE') == 'session_db_auth': from api.v1.auth.session_db_auth import SessionDBAuth auth = SessionDBAuth() @app.errorhandler(404) def not_found(error) -> str: """ Not found handler """ return jsonify({"error": "Not found"}), 404 @app.errorhandler(401) def unauthorized(error) -> str: """ Request unauthorized """ return jsonify({"error": "Unauthorized"}), 401
from flask import Flask, request from api.v1.auth.session_auth import SessionAuth from models.user import User from api.v1.auth.session_db_auth import SessionDBAuth """ Create a user test """ user_email = "*****@*****.**" user_clear_pwd = "fake pwd" user = User() user.email = user_email user.password = user_clear_pwd user.save() """ Create a session ID """ sa = SessionDBAuth() session_id = sa.create_session(user.id) print("User with ID: {} has a Session ID: {}".format(user.id, session_id)) print("--------------------------------------------------------------") """ User ID For Session ID """ user_id = sa.user_id_for_session_id(session_id) print(f"Session with ID: {session_id} has a User ID: {user_id}") """ Create a Flask app """ app = Flask(__name__) @app.route('/', methods=['GET'], strict_slashes=False) def root_path(): """ Root path