kboss/b/user/retrievecode.dspy
2026-07-16 11:36:00 +08:00

48 lines
2.2 KiB
Plaintext

async def get_retrieve_tenant_orgid(sor, ns):
domain_name = ns.get('domain_name')
if (not domain_name) and ns.get('url_link'):
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if domain_name:
domain_name = domain_name.strip().replace('https://', '').replace('http://', '').replace('/', '')
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
reseller = await sor.R('reseller', {'domain_name': domain_name, 'del_flg': '0'})
if len(reseller) >= 1:
return reseller[0]['orgid']
org = await sor.R('organization', {'org_type': '0', 'del_flg': '0'})
if len(org) >= 1:
return org[0]['id']
return None
async def retrievecode(ns):
"""找回密码发送短信验证码"""
db = DBPools()
async with db.sqlorContext('kboss') as sor:
tenant_orgid = await get_retrieve_tenant_orgid(sor, ns)
if not tenant_orgid:
return {'status': False, 'msg': '未找到当前域名所属租户'}
type = 0
username = ns.get('username') or ns.get('mobile')
if not username:
return {'status': False, 'msg': '用户标识不能为空'}
user_sql = """select * from users where username = '%s' and tenant_orgid = '%s' and del_flg = '0' limit 1;""" % (username, tenant_orgid)
userreacs = await sor.sqlExe(user_sql, {})
if len(userreacs) >= 1:
type += 1
else:
user_sql = """select * from users where mobile = '%s' and tenant_orgid = '%s' and del_flg = '0' limit 1;""" % (username, tenant_orgid)
userreacs = await sor.sqlExe(user_sql, {})
if len(userreacs) >= 1:
type += 1
if type >= 1:
code = await generate_vcode()
nss = await send_vcode(userreacs[0]['mobile'], '用户注册登录验证', code.get('vcode'))
if nss == True:
return {'status': True, 'msg': '发送成功', 'codeid': code.get('id'), 'userid': userreacs[0]['id']}
else:
return {'status': False, 'msg': '发送失败'}
else:
return {'status': False, 'msg': '没有该用户或手机号错误'}
ret = await retrievecode(params_kw)
return ret