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.mzph.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…