def create_user(income_id=Depends(Auth.wrapper), *, db: Session = Depends(db_session), new_user: UserRequestSchema) -> Any: AuthService.validate_admin_access(db, id=income_id) UsersService.validate_username(db, username=new_user.username) UsersService.validate_email(db, email=new_user.email) # UsersService.validate_student( new_user ) created_user = UsersService.create_user(db, object=new_user) return created_user
def update_user(income_id=Depends(Auth.wrapper), *, db: Session = Depends(db_session), new_infos: Union[UserUpdateSchema, Dict[str, Union[str, StatusOptions]]], id: str = id) -> Any: AuthService.validate_admin_or_current_access(db, income_id=income_id, action_id=id) current_user = UsersService.validate_id(db, id=id) updated_user = UsersService.update_user( db, db_object=current_user["db_object"], infos_object=new_infos) return updated_user
def remove_user(income_id=Depends(Auth.wrapper), *, db: Session = Depends(db_session), id: str = id): AuthService.validate_admin_access(db, id=income_id) removed_user = UsersService.remove_user(db, id=id) return removed_user
def list_user(income_id=Depends(Auth.wrapper), *, db: Session = Depends(db_session), id: str = id) -> Any: user = UsersService.validate_id(db, id=id) return user["response"]
def login(payload: AuthRequestSchema, *, db: Session = Depends(db_session)) -> Any: identity, password = dict(payload).values( ) # Desestruturando (Unpacking) os valores do Request Body payload user = UsersService.get_user(db, identity=identity) AuthService.validate_access(user, password) token = AuthService.get_token(user.id) return {'token': token, 'entity': user.entity}
def list_users(income_id=Depends(Auth.wrapper), *, db: Session = Depends(db_session), id: str = id) -> Any: users_list = UsersService.create_users_topic_list(db, id=id) return users_list
def list_users( income_id=Depends(Auth.wrapper), *, db: Session = Depends(db_session) ) -> Any: users_list = UsersService.create_users_list(db) return users_list
def validate_token(payload: TokenSchema, *, db: Session = Depends(db_session)) -> Any: user_id = AuthService.validate_token(payload.token) user = UsersService.get_user(db, identity=user_id) return {'entity': user.entity}