Ejemplo n.º 1
0
async def get_user(conn: AsyncIOMotorClient, username: str) -> UserInDB:
    row = await conn[database_name][users_collection_name].find_one(
        {"username": username})
    if row:
        dbuser = UserInDB(**row)
        dbuser.id = str(row["_id"])
        return dbuser
Ejemplo n.º 2
0
async def get_user_by_email(conn: AsyncIOMotorClient,
                            email: EmailStr) -> UserInDB:
    row = await conn[database_name][users_collection_name].find_one(
        {"email": email})
    if row:
        dbuser = UserInDB(**row)
        dbuser.id = str(row["_id"])
        return dbuser
Ejemplo n.º 3
0
async def create_user(conn: AsyncIOMotorClient,
                      user: UserInRegister) -> UserInDB:
    dbuser = UserInDB(**user.dict())
    dbuser.change_password(user.password)
    dbuser.created_at = datetime.now()
    dbuser.updated_at = datetime.now()

    inserted_row = await conn[database_name][users_collection_name].insert_one(
        dbuser.dict())
    dbuser.id = str(inserted_row.inserted_id)

    return dbuser