async def create_user(self, schema: schemas.UserCreateInRegistration, **kwargs): hash_password = get_password_hash(schema.dict().pop("password")) return await self.create( schemas.UserCreateInRegistration( **schema.dict(exclude={"password"}), password=hash_password, **kwargs ) )
def create(self, db: Session, *args, schema: schemas.UserCreate) -> User: password = schema.dict().pop("password") db_obj = User(**schema.dict(exclude={"password"}), password=get_password_hash(password)) db.add(db_obj) db.commit() db.refresh(db_obj) return db_obj
async def create_superuser(self, schema: schemas.UserCreateSchema): hash_password = get_password_hash(schema.dict().pop("password")) return await self.create( schemas.UserBaseSchema( **schema.dict(exclude={"password"}), password=hash_password, ) )
async def update(self, schema: schemas.UserUpdateSchema, *args, **kwargs): hash_password = get_password_hash(schema.dict().pop("password")) return await super().update( self.update_schema( **schema.dict(exclude={'password'}, exclude_unset=True), password=hash_password ), **kwargs )
async def create_superuser(self, schema: schemas.UserCreateInRegistration): hash_password = get_password_hash(schema.dict().pop("password")) return await self.create( schemas.UserCreate( **schema.dict(exclude={"password"}), password=hash_password, is_active=True, is_superuser=True ) )
def create(self, db_session: Session, *, obj_in: UserCreate) -> User: db_obj = User( email=obj_in.email, password=get_password_hash(obj_in.password), first_name=obj_in.first_name, is_superuser=obj_in.is_superuser, ) db_session.add(db_obj) db_session.commit() db_session.refresh(db_obj) return db_obj
def create_superuser(self, db_session: Session, *args, schema: schemas.UserCreate) -> User: db_obj = User( username=schema.username, email=schema.email, password=get_password_hash(schema.password), first_name=schema.first_name, is_superuser=schema.is_superuser, is_active=schema.is_active, ) db_session.add(db_obj) db_session.commit() db_session.refresh(db_obj) return db_obj
async def change_password(self, obj: models.User, new_password: str): hashed_password = get_password_hash(new_password) obj.password = hashed_password await obj.save()