def create(self, db: Session, user: UserRegiser) -> User: if self.does_user_exists_with_email(db, user.email): raise HTTPException(status.HTTP_400_BAD_REQUEST, detail="User Already Exists with email") if self.does_user_exists_with_username(db, user.username): raise HTTPException(status.HTTP_400_BAD_REQUEST, detail="User Already Exists with username") db_user = User(email=user.email, username=user.username) db_user.set_password(user.password) db.add(db_user) db.commit() db.refresh(db_user) return db_user
def create_user(db: Session, user: UserCreate): hashed_password = get_password_hash(user.password) db_user = User( first_name=user.first_name, last_name=user.last_name, email=user.email, is_active=user.is_active, is_ops=user.is_ops, is_superuser=user.is_superuser, hashed_password=hashed_password, ) db.add(db_user) db.commit() db.refresh(db_user) return get_user(db, db_user.id)
def delete_forward_rule( db: Session, server_id: int, port_id: int, user: User = None ) -> t.Tuple[PortForwardRule, Port]: db_forward_rule = get_forward_rule(db, server_id, port_id) if not db_forward_rule: raise HTTPException( status_code=404, detail="Port forward rule not found" ) if user is not None and not user.is_admin() and not any( user.id == u.user_id for u in db_forward_rule.port.allowed_users ): raise HTTPException( status_code=403, detail="User not allowed to delete this port forward rule", ) port = db_forward_rule.port db.delete(db_forward_rule) db.commit() return db_forward_rule, port
async def getUser(self, user): if user: return User(**user) else: return False