def create(db: Session, user_in: schemas.UserCreate): user_in.password = hash_password(user_in.password) user = User(**user_in.dict()) db.add(user) db.commit() db.refresh(user) return user
def create( self, sess: Session, obj: schemas.CustomerCreate ) -> models.Customer: data = obj.dict() data['password'] = hash_password(data['password']) instance = models.Customer(**data) sess.add(instance) sess.commit() sess.refresh(instance) return instance
def create_user(db: Session, user_in: schema.UserCreate): hashed_password = hash_password(user_in.password) db_user = User( first_name=user_in.first_name, last_name=user_in.last_name, email=user_in.email, hashed_password=hashed_password, is_active=user_in.is_active, is_superuser=user_in.is_superuser ) db.add(db_user) db.commit() db.refresh(db_user) return db_user
def edit_user( db: Session, user_id: int, user: schema.UserEdit ) -> schema.User: db_user = get_user(db, user_id) if not db_user: raise HTTPException(status.HTTP_404_NOT_FOUND, detail=Messages.USER_NOT_FOUND) update_data = user.dict(exclude_unset=True) if "password" in update_data: update_data["hashed_password"] = hash_password(user.password) del update_data["password"] for key, value in update_data.items(): setattr(db_user, key, value) db.add(db_user) db.commit() db.refresh(db_user) return db_user