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"
}


相关文章:
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…...
利用 React 和 Bootstrap 进行强大的前端开发
文章目录 介绍React 和 Bootstrap设置环境使用 Bootstrap 创建 React 组件React-Bootstrap 组件结论 介绍 创建响应式、交互式和外观引人入胜的 Web 界面是现代前端开发人员的基本技能。幸运的是,借助 React 和 Bootstrap 等工具的出现,制作这些 UI 变得…...
深度学习之基于Pytorch照片图像转漫画风格网络系统
欢迎大家点赞、收藏、关注、评论啦 ,由于篇幅有限,只展示了部分核心代码。 文章目录 一项目简介 二、功能三、系统四. 总结 一项目简介 以下是一个基本的设计介绍: 数据准备:收集足够的真实照片和漫画图像,用于训练模…...
解决No Feign Client for loadBalancing defined,修改Maven依赖
Spring微服务报错: java.lang.IllegalStateException:FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netf…...
友思特分享 | Neuro-T:零代码自动深度学习训练平台
来源:友思特 智能感知 友思特分享 | Neuro-T:零代码自动深度学习训练平台 欢迎关注虹科,为您提供最新资讯! 工业自动化、智能化浪潮涌进,视觉技术在其中扮演了至关重要的角色。在汽车、制造业、医药、芯片、食品等行业…...
基于动量的梯度下降
丹尼尔林肯 (Daniel Lincoln)在Unsplash上拍摄的照片 一、说明 基于动量的梯度下降是一种梯度下降优化算法变体,它在更新规则中添加了动量项。动量项计算为过去梯度的移动平均值,过去梯度的权重由称为 Beta 的超参数控制。 这有助于解决与普通梯度下降相…...
ELK+kafka+filebeat企业内部日志分析系统
1、组件介绍 1、Elasticsearch: 是一个基于Lucene的搜索服务器。提供搜集、分析、存储数据三大功能。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布…...
MyBatis-Plus: 简化你的MyBatis应用
MyBatis-Plus: 简化你的MyBatis应用 在Java开发中,MyBatis一直是一个受欢迎的持久层框架,提供了灵活的数据访问方式。然而,MyBatis的使用往往涉及许多样板代码,这在一定程度上增加了开发的复杂性。这里,MyBatis-Plus&…...
在 go 的项目中使用验证器
1:使用validate 包验证: 安装包: go get github.com/go-playground/validator/v10 package controllerimport ("fmt""github.com/gin-gonic/gin""github.com/go-playground/validator/v10""net/http&quo…...
Handler系列-sendMessage和post的区别
sendMessage和post基本一样,区别在于post的Runnable会被赋值给Message的callback,在最后调用dispatchMessage的时候,callback会被触发执行。 1.sendMessage 调用sendMessageDelayed发送消息 public class Handler {public final boolean s…...
java中 自动装箱与拆箱,基本数据类型,java堆与栈,面向对象与面向过程
文章目录 自动装箱与拆箱基本数据类型与包装类的区别(int 和 Integer 有什么区别)应用场景的区别: 堆和栈的区别重点来说一下堆和栈:那么堆和栈是怎么联系起来的呢? 堆与栈的区别 很明显:延伸:关于Integer…...
C语言第二十八弹--输入一个非负整数,返回组成它的数字之和
C语言求输入一个非负整数,返回组成它的数字之和 方法一、递归法 思路:设计一个初始条件,通过递归获取非负整数的个位,不断接近递归条件即可。 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h>int DigitSum(int n) {…...
redis---主从复制及哨兵模式(高可用)
主从复制 主从复制:主从复制是redis实现高可用的基础,哨兵模式和集群都是在主从复制的基础之上实现高可用。 主从负责的工作原理 1、主节点(master) 从节点(slave)组成,数据复制是单向的&a…...
【不同请求方式在springboot中对应的注解】
GET 请求方法:用于获取资源。使用 GetMapping 注解来处理 GET 请求。 示例代码: RestController public class MyController {GetMapping("/resource")public ResponseEntity<String> getResource() {// 处理 GET 请求逻辑} }POST 请求方…...
前端入门(三)Vue生命周期、组件技术、事件总线、
文章目录 Vue生命周期Vue 组件化编程 - .vue文件非单文件组件组件的注意点组件嵌套Vue实例对象和VueComponent实例对象Js对象原型与原型链Vue与VueComponent的重要内置关系 应用单文件组件构建 Vue脚手架 - vue.cli项目文件结构refpropsmixin插件scoped样式 Vue生命周期 1、bef…...
消息推送到微信,快速实现WxPusher
文章目录 前言一、平台二、代码总结 前言 我的博客里也有其他方法,测试了下感觉这个方法还是比较实用。 一、平台 先仔细阅读下平台的使用方法。 平台地址请点击 二、代码 import requests text 孪生网络模型已经训练完成,请注意查阅相关信息。 req…...
【Spring篇】JDK动态代理
目录 什么是代理? 代理模式 动态代理 Java中常用的代理模式 问题来了,如何动态生成代理类? 动态代理底层实现 什么是代理? 顾名思义,代替某个对象去处理一些问题,谓之代理,那么何为动态&a…...
【从零开始实现意图识别】中文对话意图识别详解
前言 意图识别(Intent Recognition)是自然语言处理(NLP)中的一个重要任务,它旨在确定用户输入的语句中所表达的意图或目的。简单来说,意图识别就是对用户的话语进行语义理解,以便更好地回答用户…...
腾讯云点播小程序端上传 SDK
云点播是专门应对上传大视频文件的。 腾讯云点播文档:https://cloud.tencent.com/document/product/266/18177 这个文档比较简单,实在不行,把demo下载下来,一看就明白了,然后再揉一下挪到自己的项目里。完事。 getSign…...
【MATLAB源码-第88期】基于matlab的灰狼优化算法(GWO)的栅格路径规划,输出做短路径图和适应度曲线
操作环境: MATLAB 2022a 1、算法描述 灰狼优化算法(Grey Wolf Optimizer, GWO)是一种模仿灰狼捕食行为的优化算法。灰狼是群居动物,有着严格的社会等级结构。在灰狼群体中,通常有三个等级:首领ÿ…...
【杂谈】-递归进化:人工智能的自我改进与监管挑战
递归进化:人工智能的自我改进与监管挑战 文章目录 递归进化:人工智能的自我改进与监管挑战1、自我改进型人工智能的崛起2、人工智能如何挑战人类监管?3、确保人工智能受控的策略4、人类在人工智能发展中的角色5、平衡自主性与控制力6、总结与…...
HTML 列表、表格、表单
1 列表标签 作用:布局内容排列整齐的区域 列表分类:无序列表、有序列表、定义列表。 例如: 1.1 无序列表 标签:ul 嵌套 li,ul是无序列表,li是列表条目。 注意事项: ul 标签里面只能包裹 li…...
MVC 数据库
MVC 数据库 引言 在软件开发领域,Model-View-Controller(MVC)是一种流行的软件架构模式,它将应用程序分为三个核心组件:模型(Model)、视图(View)和控制器(Controller)。这种模式有助于提高代码的可维护性和可扩展性。本文将深入探讨MVC架构与数据库之间的关系,以…...
如何在看板中有效管理突发紧急任务
在看板中有效管理突发紧急任务需要:设立专门的紧急任务通道、重新调整任务优先级、保持适度的WIP(Work-in-Progress)弹性、优化任务处理流程、提高团队应对突发情况的敏捷性。其中,设立专门的紧急任务通道尤为重要,这能…...
ffmpeg(四):滤镜命令
FFmpeg 的滤镜命令是用于音视频处理中的强大工具,可以完成剪裁、缩放、加水印、调色、合成、旋转、模糊、叠加字幕等复杂的操作。其核心语法格式一般如下: ffmpeg -i input.mp4 -vf "滤镜参数" output.mp4或者带音频滤镜: ffmpeg…...
vue3 定时器-定义全局方法 vue+ts
1.创建ts文件 路径:src/utils/timer.ts 完整代码: import { onUnmounted } from vuetype TimerCallback (...args: any[]) > voidexport function useGlobalTimer() {const timers: Map<number, NodeJS.Timeout> new Map()// 创建定时器con…...
ElasticSearch搜索引擎之倒排索引及其底层算法
文章目录 一、搜索引擎1、什么是搜索引擎?2、搜索引擎的分类3、常用的搜索引擎4、搜索引擎的特点二、倒排索引1、简介2、为什么倒排索引不用B+树1.创建时间长,文件大。2.其次,树深,IO次数可怕。3.索引可能会失效。4.精准度差。三. 倒排索引四、算法1、Term Index的算法2、 …...
爬虫基础学习day2
# 爬虫设计领域 工商:企查查、天眼查短视频:抖音、快手、西瓜 ---> 飞瓜电商:京东、淘宝、聚美优品、亚马逊 ---> 分析店铺经营决策标题、排名航空:抓取所有航空公司价格 ---> 去哪儿自媒体:采集自媒体数据进…...
鸿蒙DevEco Studio HarmonyOS 5跑酷小游戏实现指南
1. 项目概述 本跑酷小游戏基于鸿蒙HarmonyOS 5开发,使用DevEco Studio作为开发工具,采用Java语言实现,包含角色控制、障碍物生成和分数计算系统。 2. 项目结构 /src/main/java/com/example/runner/├── MainAbilitySlice.java // 主界…...
初学 pytest 记录
安装 pip install pytest用例可以是函数也可以是类中的方法 def test_func():print()class TestAdd: # def __init__(self): 在 pytest 中不可以使用__init__方法 # self.cc 12345 pytest.mark.api def test_str(self):res add(1, 2)assert res 12def test_int(self):r…...
