当前位置: 首页 > news >正文

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 后端增加注册接口

好烦啊-- &#xff1a;< 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 界面是现代前端开发人员的基本技能。幸运的是&#xff0c;借助 React 和 Bootstrap 等工具的出现&#xff0c;制作这些 UI 变得…...

深度学习之基于Pytorch照片图像转漫画风格网络系统

欢迎大家点赞、收藏、关注、评论啦 &#xff0c;由于篇幅有限&#xff0c;只展示了部分核心代码。 文章目录 一项目简介 二、功能三、系统四. 总结 一项目简介 以下是一个基本的设计介绍&#xff1a; 数据准备&#xff1a;收集足够的真实照片和漫画图像&#xff0c;用于训练模…...

解决No Feign Client for loadBalancing defined,修改Maven依赖

Spring微服务报错&#xff1a; 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:零代码自动深度学习训练平台

来源&#xff1a;友思特 智能感知 友思特分享 | Neuro-T&#xff1a;零代码自动深度学习训练平台 欢迎关注虹科&#xff0c;为您提供最新资讯&#xff01; 工业自动化、智能化浪潮涌进&#xff0c;视觉技术在其中扮演了至关重要的角色。在汽车、制造业、医药、芯片、食品等行业…...

基于动量的梯度下降

丹尼尔林肯 (Daniel Lincoln)在Unsplash上拍摄的照片 一、说明 基于动量的梯度下降是一种梯度下降优化算法变体&#xff0c;它在更新规则中添加了动量项。动量项计算为过去梯度的移动平均值&#xff0c;过去梯度的权重由称为 Beta 的超参数控制。 这有助于解决与普通梯度下降相…...

ELK+kafka+filebeat企业内部日志分析系统

1、组件介绍 1、Elasticsearch&#xff1a; 是一个基于Lucene的搜索服务器。提供搜集、分析、存储数据三大功能。它提供了一个分布式多用户能力的全文搜索引擎&#xff0c;基于RESTful web接口。Elasticsearch是用Java开发的&#xff0c;并作为Apache许可条款下的开放源码发布…...

MyBatis-Plus: 简化你的MyBatis应用

MyBatis-Plus: 简化你的MyBatis应用 在Java开发中&#xff0c;MyBatis一直是一个受欢迎的持久层框架&#xff0c;提供了灵活的数据访问方式。然而&#xff0c;MyBatis的使用往往涉及许多样板代码&#xff0c;这在一定程度上增加了开发的复杂性。这里&#xff0c;MyBatis-Plus&…...

在 go 的项目中使用验证器

1&#xff1a;使用validate 包验证&#xff1a; 安装包&#xff1a; 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基本一样&#xff0c;区别在于post的Runnable会被赋值给Message的callback&#xff0c;在最后调用dispatchMessage的时候&#xff0c;callback会被触发执行。 1.sendMessage 调用sendMessageDelayed发送消息 public class Handler {public final boolean s…...

java中 自动装箱与拆箱,基本数据类型,java堆与栈,面向对象与面向过程

文章目录 自动装箱与拆箱基本数据类型与包装类的区别&#xff08;int 和 Integer 有什么区别&#xff09;应用场景的区别&#xff1a; 堆和栈的区别重点来说一下堆和栈&#xff1a;那么堆和栈是怎么联系起来的呢? 堆与栈的区别 很明显&#xff1a;延伸&#xff1a;关于Integer…...

C语言第二十八弹--输入一个非负整数,返回组成它的数字之和

C语言求输入一个非负整数&#xff0c;返回组成它的数字之和 方法一、递归法 思路&#xff1a;设计一个初始条件&#xff0c;通过递归获取非负整数的个位&#xff0c;不断接近递归条件即可。 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h>int DigitSum(int n) {…...

redis---主从复制及哨兵模式(高可用)

主从复制 主从复制&#xff1a;主从复制是redis实现高可用的基础&#xff0c;哨兵模式和集群都是在主从复制的基础之上实现高可用。 主从负责的工作原理 1、主节点&#xff08;master&#xff09; 从节点&#xff08;slave&#xff09;组成&#xff0c;数据复制是单向的&a…...

【不同请求方式在springboot中对应的注解】

GET 请求方法&#xff1a;用于获取资源。使用 GetMapping 注解来处理 GET 请求。 示例代码&#xff1a; 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

文章目录 前言一、平台二、代码总结 前言 我的博客里也有其他方法&#xff0c;测试了下感觉这个方法还是比较实用。 一、平台 先仔细阅读下平台的使用方法。 平台地址请点击 二、代码 import requests text 孪生网络模型已经训练完成&#xff0c;请注意查阅相关信息。 req…...

【Spring篇】JDK动态代理

目录 什么是代理&#xff1f; 代理模式 动态代理 Java中常用的代理模式 问题来了&#xff0c;如何动态生成代理类&#xff1f; 动态代理底层实现 什么是代理&#xff1f; 顾名思义&#xff0c;代替某个对象去处理一些问题&#xff0c;谓之代理&#xff0c;那么何为动态&a…...

【从零开始实现意图识别】中文对话意图识别详解

前言 意图识别&#xff08;Intent Recognition&#xff09;是自然语言处理&#xff08;NLP&#xff09;中的一个重要任务&#xff0c;它旨在确定用户输入的语句中所表达的意图或目的。简单来说&#xff0c;意图识别就是对用户的话语进行语义理解&#xff0c;以便更好地回答用户…...

腾讯云点播小程序端上传 SDK

云点播是专门应对上传大视频文件的。 腾讯云点播文档&#xff1a;https://cloud.tencent.com/document/product/266/18177 这个文档比较简单&#xff0c;实在不行&#xff0c;把demo下载下来&#xff0c;一看就明白了&#xff0c;然后再揉一下挪到自己的项目里。完事。 getSign…...

【MATLAB源码-第88期】基于matlab的灰狼优化算法(GWO)的栅格路径规划,输出做短路径图和适应度曲线

操作环境&#xff1a; MATLAB 2022a 1、算法描述 灰狼优化算法&#xff08;Grey Wolf Optimizer, GWO&#xff09;是一种模仿灰狼捕食行为的优化算法。灰狼是群居动物&#xff0c;有着严格的社会等级结构。在灰狼群体中&#xff0c;通常有三个等级&#xff1a;首领&#xff…...

别再只盯着西门子三菱了!盘点那些好用不贵的国产HMI触摸屏品牌(附选型指南)

国产HMI触摸屏品牌深度评测与选型指南&#xff1a;如何用30%预算实现80%进口品牌功能 在工业自动化领域&#xff0c;人机界面(HMI)作为连接操作人员与设备的"神经中枢"&#xff0c;其重要性不言而喻。过去十年间&#xff0c;国内HMI市场格局已发生翻天覆地的变化——…...

从GPS定位到机器人导航:一文讲透ROS中坐标系转换(WGS-84/UTM/ENU)的底层逻辑与实战

从GPS定位到机器人导航&#xff1a;一文讲透ROS中坐标系转换&#xff08;WGS-84/UTM/ENU&#xff09;的底层逻辑与实战 当你在机器人项目中第一次看到GPS数据在ROS中飘忽不定时&#xff0c;是否曾困惑于如何将这些经纬度数字变成机器人能理解的导航指令&#xff1f;坐标系转换就…...

如何用MAA智能辅助工具5分钟解放双手?明日方舟玩家的效率革命指南

如何用MAA智能辅助工具5分钟解放双手&#xff1f;明日方舟玩家的效率革命指南 【免费下载链接】MaaAssistantArknights 《明日方舟》小助手&#xff0c;全日常一键长草&#xff01;| A one-click tool for the daily tasks of Arknights, supporting all clients. 项目地址: …...

从RoboMaster A板拆解到自制飞控:MPU6500硬件电路设计与避坑全指南

MPU6500硬件设计实战&#xff1a;从电源管理到九轴融合的工程细节 拆开手边的RoboMaster A板&#xff0c;那颗3x3mm的MPU6500芯片周围密布着0402封装的去耦电容——这个场景完美诠释了现代运动传感器设计的核心矛盾&#xff1a;如何在极致紧凑的空间内实现可靠的信号完整性&…...

Path of Building 终极指南:三步掌握流放之路离线构筑模拟器

Path of Building 终极指南&#xff1a;三步掌握流放之路离线构筑模拟器 【免费下载链接】PathOfBuilding Offline build planner for Path of Exile. 项目地址: https://gitcode.com/gh_mirrors/pat/PathOfBuilding Path of Building是一款专为《流放之路》玩家设计的免…...

从AM到VSB:揭秘模拟调制技术的演进与实战解调

1. 模拟调制技术的前世今生&#xff1a;从AM到VSB的进化之路 记得我第一次接触无线电广播时&#xff0c;就被那个能"凭空"传递声音的小盒子迷住了。后来才知道&#xff0c;这背后藏着模拟调制技术的精妙设计。AM&#xff08;调幅&#xff09;就像是最早的"声音快…...

C#中+=的双重用途详解

是 C# 中的一个复合赋值运算符&#xff0c;其核心含义是“先相加&#xff0c;再赋值”。它并非单一功能&#xff0c;而是根据其应用的上下文&#xff08;操作数类型&#xff09;表现出两种主要行为&#xff1a;作为数值计算的简化运算符和作为事件订阅的注册运算符。 为了清晰…...

联邦学习在勒索软件检测中的隐私保护应用

1. 联邦学习与勒索软件检测的隐私保护应用概述勒索软件已成为当今网络安全领域最具破坏性的威胁之一。这类恶意软件通过加密受害者文件或锁定系统访问权限&#xff0c;要求支付赎金才能恢复数据。根据统计&#xff0c;全球每年因勒索软件造成的经济损失高达数千亿美元。传统检测…...

反深度学习运动观察:软件测试从业者的专业审视

浪潮下的回响在当今软件工程领域&#xff0c;深度学习&#xff08;Deep Learning&#xff09;以其强大的数据驱动能力和在某些任务上的卓越表现&#xff0c;正以前所未有的速度渗透到包括软件测试在内的各个环节。从自动化测试脚本生成、缺陷预测到用户界面&#xff08;UI&…...

ComfyUI ControlNet Aux预处理器终极配置指南:5步快速解决安装与运行问题

ComfyUI ControlNet Aux预处理器终极配置指南&#xff1a;5步快速解决安装与运行问题 【免费下载链接】comfyui_controlnet_aux ComfyUIs ControlNet Auxiliary Preprocessors 项目地址: https://gitcode.com/gh_mirrors/co/comfyui_controlnet_aux ControlNet Aux预处理…...