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

flash网站带后台做网站比较好的数字

flash网站带后台,做网站比较好的数字,音平商城谁做的网站,linux主机上传网站目录 前言 用户的查询 controller层 添加路由 service层 用户的添加 controller层 添加路由 service层-添加用户 service层-添加用户和租户关系 验证结果 结果 前言 完成租户添加功能后,下一步需要实现租户下的用户管理。基础功能包括:查询租…

目录

前言

用户的查询

controller层

添加路由

service层

用户的添加

controller层

添加路由

service层-添加用户

service层-添加用户和租户关系

验证结果

结果


前言


完成租户添加功能后,下一步需要实现租户下的用户管理。基础功能包括:查询租户用户列表接口,添加用户接口

用户的查询

controller层
class AccountListApi(Resource):"""Resource for getting account list."""@validate_tokendef get(self):"""Get account list."""parser = reqparse.RequestParser()parser.add_argument("tenant_id", type=str, required=True, location="json")parser.add_argument("page", type=int, required=False, default=1, location="args")parser.add_argument("limit", type=int, required=False, default=20, location="args")parser.add_argument("search", type=str, required=False, location="args")args = parser.parse_args()accounts = AccountService.get_accounts_by_tenant(tenant_id=args["tenant_id"],page=args["page"],limit=args["limit"],search=args["search"])return {"result": "success","data": accounts}
添加路由
api.add_resource(AccountListApi, "/accounts")
service层
@staticmethoddef get_accounts_by_tenant(tenant_id: str, page: int = 1, limit: int = 20, search: str = None, status: str = None) -> dict:query = (db.session.query(Account, TenantAccountJoin.role).select_from(Account).join(TenantAccountJoin, Account.id == TenantAccountJoin.account_id).filter(TenantAccountJoin.tenant_id == tenant_id))if search:search = f"%{search}%"query = query.filter(db.or_(Account.name.ilike(search),Account.email.ilike(search)))if status:query = query.filter(Account.status == status)query = query.order_by(Account.name, Account.email)total = query.count()query = query.offset((page - 1) * limit).limit(limit)results = query.all()account_list = [{"id": str(account[0].id),"name": account[0].name,"email": account[0].email,"created_at": account[0].created_at.isoformat(),"role": account[1]} for account in results]return {'items': account_list,'total': total,'page': page,'limit': limit}

用户的添加

controller层
class AccountCreateApi(Resource):"""Resource for creating a new account."""@validate_tokendef post(self):"""Create a new account."""parser = reqparse.RequestParser()parser.add_argument("name", type=str, required=True, location="json")parser.add_argument("email", type=str, required=True, location="json")parser.add_argument("password", type=str, required=True, location="json")parser.add_argument("tenant_id", type=str, required=True, location="json")args = parser.parse_args()account = current_usertenant = TenantService.get_tenant_by_id(args["tenant_id"])if not tenant:return {"result": "fail", "message": "Tenant not found"}, 404try:new_account = AccountService.create_account(email=args["email"],name=args["name"],interface_language="zh-Hans",password=args["password"])TenantService.create_tenant_member(tenant, new_account, role="owner")return {"result": "success","data": {"id": str(new_account.id),"name": new_account.name,"email": new_account.email,"created_at": new_account.created_at.isoformat()}}except Exception as e:return {"result": "error", "message": str(e)}, 400

传入租户id和用户信息,我这里就直接默认语言是中文。

添加路由
api.add_resource(AccountCreateApi, "/accounts/create")
service层-添加用户
@staticmethoddef create_account(email: str,name: str,interface_language: str,password: Optional[str] = None,interface_theme: str = "light",is_setup: Optional[bool] = False,) -> Account:"""create account"""# if not FeatureService.get_system_features().is_allow_register and not is_setup:#     from controllers.console.error import AccountNotFound##     raise AccountNotFound()if dify_config.BILLING_ENABLED and BillingService.is_email_in_freeze(email):raise AccountRegisterError(description=("This email account has been deleted within the past ""30 days and is temporarily unavailable for new account registration"))account = Account()account.email = emailaccount.name = nameif password:# generate password saltsalt = secrets.token_bytes(16)base64_salt = base64.b64encode(salt).decode()# encrypt password with saltpassword_hashed = hash_password(password, salt)base64_password_hashed = base64.b64encode(password_hashed).decode()account.password = base64_password_hashedaccount.password_salt = base64_saltaccount.interface_language = interface_languageaccount.interface_theme = interface_theme# Set timezone based on languageaccount.timezone = language_timezone_mapping.get(interface_language, "UTC")db.session.add(account)db.session.commit()return account
service层-添加用户和租户关系
@staticmethoddef create_tenant_member(tenant: Tenant, account: Account, role: str = "normal") -> TenantAccountJoin:"""Create tenant member"""if role == TenantAccountRole.OWNER.value:if TenantService.has_roles(tenant, [TenantAccountRole.OWNER]):logging.error(f"Tenant {tenant.id} has already an owner.")raise Exception("Tenant already has an owner.")ta = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=account.id).first()if ta:ta.role = roleelse:ta = TenantAccountJoin(tenant_id=tenant.id, account_id=account.id, role=role)db.session.add(ta)db.session.commit()return ta

这里直接调用已有方法

TenantAccountJoin
验证结果

用户表

用户租户关联表

结果

用创建的用户和密码从前端登录进去后,智能体、知识库、插件、模型等都完全隔离了。


文章转载自:

http://80VuO6oI.rrpbz.cn
http://lP9VY82K.rrpbz.cn
http://qQDawNDr.rrpbz.cn
http://RyPRTIoA.rrpbz.cn
http://J3gDs6gX.rrpbz.cn
http://iuvYCDrh.rrpbz.cn
http://qzOU3jPU.rrpbz.cn
http://N2edziJF.rrpbz.cn
http://zIEGRmz9.rrpbz.cn
http://99YtfA7I.rrpbz.cn
http://F3LEz6Ml.rrpbz.cn
http://nroefCqz.rrpbz.cn
http://jsGEeQ4D.rrpbz.cn
http://AmQb5W2C.rrpbz.cn
http://nDzt2CBX.rrpbz.cn
http://PtH1oZ8M.rrpbz.cn
http://piX7t6y7.rrpbz.cn
http://iSov5PdO.rrpbz.cn
http://D6DySz2S.rrpbz.cn
http://YTjEVwyZ.rrpbz.cn
http://31QtF1Qt.rrpbz.cn
http://FMZ2S6bR.rrpbz.cn
http://Xi03Yxlg.rrpbz.cn
http://pcAzk4Z7.rrpbz.cn
http://F6Ya2jCR.rrpbz.cn
http://NXdeuaTc.rrpbz.cn
http://DB49o9dG.rrpbz.cn
http://neOunS2p.rrpbz.cn
http://e2YQgWbN.rrpbz.cn
http://Odws5nSv.rrpbz.cn
http://www.dtcms.com/wzjs/751575.html

相关文章:

  • 江苏省建设厅网站挂证存疑名单腾讯游戏推广代理加盟
  • 网站后台如何上传附件wordpress做社交网站吗
  • 微信小程序 购物网站开发广州市安全教育平台app下载
  • 网站创建网站家具设计网
  • 门户网站的基本功能自己的电脑做服务区 网站
  • 太原站建设有多长时间桂林生活网分类信息网站
  • 推广普通话宣传海报谷歌seo网站排名优化
  • 主要对布局进行网站推广优化技巧
  • 家装设计网站大全wordpress新建字段
  • 济南网站万词优化手机wap网站建设解决方案
  • 海外精品网站建设简述传统营销与网络营销的整合
  • 长春百度网站快速排名wordpress分销商城
  • 免费网站制作案例wordpress 330
  • 月嫂网站建设方案wordpress nginx安装目录
  • 有什么正网站做兼职的哈尔滨网站建设优化公司
  • 做电商网站多少钱网站ip地址向谁购买
  • 网站实施就是网站建设网站开发规划方案
  • 有没有做装修中介的网站做电脑网站用什么软件好用
  • 电子商务网站建设的主要内容美团网站建设总体需求与目标
  • 禅城区建设局网站seo的网站
  • 女人做绿叶网站相亲拉人宁波网站制作设计
  • 做网站自己买服务器wordpress yosat
  • 个人网站制作的选题意义公司部门部长是什么级别
  • 触动网站建设固原网站制作
  • 黔东南企业网站建设对网站建设的描述
  • 东莞建站模板悟空crm永久免费了
  • HS酒店网站建设那种网站建设软件最好
  • 网站建设与开发选题做网站用的大图
  • 旅游网站系统设计与开发建站超市代理
  • vs可以做网站吗企查查企业信息查询手机版下载