Exemplo n.º 1
0
Arquivo: users.py Projeto: antidoc/SN
    async def get_user_by_id(self, *, id: int) -> UserInDB:
        user_record = await self.db.fetch_one(query=GET_USER_BY_ID_QUERY,
                                              values={"id": id})

        if not user_record:
            return None

        return UserInDB(**user_record)
Exemplo n.º 2
0
Arquivo: users.py Projeto: antidoc/SN
    async def get_user_by_username(self, *, username: str) -> UserInDB:
        user_record = await self.db.fetch_one(query=GET_USER_BY_USERNAME_QUERY,
                                              values={"username": username})

        if not user_record:
            return None

        return UserInDB(**user_record)
Exemplo n.º 3
0
Arquivo: users.py Projeto: antidoc/SN
    async def get_user_by_email(self, *, email: EmailStr) -> UserInDB:
        user_record = await self.db.fetch_one(query=GET_USER_BY_EMAIL_QUERY,
                                              values={"email": email})

        if not user_record:
            return None

        return UserInDB(**user_record)
Exemplo n.º 4
0
    async def create_user(self, new_user: PostUserModel) -> UserInDB:
        if await self.get_user_by_email(email=new_user.email):
            raise HTTPException(status_code=409, detail="Email taken!")

        if await self.get_user_by_username(username=new_user.username):
            raise HTTPException(status_code=409, detail="Username taken!")

        user_password_update = self.auth_service.create_salt_and_hashed_password(
            plaintext_password=new_user.password)
        new_user = new_user.copy(update=user_password_update.dict())
        response = await self.__execute_query(query=create_user_query(new_user)
                                              )

        return UserInDB(**response)
Exemplo n.º 5
0
Arquivo: users.py Projeto: antidoc/SN
    async def register_new_user(self, *, new_user: UserCreate):
        if await self.get_user_by_email(email=new_user.email):
            raise HTTPException(
                status_code=HTTP_400_BAD_REQUEST,
                detail=
                "That email is already taken. Login with this email or register with another one"
            )
        if await self.get_user_by_username(username=new_user.username):
            raise HTTPException(
                status_code=HTTP_400_BAD_REQUEST,
                detail=
                "That username is already taken. Login with this username or register with another one"
            )

        user_password_update = self.auth_service.create_salt_and_hashed_password(
            plaintext_password=new_user.password)
        new_user_params = new_user.copy(update=user_password_update.dict())
        created_user = await self.db.fetch_one(query=REGISTER_NEW_USER_QUERY,
                                               values=new_user_params.dict())

        return UserInDB(**created_user)
Exemplo n.º 6
0
 async def get_user_by_username(self, *, username: str) -> UserInDB:
     user = await self.__execute_query(query=get_user_by_username_query(
         username=username))
     return UserInDB(**user) if user else None
Exemplo n.º 7
0
 async def get_user_by_email(self, *, email: str) -> UserInDB:
     user = await self.__execute_query(query=get_user_by_email_query(
         email=email))
     return UserInDB(**user) if user else None
Exemplo n.º 8
0
def get_user(username: str):
    user = db.users.find_one({"username": username})
    if user:
        return UserInDB(**user)