Beispiel #1
0
async def create_in_db(db: AsyncIOMotorDatabase, *,
                       user_in: UserCreate) -> InsertOneResult:
    passwordhash = get_password_hash(user_in.password)
    user = UserInDB(**user_in.dict(), hashed_password=passwordhash)
    doc_data = jsonable_encoder(user)

    res = await db[USER_COLLECTION_NAME].insert_one(doc_data)
    return res
Beispiel #2
0
async def create_license_user(
    slug: str,
    data: UserCreate,
    current_user: User = Depends(get_current_active_user)):
    logging.info(">>> " + __name__ + ":create")
    slug = slug.strip().lower()
    # data.license = license
    logging.info(data)
    model = UserCreate(**data.dict())
    # model.license = slug
    logging.info(model)
    user = await crud.find_by_email_or_username(data.email, data.username)
    if user:
        raise_bad_request(
            "Username or email is already registered in the system.")
    return await crud.insert_one(slug, model, license_owner=False)
Beispiel #3
0
async def insert_one(license: str, data: UserCreate, license_owner: bool):
    logging.info(">>> " + __name__ + ":insert_one")
    collection = get_collection(DOCUMENT_TYPE)
    fpwd = create_fpwd(data.username)
    hashed_password = get_password_hash(fpwd)
    model = UserSave(**data.dict(),
                     license=license,
                     hashed_password=hashed_password)
    props = fields_in_create(model)
    props["xfpwd"] = fpwd[::-1]
    try:
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            user = await collection.find_one({"_id": rs.inserted_id})
            return user
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))
Beispiel #4
0
async def insert_one(data: UserCreate):
    logging.info(">>> " + __name__ + ":insert_one")

    # Check license
    valid = await is_license_valid(data.license)
    if not valid:
        raise_bad_request("License is not valid")

    collection = get_collection(DOCUMENT_TYPE)
    hashed_password = get_password_hash(data.password)
    model = UserInDB(**data.dict(), hashed_password=hashed_password)
    props = fields_in_create(model)

    try:
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            user = await collection.find_one({"_id": rs.inserted_id})
            return user
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))