|
@@ -848,39 +848,50 @@ class v2authCodeView(TemplateView):
|
|
|
|
|
|
# 阿里云获取邮箱验证码
|
|
|
def aliyun_emailCode(self, email, response):
|
|
|
- print('阿里云开始')
|
|
|
- dataValid = DataValid()
|
|
|
- # 邮箱匹配
|
|
|
- if dataValid.email_validate(email) is False:
|
|
|
- return response.json(107)
|
|
|
- reds = RedisObject()
|
|
|
- identifyingCode = reds.get_data(key=email + '_identifyingCode')
|
|
|
- # 是否以获取邮箱验证码
|
|
|
- if identifyingCode:
|
|
|
+ try:
|
|
|
+ print('阿里云开始')
|
|
|
+ dataValid = DataValid()
|
|
|
+ # 邮箱匹配
|
|
|
+ if dataValid.email_validate(email) is False:
|
|
|
+ return response.json(107)
|
|
|
+ reds = RedisObject()
|
|
|
+ code_key = f'ZOSI:BASIC:USER:EMAIL:{email}'
|
|
|
+ code = reds.get_data(key=code_key)
|
|
|
+ # 是否以获取邮箱验证码
|
|
|
+ if code:
|
|
|
+ return response.json(0)
|
|
|
+ user_qs = Device_User.objects.filter(username=email)
|
|
|
+ email_qs = Device_User.objects.filter(userEmail=email)
|
|
|
+ # 邮箱用户是否已存在
|
|
|
+ if user_qs.exists():
|
|
|
+ return response.json(103)
|
|
|
+ elif email_qs.exists():
|
|
|
+ return response.json(103)
|
|
|
+ # 生成随机6位数
|
|
|
+ identifyingCode = RandomStr(6, True)
|
|
|
+ # 设置随机数缓存生命周期
|
|
|
+ send_data = TemplateService.email_message(type='register_code', language=response.lang)
|
|
|
+ start_time = time.time()
|
|
|
+ ses = SesClassObject()
|
|
|
+ # 发送邮件
|
|
|
+ send_res = ses.alyEmailCode(
|
|
|
+ send_address_list=[email],
|
|
|
+ subject=send_data['title'],
|
|
|
+ body=send_data['body'].replace("{username}", email).replace("{captcha}", str(identifyingCode))
|
|
|
+ )
|
|
|
+ end_time = time.time()
|
|
|
+ LOGGER.info('阿里云邮箱发送验证码执行时间: {:.3f} 秒,email:{}'.format((end_time - start_time), email))
|
|
|
+ if send_res is not True:
|
|
|
+ return response.json(44)
|
|
|
+ # 单个邮箱验证码有效期5分钟
|
|
|
+ if reds.set_data(key=email + '_identifyingCode', val=identifyingCode, expire=300) is not True:
|
|
|
+ return response.json(10, 'error')
|
|
|
+ # 单个邮箱一分钟发送一次验证码
|
|
|
+ reds.set_data(key=code_key, val=identifyingCode, expire=60)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('aliyun_emailCode error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(0)
|
|
|
- user_qs = Device_User.objects.filter(username=email)
|
|
|
- email_qs = Device_User.objects.filter(userEmail=email)
|
|
|
- # 邮箱用户是否已存在
|
|
|
- if user_qs.exists():
|
|
|
- return response.json(103)
|
|
|
- elif email_qs.exists():
|
|
|
- return response.json(103)
|
|
|
- # 生成随机6位数
|
|
|
- identifyingCode = RandomStr(6, True)
|
|
|
- # 设置随机数缓存生命周期
|
|
|
- send_data = TemplateService.email_message(type='register_code', language=response.lang)
|
|
|
- ses = SesClassObject()
|
|
|
- # 发送邮件
|
|
|
- send_res = ses.alyEmailCode(
|
|
|
- send_address_list=[email],
|
|
|
- subject=send_data['title'],
|
|
|
- body=send_data['body'].replace("{username}", email).replace("{captcha}", str(identifyingCode))
|
|
|
- )
|
|
|
- if send_res is not True:
|
|
|
- return response.json(44)
|
|
|
- if reds.set_data(key=email + '_identifyingCode', val=identifyingCode, expire=60) is not True:
|
|
|
- return response.json(10, 'error')
|
|
|
- return response.json(0)
|
|
|
|
|
|
def phoneCode(self, phone, response, sign_name):
|
|
|
dataValid = DataValid()
|