Merge branch 'main' of https://git.opencomputing.cn/yumoqing/kboss
This commit is contained in:
commit
0acedc3543
@ -4,7 +4,7 @@ async def jiajie_get_token_redirect(ns={}):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# target_host = 'https://testing.vstecscloud.shop'
|
# target_host = 'https://testing.vstecscloud.shop'
|
||||||
target_host = 'https://aliyun.kaiyuancloud.cn'
|
target_host = 'https://aliyun.opencomputing.cn'
|
||||||
|
|
||||||
if ns.get('userid'):
|
if ns.get('userid'):
|
||||||
userid = ns.get('userid')
|
userid = ns.get('userid')
|
||||||
@ -39,7 +39,7 @@ async def jiajie_get_token_redirect(ns={}):
|
|||||||
# 发送HTTP请求
|
# 发送HTTP请求
|
||||||
url = "%s/api/blade-auth/oauth/token" % target_host
|
url = "%s/api/blade-auth/oauth/token" % target_host
|
||||||
|
|
||||||
if 'kaiyuancloud' in target_host:
|
if 'opencomputing' in target_host:
|
||||||
tenantid = '502332'
|
tenantid = '502332'
|
||||||
else:
|
else:
|
||||||
tenantid = '024060'
|
tenantid = '024060'
|
||||||
|
|||||||
@ -15,7 +15,7 @@ async def jiajie_sync_user(ns={}):
|
|||||||
'msg': '用户还未登录'
|
'msg': '用户还未登录'
|
||||||
}
|
}
|
||||||
# target_host = 'https://testing.vstecscloud.shop'
|
# target_host = 'https://testing.vstecscloud.shop'
|
||||||
target_host = 'https://aliyun.kaiyuancloud.cn'
|
target_host = 'https://aliyun.opencomputing.cn'
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
async with db.sqlorContext('kboss') as sor:
|
||||||
exits_user = await sor.R('weishijiajie_users', {'user_id': userid})
|
exits_user = await sor.R('weishijiajie_users', {'user_id': userid})
|
||||||
@ -71,7 +71,7 @@ async def jiajie_sync_user(ns={}):
|
|||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
'status': False,
|
'status': False,
|
||||||
'msg': f"请求失败,状态码: {result.get('code')},响应内容: {result.get('msg')}"
|
'msg': f"用户手机号:{phone}, 请求失败,状态码: {result.get('code')},响应内容: {result.get('msg')}"
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = await jiajie_sync_user(params_kw)
|
ret = await jiajie_sync_user(params_kw)
|
||||||
|
|||||||
@ -29,10 +29,20 @@ async def registerUser(ns):
|
|||||||
if len(ns.get('password')) < 6:
|
if len(ns.get('password')) < 6:
|
||||||
return {'status': False, 'msg': '密码必须6位数以上'}
|
return {'status': False, 'msg': '密码必须6位数以上'}
|
||||||
|
|
||||||
|
if not ns.get('codeid'):
|
||||||
|
return {'status': False, 'msg': '验证码ID不能为空'}
|
||||||
|
|
||||||
if ns.get('codeid'):
|
if ns.get('codeid'):
|
||||||
type += 1
|
|
||||||
code = await sor.R('validatecode', {'id': ns.get('codeid'), 'vcode': ns.get('vcode')})
|
code = await sor.R('validatecode', {'id': ns.get('codeid'), 'vcode': ns.get('vcode')})
|
||||||
if len(code) < 1:
|
# 验证码五分钟内才有效 create_at是字符串 格式是"2025-11-05 16:00:19"
|
||||||
|
if code:
|
||||||
|
create_at = code[0]['create_at']
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
create_at_dt = datetime.datetime.strptime(create_at, "%Y-%m-%d %H:%M:%S")
|
||||||
|
if (now - create_at_dt).seconds > 500:
|
||||||
|
return {'status': False, 'msg': '验证码过期'}
|
||||||
|
|
||||||
|
else:
|
||||||
return {'status': False, 'msg': '验证码不正确'}
|
return {'status': False, 'msg': '验证码不正确'}
|
||||||
|
|
||||||
#通过邀请码注册
|
#通过邀请码注册
|
||||||
@ -160,8 +170,8 @@ async def registerUser(ns):
|
|||||||
await openCustomerAccounts(sor, org[0]['id'], org_id)
|
await openCustomerAccounts(sor, org[0]['id'], org_id)
|
||||||
return {'status': True, 'msg': '注册成功'}
|
return {'status': True, 'msg': '注册成功'}
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
raise error
|
# raise error
|
||||||
return {'status': False, 'msg': '注册失败'}
|
return {'status': False, 'msg': '注册失败, %s' % str(error)}
|
||||||
|
|
||||||
|
|
||||||
ret = await registerUser(params_kw)
|
ret = await registerUser(params_kw)
|
||||||
|
|||||||
82
b/product/baidu_resource_query.dspy
Normal file
82
b/product/baidu_resource_query.dspy
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
async def baidu_resource_query(ns={}):
|
||||||
|
"""
|
||||||
|
用户资源查询
|
||||||
|
:param ns:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if ns.get('userid'):
|
||||||
|
userid = ns.get('userid')
|
||||||
|
else:
|
||||||
|
userid = await get_user()
|
||||||
|
db = DBPools()
|
||||||
|
async with db.sqlorContext('kboss') as sor:
|
||||||
|
baiduids = await sor.R('baidu_users', {'user_id': userid})
|
||||||
|
if baiduids:
|
||||||
|
baiduid = baiduids[0]['baidu_id']
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
'status': False,
|
||||||
|
'msg': 'User not synchronized'
|
||||||
|
}
|
||||||
|
ns['queryAccountId'] = baiduid
|
||||||
|
ns['pageSize'] = 200
|
||||||
|
method = 'POST'
|
||||||
|
ns_format = '&'.join(['%s=%s' % (k, v) for k, v in ns.items()])
|
||||||
|
url = 'https://billing.baidubce.com/v1/resource/query?%s' % ns_format
|
||||||
|
header = {
|
||||||
|
"Host": "billing.baidubce.com"
|
||||||
|
}
|
||||||
|
header = await get_auth_header(method=method, url=url, header=header)
|
||||||
|
async with aiohttp_client.request(
|
||||||
|
method=method,
|
||||||
|
url=url,
|
||||||
|
headers=header,
|
||||||
|
json=ns) as res:
|
||||||
|
result = await res.json()
|
||||||
|
return {'1': result}
|
||||||
|
|
||||||
|
result_new = []
|
||||||
|
for i in result['result']:
|
||||||
|
if i.get('status') != 'STOPPED':
|
||||||
|
result_new.append(i)
|
||||||
|
|
||||||
|
result['result'] = result_new
|
||||||
|
|
||||||
|
return {
|
||||||
|
'status': True,
|
||||||
|
'msg': 'get resource success',
|
||||||
|
'data': result
|
||||||
|
}
|
||||||
|
|
||||||
|
async def resource_overview(ns={}):
|
||||||
|
if ns.get('userid'):
|
||||||
|
userid = ns.get('userid')
|
||||||
|
else:
|
||||||
|
userid = await get_user()
|
||||||
|
init_data = [
|
||||||
|
{'id': 1, 'name': '云服务器', 'count': 0, 'unit': '实例'},
|
||||||
|
{'id': 2, 'name': '私有网络', 'count': 0, 'unit': 'VPC'},
|
||||||
|
{'id': 3, 'name': '负载均衡', 'count': 0, 'unit': '负载均衡'},
|
||||||
|
{'id': 4, 'name': '弹性块存储', 'count': 0, 'unit': '云盘'},
|
||||||
|
{'id': 5, 'name': 'NAT网关', 'count': 0, 'unit': '实例'},
|
||||||
|
{'id': 6, 'name': 'VPN连接', 'count': 0, 'unit': 'VPN网关'},
|
||||||
|
]
|
||||||
|
baidu_resource_data = await baidu_resource_query({'userid': userid})
|
||||||
|
print(baidu_resource_data)
|
||||||
|
if baidu_resource_data and baidu_resource_data.get('data') and baidu_resource_data['data'].get('result'):
|
||||||
|
for baidu_resource in baidu_resource_data['data']['result']:
|
||||||
|
if baidu_resource.get('serviceType') == 'CDS' and baidu_resource['status'] == 'RUNNING':
|
||||||
|
init_data[3]['count'] += 1
|
||||||
|
elif baidu_resource.get('serviceType') == 'EIP' and baidu_resource['status'] == 'RUNNING':
|
||||||
|
init_data[1]['count'] += 1
|
||||||
|
elif (baidu_resource.get('serviceType') == 'BCC' or baidu_resource.get('serviceType') == 'LS') and baidu_resource['status'] == 'RUNNING':
|
||||||
|
init_data[0]['count'] += 1
|
||||||
|
|
||||||
|
return {
|
||||||
|
'status': True,
|
||||||
|
'msg': 'get resource success',
|
||||||
|
'data': init_data
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = await baidu_resource_query(params_kw)
|
||||||
|
return ret
|
||||||
@ -1113,7 +1113,7 @@ detailDataLJS = {
|
|||||||
{
|
{
|
||||||
"title": "NVIDIA-4090-48G",
|
"title": "NVIDIA-4090-48G",
|
||||||
"description": "High-performance GPU server with powerful computing capabilities, suitable for AI training, deep learning, etc.",
|
"description": "High-performance GPU server with powerful computing capabilities, suitable for AI training, deep learning, etc.",
|
||||||
"price": "8000",
|
"price": "8800",
|
||||||
"pre_price": None,
|
"pre_price": None,
|
||||||
"price_unit": "台/月",
|
"price_unit": "台/月",
|
||||||
"discount": None,
|
"discount": None,
|
||||||
@ -1207,7 +1207,7 @@ detailDataLJS = {
|
|||||||
{
|
{
|
||||||
"title": "NVIDIA-4090",
|
"title": "NVIDIA-4090",
|
||||||
"description": "High-performance GPU server with powerful computing capabilities, suitable for AI training, deep learning, etc.",
|
"description": "High-performance GPU server with powerful computing capabilities, suitable for AI training, deep learning, etc.",
|
||||||
"price": "6500",
|
"price": "7200",
|
||||||
"pre_price": None,
|
"pre_price": None,
|
||||||
"price_unit": "台/月",
|
"price_unit": "台/月",
|
||||||
"discount": None,
|
"discount": None,
|
||||||
|
|||||||
@ -1,7 +1,48 @@
|
|||||||
async def mobilecode(ns):
|
async def mobilecode(ns):
|
||||||
"""登录发送短信验证码"""
|
"""发送短信验证码,支持注册和登录筛选"""
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
async with db.sqlorContext('kboss') as sor:
|
||||||
|
# 获取操作类型:register 或 login
|
||||||
|
action_type = ns.get('action_type') # register 或 login
|
||||||
|
|
||||||
|
if not action_type:
|
||||||
|
return {'status': False, 'msg': '操作类型action_type不能为空'}
|
||||||
|
|
||||||
|
# 通过手机号查找用户
|
||||||
|
mobile = ns.get('mobile')
|
||||||
|
if not mobile:
|
||||||
|
return {'status': False, 'msg': '手机号不能为空'}
|
||||||
|
|
||||||
|
userreacs = await sor.R('users', {'mobile': mobile, 'del_flg': '0'})
|
||||||
|
|
||||||
|
# 注册逻辑:检查手机号是否已存在
|
||||||
|
if action_type == 'register':
|
||||||
|
if len(userreacs) >= 1:
|
||||||
|
return {'status': False, 'msg': '手机号已注册,请直接登录'}
|
||||||
|
else:
|
||||||
|
# 注册时手机号不存在,可以发送验证码
|
||||||
|
code = await generate_vcode()
|
||||||
|
nss = await send_vcode(mobile, '用户注册登录验证', {'SMSvCode': code.get('vcode')})
|
||||||
|
if nss['status']:
|
||||||
|
return {'status': True, 'msg': '注册验证码发送成功', 'codeid': code.get('id')}
|
||||||
|
else:
|
||||||
|
return {'status': False, 'msg': '发送失败'}
|
||||||
|
|
||||||
|
# 登录逻辑:检查手机号是否存在
|
||||||
|
elif action_type == 'login':
|
||||||
|
if len(userreacs) >= 1:
|
||||||
|
# 登录时手机号存在,可以发送验证码
|
||||||
|
code = await generate_vcode()
|
||||||
|
nss = await send_vcode(userreacs[0]['mobile'], '用户注册登录验证', {'SMSvCode': code.get('vcode')})
|
||||||
|
if nss['status']:
|
||||||
|
return {'status': True, 'msg': '登录验证码发送成功', 'codeid': code.get('id')}
|
||||||
|
else:
|
||||||
|
return {'status': False, 'msg': '发送失败'}
|
||||||
|
else:
|
||||||
|
return {'status': False, 'action': 'redirect', 'msg': '用户未注册, 请到注册页面注册'}
|
||||||
|
|
||||||
|
# 原有逻辑:如果没有指定action_type,保持原有逻辑
|
||||||
|
else:
|
||||||
type = 0
|
type = 0
|
||||||
ns['del_flg'] = '0'
|
ns['del_flg'] = '0'
|
||||||
userreacs = await sor.R('users', ns)
|
userreacs = await sor.R('users', ns)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user