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)是一种模仿灰狼捕食行为的优化算法。灰狼是群居动物,有着严格的社会等级结构。在灰狼群体中,通常有三个等级:首领ÿ…...
Python爬虫实战:研究MechanicalSoup库相关技术
一、MechanicalSoup 库概述 1.1 库简介 MechanicalSoup 是一个 Python 库,专为自动化交互网站而设计。它结合了 requests 的 HTTP 请求能力和 BeautifulSoup 的 HTML 解析能力,提供了直观的 API,让我们可以像人类用户一样浏览网页、填写表单和提交请求。 1.2 主要功能特点…...
观成科技:隐蔽隧道工具Ligolo-ng加密流量分析
1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具,该工具基于TUN接口实现其功能,利用反向TCP/TLS连接建立一条隐蔽的通信信道,支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式,适应复杂网…...
2024年赣州旅游投资集团社会招聘笔试真
2024年赣州旅游投资集团社会招聘笔试真 题 ( 满 分 1 0 0 分 时 间 1 2 0 分 钟 ) 一、单选题(每题只有一个正确答案,答错、不答或多答均不得分) 1.纪要的特点不包括()。 A.概括重点 B.指导传达 C. 客观纪实 D.有言必录 【答案】: D 2.1864年,()预言了电磁波的存在,并指出…...
学校招生小程序源码介绍
基于ThinkPHPFastAdminUniApp开发的学校招生小程序源码,专为学校招生场景量身打造,功能实用且操作便捷。 从技术架构来看,ThinkPHP提供稳定可靠的后台服务,FastAdmin加速开发流程,UniApp则保障小程序在多端有良好的兼…...
IT供电系统绝缘监测及故障定位解决方案
随着新能源的快速发展,光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域,IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选,但在长期运行中,例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...
【论文阅读28】-CNN-BiLSTM-Attention-(2024)
本文把滑坡位移序列拆开、筛优质因子,再用 CNN-BiLSTM-Attention 来动态预测每个子序列,最后重构出总位移,预测效果超越传统模型。 文章目录 1 引言2 方法2.1 位移时间序列加性模型2.2 变分模态分解 (VMD) 具体步骤2.3.1 样本熵(S…...
C++.OpenGL (20/64)混合(Blending)
混合(Blending) 透明效果核心原理 #mermaid-svg-SWG0UzVfJms7Sm3e {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-SWG0UzVfJms7Sm3e .error-icon{fill:#552222;}#mermaid-svg-SWG0UzVfJms7Sm3e .error-text{fill…...
C#学习第29天:表达式树(Expression Trees)
目录 什么是表达式树? 核心概念 1.表达式树的构建 2. 表达式树与Lambda表达式 3.解析和访问表达式树 4.动态条件查询 表达式树的优势 1.动态构建查询 2.LINQ 提供程序支持: 3.性能优化 4.元数据处理 5.代码转换和重写 适用场景 代码复杂性…...
NPOI Excel用OLE对象的形式插入文件附件以及插入图片
static void Main(string[] args) {XlsWithObjData();Console.WriteLine("输出完成"); }static void XlsWithObjData() {// 创建工作簿和单元格,只有HSSFWorkbook,XSSFWorkbook不可以HSSFWorkbook workbook new HSSFWorkbook();HSSFSheet sheet (HSSFSheet)workboo…...
4. TypeScript 类型推断与类型组合
一、类型推断 (一) 什么是类型推断 TypeScript 的类型推断会根据变量、函数返回值、对象和数组的赋值和使用方式,自动确定它们的类型。 这一特性减少了显式类型注解的需要,在保持类型安全的同时简化了代码。通过分析上下文和初始值,TypeSc…...
