""" from flask import Flask, request from api.v1.auth.session_auth import SessionAuth from models import db_session from models.user import User """ Create a user test """ user_email = "*****@*****.**" user_clear_pwd = "fake pwd" user = User() user.email = user_email user.password = user_clear_pwd db_session.add(user) db_session.commit() """ Create a session ID """ sa = SessionAuth() session_id = sa.create_session(user.id) print("User with ID: {} has a Session ID: {}".format(user.id, session_id)) """ Create a Flask app """ app = Flask(__name__) @app.route('/', methods=['GET'], strict_slashes=False) def root_path(): """ Root path """ request_user = sa.current_user(request) if request_user is None: return "No user found\n" return "User found: {}\n".format(request_user.id)
#!/usr/bin/env python3 """ Main 2 """ from api.v1.auth.session_auth import SessionAuth sa = SessionAuth() user_id_1 = "abcde" session_1 = sa.create_session(user_id_1) print("{} => {}: {}".format(user_id_1, session_1, sa.user_id_by_session_id)) user_id_2 = "fghij" session_2 = sa.create_session(user_id_2) print("{} => {}: {}".format(user_id_2, session_2, sa.user_id_by_session_id)) print("---") tmp_session_id = None tmp_user_id = sa.user_id_for_session_id(tmp_session_id) print("{} => {}".format(tmp_session_id, tmp_user_id)) tmp_session_id = 89 tmp_user_id = sa.user_id_for_session_id(tmp_session_id) print("{} => {}".format(tmp_session_id, tmp_user_id)) tmp_session_id = "doesntexist" tmp_user_id = sa.user_id_for_session_id(tmp_session_id) print("{} => {}".format(tmp_session_id, tmp_user_id)) print("---")
#!/usr/bin/python3 """ Main 1 """ from api.v1.auth.session_auth import SessionAuth sa = SessionAuth() print("{}: {}".format( type(sa.user_id_by_session_id), sa.user_id_by_session_id)) user_id = None session = sa.create_session(user_id) print("{} => {}: {}".format(user_id, session, sa.user_id_by_session_id)) user_id = 89 session = sa.create_session(user_id) print("{} => {}: {}".format(user_id, session, sa.user_id_by_session_id)) user_id = "abcde" session = sa.create_session(user_id) print("{} => {}: {}".format(user_id, session, sa.user_id_by_session_id)) user_id = "fghij" session = sa.create_session(user_id) print("{} => {}: {}".format(user_id, session, sa.user_id_by_session_id)) user_id = "abcde" session = sa.create_session(user_id) print("{} => {}: {}".format(user_id, session, sa.user_id_by_session_id))