superset 后端增加注冊接口

好煩啊-- :<

1.先定義modes:

superset\superset\models\user.py

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.from flask_appbuilder.security.sqla.models import User
from sqlalchemy import String, Column, Boolean
from typing import Union
from superset import dbdef id_or_slug_filter(models_name, id_or_slug):if isinstance(id_or_slug, int):return models_name.id == id_or_slugif id_or_slug.isdigit():return models_name.id == int(id_or_slug)return models_name.slug == id_or_slugclass UserV2(User):__tablename__ = "ab_user"@classmethoddef get(cls, id_or_slug: Union[str, int]):query = db.session.query(UserV2).filter(id_or_slug_filter(UserV2, id_or_slug))return query.one_or_none()@classmethoddef get_user_by_cn_name(cls, cn_name: Union[str]):query = db.session.query(UserV2).filter(UserV2.username == cn_name)return query.one_or_none()@classmethoddef get_model_by_username(cls, username: Union[str]):query = db.session.query(UserV2).filter(UserV2.username == username)return query.one_or_none()def as_dict(self):return {c.name: getattr(self, c.name) for c in self.__table__.columns}def __repr__(self):return self.username

2.新增注冊接口接口

superset\superset\views\users\api.py

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT     OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from flask import g, Response, request
from flask_appbuilder.api import expose, safe, BaseApi
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.security.sqla.models import User
from flask_jwt_extended.exceptions import NoAuthorizationErrorfrom superset import appbuilder
from superset.models.user import UserV2
from superset.views.base_api import BaseSupersetApi
from superset.views.users.schemas import UserResponseSchema
from superset.views.utils import bootstrap_user_datauser_response_schema = UserResponseSchema()class CurrentUserRestApi(BaseSupersetApi):"""An API to get information about the current user"""resource_name = "me"openapi_spec_tag = "Current User"openapi_spec_component_schemas = (UserResponseSchema,)@expose("/", methods=("GET",))@safedef get_me(self) -> Response:"""Get the user object corresponding to the agent making the request.---get:summary: Get the user objectdescription: >-Gets the user object corresponding to the agent making the request,or returns a 401 error if the user is unauthenticated.responses:200:description: The current usercontent:application/json:schema:type: objectproperties:result:$ref: '#/components/schemas/UserResponseSchema'401:$ref: '#/components/responses/401'"""try:if g.user is None or g.user.is_anonymous:return self.response_401()except NoAuthorizationError:return self.response_401()return self.response(200, result=user_response_schema.dump(g.user))@expose("/roles/", methods=("GET",))@safedef get_my_roles(self) -> Response:"""Get the user roles corresponding to the agent making the request.---get:summary: Get the user rolesdescription: >-Gets the user roles corresponding to the agent making the request,or returns a 401 error if the user is unauthenticated.responses:200:description: The current usercontent:application/json:schema:type: objectproperties:result:$ref: '#/components/schemas/UserResponseSchema'401:$ref: '#/components/responses/401'"""try:if g.user is None or g.user.is_anonymous:return self.response_401()except NoAuthorizationError:return self.response_401()user = bootstrap_user_data(g.user, include_perms=True)return self.response(200, result=user)class UserRestApi(BaseApi):"""繼承Flask-appbuilder原生用戶視圖類, 擴展用戶操作的接口類"""route_base = "/api/v1/users"datamodel = SQLAInterface(UserV2)include_route_methods = {"register"}@expose("/register/", methods=("POST",))@safedef register(self) -> Response:"""Get the user roles corresponding to the agent making the request.---get:summary: Get the user rolesdescription: >-Gets the user roles corresponding to the agent making the request,or returns a 401 error if the user is unauthenticated.responses:200:description: The current usercontent:application/json:schema:type: objectproperties:result:$ref: '#/components/schemas/UserResponseSchema'401:$ref: '#/components/responses/401'"""try:data = request.get_json()username = data.get("username")user_models = UserV2.get_model_by_username(username)if username and not user_models:result = appbuilder.sm.add_user(username,data.get("first_name"),data.get("last_name"),data.get("email"),appbuilder.sm.find_role(data.get("role")),data.get("password"),)if result:return self.response(200, result={"status": "Success","message": "ok",})else:return self.response_401()else:return self.response_401()except NoAuthorizationError:return self.response_401()

3. 增加api導入

superset\superset\initialization_init_.py

		...from superset.views.users.api import UserRestApi...appbuilder.add_api(UserRestApi)

在這里插入圖片描述

4. postman 測試:

參數:

{"username": "1213","first_name": "122","last_name":"last_name","email":"email@qq.com","role":"admin","password":"sasadasd121324rd"
}

在這里插入圖片描述
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/167986.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/167986.shtml
英文地址,請注明出處:http://en.pswp.cn/news/167986.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Tars框架 Tars-Go 學習

Tars 框架安裝 網上安裝教程比較多&#xff0c;官方可以參數這個 TARS官方文檔 (tarsyun.com) 本文主要介紹部署應用。 安裝完成后Tars 界面 增加應用amc 部署申請 amc.GoTestServer.GoTestObj 名稱不知道的可以參考自己創建的app config 點擊刷新可以看到自己部署的應用 服…

獲取當日的日期三個月后的日期

使用 java.time.LocalDate 類進行計算 import java.time.LocalDate;public class ThreeMonthsLaterExample {public static void main(String[] args) {// 獲取當前日期LocalDate currentDate LocalDate.now();// 添加三個月LocalDate threeMonthsLater currentDate.plusMont…

【阿里云服務器】2023安裝寶塔面板8.0.4

文章目錄 前言安裝寶塔遠程鏈接服務器輸入安裝寶塔命令放行寶塔端口 一鍵安裝環境附錄重裝系統Linux系統卸載寶塔方式一方式二 遇見的問題 前言 鏡像是CentOS 7.9.4 安裝寶塔 遠程鏈接服務器 輸入安裝寶塔命令 yum install -y wget && wget -O install.sh https://…

Android 13.0 系統settings系統屬性控制一級菜單顯示隱藏

1.概述 在13.0的系統rom定制化開發中,系統settings的一級菜單有些在客戶需求中需要去掉不顯示,所以就需要通過系統屬性來控制顯示隱藏, 從而達到控制一級菜單的顯示的目的,而系統settings是通過靜態加載的方式負責顯示隱藏,接下來就來實現隱藏顯示一級菜單的 功能實現 2.…

2023年亞太杯數學建模A題水果采摘機器人的圖像識別功能(基于yolov5的蘋果分割)

注&#xff1a;.題中附錄并沒有給出蘋果的標簽集&#xff0c;所以需要我們自己通過前4問得到訓練的標簽集&#xff0c;采用的是yolov5 7.0 版本&#xff0c;該版本帶分割功能 一&#xff1a;關于數據集的制作&#xff1a; clc; close all; clear; %-----這個是生成yolov5 數據…

任務4-繪制圖形

python字典的使用方法 !echo $(date)‘開始下載并解壓’ && curl -o Task4.zip https://zyenv-1302342904.cos.ap-guangzhou.myqcloud.com/datas/TianJin/Task4_TJ_ZZ.zip && unzip -o Task4.zip > /dev/null 2>&1 && echo $(date)‘解壓完…

學習課題:逐步構建開發播放器【QT5 + FFmpeg6 + SDL2】

目錄 一、播放器開發(一)&#xff1a;播放器組成大致結構與代碼流程設計 二、播放器開發(二)&#xff1a;了解FFmpeg與SDL常用對象和函數 三、播放器開發(三)&#xff1a;FFmpeg與SDL環境配置 四、播放器開發(四)&#xff1a;多線程解復用與解碼模塊實現 五、播放器開發(五…

Linux應用開發基礎知識——I2C應用編程(十三)

一、無需編寫驅動程序即可訪問 I2C 設備 APP 訪問硬件肯定是需要驅動程序的&#xff0c;對于 I2C 設備&#xff0c;內核提供了驅動程序 drivers/i2c/i2c-dev.c&#xff0c;通過它可以直接使用下面的 I2C 控制器驅動程序來訪問 I2C 設備。 i2c-tools 是一套好用的工具&#xff0…

虛擬機系列:Oracle VM VirtualBox虛擬機的使用教程和使用體驗情況反饋

Oracle VM VirtualBox虛擬機的使用教程和使用體驗情況反饋 一. 簡述:二. 下載三. 安裝解壓后選擇需要的版本點擊安裝1:第一步,點擊安裝,點擊下一步2. 這里直接點擊下一步,3. 網絡警告選擇:是4. 準備好以后,點擊安裝5. 點擊完成即可四. 打開五. 創建虛擬機1. 輸入虛擬機名…

H5(uniapp)中使用echarts

1,安裝echarts npm install echarts 2&#xff0c;具體頁面 <template><view class"container notice-list"><view><view class"aa" id"main" style"width: 500px; height: 400px;"></view></v…

MySQL 中的 JSON_CONTAINS 函數詳解

在處理 MySQL 中的 JSON 數據時&#xff0c;我們經常需要檢查一個 JSON 文檔是否包含特定的值。這時&#xff0c;JSON_CONTAINS 函數就顯得非常有用。 JSON_CONTAINS函數介紹 JSON_CONTAINS 是 MySQL 提供的一個 JSON 函數&#xff0c;用于測試一個 JSON 文檔是否包含特定的值…

SQLite 和 SQLiteDatabase 的使用

實驗七&#xff1a;SQLite 和 SQLiteDatabase 的使用 7.1 實驗目的 本次實驗的目的是讓大家熟悉 Android 中對數據庫進行操作的相關的接口、類等。SQLiteDatabase 這個是在 android 中數據庫操作使用最頻繁的一個類。通過它可以實現數據庫的創建或打開、創建表、插入數據、刪…

22、什么是中間件和權限攔截中間件實操

新建中間件 middleware\auth.js // 定義權限判斷中間件&#xff0c;中間件的第一個參數是context export default ({store, redirect}) > {console.log("中間件被調用")// if (!store || !store.state.userinfo) {// redirect("/")// } }頁面使用…

CF -- Educational Codeforces Round 158 (Rated for Div. 2) -- D 補題記錄

Yet Another Monster Fight Problem - D - Codeforces 題目大意&#xff1a; 現在給你一堆怪物&#xff0c;你擁有法術&#xff08;一個法術可以連續攻擊這n個所有怪物&#xff09;&#xff0c;你可以選擇任意一個怪物作為法術的第一個攻擊目標&#xff08;傷害為x&#xff…

【MySQL】索引與事務

&#x1f451;專欄內容&#xff1a;MySQL?個人主頁&#xff1a;子夜的星的主頁&#x1f495;座右銘&#xff1a;前路未遠&#xff0c;步履不停 目錄 一、索引1、使用場景2、使用索引創建索引查看索引刪除索引 3、底層數據結構&#xff08;非常重要&#xff09; 二、事務1、概念…

Android設計模式--享元模式

水不激不躍&#xff0c;人不激不奮 一&#xff0c;定義 使用共享對象可有效地支持大量的細粒度的對象 享元模式是對象池的一種實現&#xff0c;用來盡可能減少內存使用量&#xff0c;它適合用于可能存在大量重復對象的場景&#xff0c;來緩存可共享的對象&#xff0c;達到對象…

騰訊云CVM標準型SA5云服務器AMD EPYC Bergamo處理器

騰訊云服務器標準型SA5實例是最新一代的標準型實例&#xff0c;CPU采用AMD EPYC? Bergamo全新處理器&#xff0c;采用最新DDR5內存&#xff0c;默認網絡優化&#xff0c;最高內網收發能力達4500萬pps。騰訊云百科txybk.com分享騰訊云標準型SA5云服務器CPU、內存、網絡、性能、…

Qt項目打包發布超詳細教程

https://blog.csdn.net/qq_45491628/article/details/129091320

用蘋果簽名免費獲取Xcode

使用蘋果企業簽名免費獲取Xcode&#xff1a; 打開Xcode。連接iOS設備到Mac。選擇Window→Devices and Simulators。選擇該設備。將IPA文件拖到“Installed Apps”的列表框中即可安裝。使用Cydia Impactor&#xff08;可以在網上找到相關下載鏈接&#xff09;&#xff1a; 打開…

HTML網站穩定性狀態監控平臺源碼

這是一款網站穩定性狀態監控平臺源碼&#xff0c;它基于UptimeRobot接口進行開發。當您的網站遇到故障時&#xff0c;該平臺能夠通過郵件或短信通知您。下面是對安裝過程的詳細說明&#xff1a; 安裝步驟 將源碼上傳至您的主機或服務器&#xff0c;并進行解壓操作。 在Uptim…