update
This commit is contained in:
parent
e4810961cc
commit
63a1d4d1f0
@ -1,7 +1,80 @@
|
||||
async def sync_cn_ai_user(userid=None, orgid=None, username=None, name=None, email=None):
|
||||
import aiohttp
|
||||
# 目标URL
|
||||
url = "https://ai.atvoe.com/rbac/usersync"
|
||||
# url = 'https://ai.atvoe.com/tmp/env.dspy'
|
||||
|
||||
# 请求头
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + "2i68AZ81di_q5f8AySDrJ"
|
||||
}
|
||||
|
||||
# 请求体数据
|
||||
payload = {
|
||||
"action": "single",
|
||||
"dappid": "cndemo",
|
||||
"user": {
|
||||
"id": userid,
|
||||
"orgid": orgid,
|
||||
"username": username,
|
||||
"name": name,
|
||||
"email": email
|
||||
}
|
||||
}
|
||||
|
||||
try:
|
||||
# 创建一个异步会话
|
||||
result_sysnc = None
|
||||
async with aiohttp.ClientSession() as session:
|
||||
# 发送POST请求
|
||||
async with session.post(url, headers=headers, data=json.dumps(payload)) as response:
|
||||
# 打印响应状态码
|
||||
print(f"状态码: {response.status}")
|
||||
result_sysnc = await response.json()
|
||||
|
||||
if not result_sysnc.get('status') == 'success':
|
||||
print(f"同步用户失败")
|
||||
return {
|
||||
'status': False
|
||||
}
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
# user_api_keys表格 userid/opc_apikey
|
||||
# 首先判断apikey是否存在
|
||||
apikey = result_sysnc['data'][0].get('apikey')
|
||||
records = await sor.R('user_api_keys', {'opc_apikey': apikey})
|
||||
if records:
|
||||
print(f"用户{payload['user']['id']}已存在")
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '用户opc_apikey已存在'
|
||||
}
|
||||
await sor.C('user_api_keys', {
|
||||
'userid': userid,
|
||||
'opc_apikey': apikey,
|
||||
'expire_time': None,
|
||||
})
|
||||
|
||||
return {
|
||||
'status': True,
|
||||
'msg': '用户同步成功'
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"同步用户失败: {e}")
|
||||
return {
|
||||
'status': False,
|
||||
'msg': f"同步用户失败: {e}"
|
||||
}
|
||||
|
||||
|
||||
async def registerUser(ns):
|
||||
"""
|
||||
用户注册
|
||||
"""
|
||||
import re
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
if ns:
|
||||
@ -176,6 +249,10 @@ async def registerUser(ns):
|
||||
ns['customerid'] = org_id
|
||||
await sor.C('customer', ns)
|
||||
await openCustomerAccounts(sor, org[0]['id'], org_id)
|
||||
|
||||
# 同步用户
|
||||
await sync_cn_ai_user(userid=userid, orgid=ns_org['id'], username=ns['username'], name=ns['username'])
|
||||
|
||||
return {'status': True, 'msg': '注册成功'}
|
||||
except Exception as error:
|
||||
# raise error
|
||||
|
||||
@ -660,7 +660,7 @@ async def get_firstpage_product_tree(ns={}):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
if ns.get('url_link') and ('kaiyuancloud' in ns.get('url_link') or 'opencomputing' in ns.get('url_link')):
|
||||
if ns.get('url_link') and ('kaiyuancloud' in ns.get('url_link') or 'opencomputing' in ns.get('url_link') or 'ncmatch' in ns.get('url_link')):
|
||||
data_baidu = {
|
||||
"id": "12",
|
||||
"secTitle": "阿里云",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user