Example #1
0
def get_post(db: Session, post_id: int) -> Any:
    try:
        data = db.query(models.Post).filter(models.Post.id == post_id).first()
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_post")
        return None
Example #2
0
def get_all_user(db: Session) -> Any:
    try:
        data = db.query(models.User).options(defer('password')).all()
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_all_user")
        return None
Example #3
0
def get_user(db: Session, email: str) -> Any:
    try:
        data = db.query(models.User).filter(
            models.User.email == email).options(defer('password')).first()
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_user")
        return None
 def get_user_id(self, query: models.User, user_id: int) -> Any:
     """ Get User Data based on id"""
     try:
         data = query.filter(models.User.id == user_id).first()
         return data
     except SQLAlchemyError as e:
         fastapi_logger.exception("get_user_id")
         return None
Example #5
0
def get_user_id(db: Session, id: int) -> Any:
    try:
        data = db.query(models.User).filter(models.User.id == id).options(
            defer('password')).first()
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_user_id")
        return None
 def get_user_id(self, idd: int) -> Any:
     """ Get User Data based on id"""
     try:
         data = User.objects(id=idd).exclude('password').first()
         return data
     except Exception as e:
         fastapi_logger.exception("get_user_id")
         return None
 def verify_user(self, email: str) -> Any:
     """ Verify User"""
     try:
         data = User.objects(email=email).only('id', 'email').first()
         return data
     except Exception as e:
         fastapi_logger.exception("verify_user")
         return None
Example #8
0
 def get_article(self, article_id: str):
     """ Get A Single article """
     try:
         data = Article.objects(id=article_id).first()
         return data
     except Exception as e:
         fastapi_logger.exception("get_article")
         return None
 def check_active_session(self, session_id: str):
     """ check for active session """
     try:
         db_session = dbconf_models.UsersLoginAttempt.objects(
             session_id=session_id).first()
         return db_session
     except Exception as e:
         fastapi_logger.exception("logoff_user")
         return None
Example #10
0
 def check_password(self, user_id: int, password: str):
     """ get user Password"""
     try:
         db_user = dbconf_models.User.objects(id=user_id).first()
         return passutil.verify_password(str(password),
                                         str(db_user.password))
     except Exception as e:
         fastapi_logger.exception("get_password")
         return None
Example #11
0
 def get_all_user(self) -> Any:
     """ Get All Users"""
     try:
         query = dbconf_models.User.objects.exclude('password').order_by(
             '-modified_timestamp')
         return query.all()
     except Exception as e:
         fastapi_logger.exception("get_all_user")
         return None
 def get_article(self, article_id: str, db: Session):
     """ Get A Single article """
     try:
         data = db.query(models.Article).filter(
             models.Article.article_id == article_id).first()
         return data
     except SQLAlchemyError as e:
         fastapi_logger.exception("get_article")
         return None
 def get_all_user(self, query: models.User) -> Any:
     """ Get All Users"""
     try:
         # data = db.query(models.User).options(defer('password')).all()
         data = query.order_by(models.User.modified_timestamp.desc())
         return data
     except SQLAlchemyError as e:
         fastapi_logger.exception("get_all_user")
         return None
Example #14
0
 def delete_user(self, user_id: int) -> Any:
     """ Delete User"""
     try:
         data = dbconf_models.User.objects(id=user_id)
         data.delete()
         return True
     except Exception as e:
         fastapi_logger.exception("delete_user")
         return None
def get_password(email: str) -> Any:
    """ Get User Data based on email"""
    try:
        # this will extract user data by excluding password
        data = User.objects(email=email).only('password').first()
        return data
    except Exception as e:
        fastapi_logger.exception("get_user")
        return None
Example #16
0
 def delete_article(self, article_id: str) -> Any:
     """ Delete Article """
     try:
         db_article = Article.objects(id=article_id)
         db_article.delete()
         return True
     except Exception as e:
         fastapi_logger.exception("delete_article")
         return None
Example #17
0
def verify_user(db: Session, email: str) -> Any:
    try:
        data = db.query(
            models.User.id,
            models.User.email).filter(models.User.email == email).first()
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("verify_user")
        return None
 def delete_user(self, user_id: int, db: Session) -> Any:
     """ Delete User"""
     try:
         db.query(models.User).filter(models.User.id == user_id).delete()
         db.commit()
         return True
     except SQLAlchemyError as e:
         fastapi_logger.exception("delete_user")
         return None
 def delete_article(self, article_id: str, db: Session) -> Any:
     """ Delete Article """
     try:
         db.query(models.Article).filter(
             models.Article.article_id == article_id).delete()
         db.commit()
         return True
     except SQLAlchemyError as e:
         fastapi_logger.exception("delete_article")
         return None
Example #20
0
def get_all_posts(user_id: int, page_num: int, db: Session) -> Any:
    try:
        # data = db.query(models.Post).paginate(page=page_num, per_page=20)
        query = db.query(models.Post).filter_by(user_id=user_id).order_by(
            models.Post.post_date.desc())
        data = pagination.paginate(query=query, page=page_num, page_size=20)
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_all_posts")
        return None
Example #21
0
def delete_post(db: Session, post_id: int) -> Any:
    try:
        # db_post = db.query(models.Post).delete(models.Post.id == post.id)
        # db.delete(db_post)
        db.query(models.Post).filter(models.Post.id == post_id).delete()
        db.commit()
        return True
    except SQLAlchemyError as e:
        fastapi_logger.exception("delete_post")
        return None
 def check_password(self, user_id: int, password: str, db: Session):
     """ get user Password"""
     try:
         db_user = db.query(models.User.password).filter(
             models.User.id == user_id).first()
         return passutil.verify_password(str(password),
                                         str(db_user.password))
     except SQLAlchemyError as e:
         fastapi_logger.exception("get_password")
         return None
Example #23
0
    def check_active_session(self, session_id: str, db: Session):
        """ check for active session """
        try:
            db_session = db.query(models.UsersLoginAttempt).filter(
                models.UsersLoginAttempt.session_id == session_id).first()

            return db_session
        except SQLAlchemyError as e:
            fastapi_logger.exception("logoff_user")
            return None
Example #24
0
def update_user(db: Session, user_id: int, user: schemas.UserUpdate) -> Any:
    try:
        db_user = db.query(
            models.User).filter(models.User.id == user_id).first()
        db_user.name = user.name
        db.commit()
        db.refresh(db_user)
        return db_user
    except SQLAlchemyError as e:
        fastapi_logger.exception("update_user")
        return None
 def change_user_password(self, user_id: str, password: str) -> Any:
     """ Update User Password"""
     try:
         hashed_password = passutil.get_password_hash(password)
         db_user = User.objects(id=user_id).first()
         db_user.password = hashed_password
         db_user.save()
         return db_user
     except Exception as e:
         fastapi_logger.exception("change_user_password")
         return None
Example #26
0
 def update_user_password(self, email: str, password: str) -> Any:
     """ Update User Password"""
     try:
         hashed_password = passutil.get_password_hash(password)
         db_user = dbconf_models.User.objects(email=email).first()
         db_user.password = hashed_password
         db_user.save()
         return db_user
     except Exception as e:
         fastapi_logger.exception("update_user_password")
         return None
Example #27
0
def delete_user(db: Session, user_id: int) -> Any:
    try:
        # db_user = db.query(models.User).filter(models.User.id == user_id)
        # db.delete(db_user)
        db.query(models.User).filter(models.User.id == user_id).delete()
        db.commit()
        # db.refresh(db_user)
        return True
    except SQLAlchemyError as e:
        fastapi_logger.exception("delete_user")
        return None
Example #28
0
def get_active_user(email: str, db: Session) -> Any:
    """ Get User Data based on email and active status"""
    try:
        data = db.query(models.User).filter(
            models.User.email == email,
            models.User.is_active == expression.true()).options(
                defer('password')).first()
        return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_user")
        return None
 def active_user(self, session_id: str) -> Any:
     """ check for active user"""
     try:
         db_session = dbconf_models.UsersLoginAttempt.objects(
             session_id=session_id).first()
         db_session.status = "active"
         db_session.save()
         return db_session
     except Exception as e:
         fastapi_logger.exception("active_user")
         return None
def get_active_user(email: str) -> Any:
    """ Get User Data based on email and active status"""
    try:
        # this will for check active user and returns data by excluding password
        # data = User.objects(Q(email=email) & Q(is_active=True)).exclude(
        #     'password').first()
        data = User.objects(Q(email=email) & Q(is_active=True)).fields(
            password=0).first()
        return data
    except Exception as e:
        fastapi_logger.exception("get_user")
        return None