def update_information_wop(original_email, updated_email, updated_name, updated_image): session = db_session.create_session() user = session.query(User).filter_by(email=original_email).first() user.email = f'{updated_email}' user.name = f"{updated_name}" user.profile_image_url = updated_image session.commit() return user
def validate_admin(email, password): session = db_session.create_session() admin = session.query(Admins).filter(Admins.email == email).first() if not admin: return None if not verify_hash(admin.hashed_password, password): return None return admin
def validate_user(email, password): session = db_session.create_session() user = session.query(User).filter(User.email == email).first() if not user: return None if not verify_hash(user.hashed_password, password): return None return user
def create_user(name: str, email: str, password: str) -> Optional[User]: if find_user_by_email(email): return None user = User() user.email = email user.name = name user.hashed_password = hash_text(password) session = db_session.create_session() session.add(user) session.commit() return user
def create_admin(name: str, email: str, password: str): if find_admin_by_email(email): return None admin = Admins() admin.email = email admin.name = name admin.hashed_password = hash_text(password) session = db_session.create_session() session.add(admin) session.commit() return admin
def login_user_self(email: str, password: str) -> Optional[User]: session = db_session.create_session() try: user = session.query(User).filter(User.email == email).first() if not user: return None if not verify_hash(user.hashed_password, password): return None return user finally: session.close()
def login_admin_self(email, password): session = db_session.create_session() try: admin = session.query(Admins).filter(Admins.email == email).first() if not admin: return None # if not verify_hash(admin.hashed_password, password): # return None if password != admin.hashed_password: return None return admin finally: session.close()
def find_Admin_id_by_email(email): session = db_session.create_session() admin_email = session.query(Admins).filter(Admins.email == email).first() return admin_email.id
def find_admin_by_id(user_id: int): session = db_session.create_session() admin = session.query(Admins).filter(Admins.id == user_id).first() return admin
def get_admin_count() -> int: session = db_session.create_session() return session.query(Admins).count()
def check_admin_or_user(user_id): session = db_session.create_session() user_id = session.query().filter(User.id == user_id).first() return login_user(user_id)
def find_user_by_id(user_id): session = db_session.create_session() user = session.query(User).filter(User.id == user_id).first() return user
def get_admin(): session = db_session.create_session() return session.query(Admins).all()
def load_user(user_id): session = db_session.create_session() return session.query(Admins).get(user_id)
def find_user_by_email(email): session = db_session.create_session() return session.query(User).filter(User.email == email).first()
def check_admin_or_user(admin_id): session = db_session.create_session() return session.query(Admins).filter(Admins.id == admin_id).first()
def get_user_count() -> int: session = db_session.create_session() return session.query(User).count()
def get_games(): session = db_session.create_session() lst = session.query(Game).all() return lst
def get_user(): session = db_session.create_session() return session.query(User).all()