update mailcode

This commit is contained in:
ping 2025-11-05 15:31:47 +08:00
parent 1a173b4775
commit 1dca74e01f

View File

@ -1,7 +1,45 @@
async def mobilecode(ns):
"""登录发送短信验证码"""
"""发送短信验证码,支持注册和登录筛选"""
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 获取操作类型register 或 login
action_type = ns.get('action_type') # register 或 login
# 通过手机号查找用户
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:
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:
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
ns['del_flg'] = '0'
userreacs = await sor.R('users', ns)