|
@@ -3398,8 +3398,7 @@ class SingleLoginView(TemplateView):
|
|
# 邮箱验证码
|
|
# 邮箱验证码
|
|
if email is not None:
|
|
if email is not None:
|
|
email = email.strip()
|
|
email = email.strip()
|
|
- # 阿里云的发送邮箱的调用方法
|
|
|
|
- return self.get_aliyun_email_code(email, response)
|
|
|
|
|
|
+ return self.get_aliyun_email_code(email, code_type, response)
|
|
# 手机验证码
|
|
# 手机验证码
|
|
else:
|
|
else:
|
|
phone = phone.strip()
|
|
phone = phone.strip()
|
|
@@ -3411,36 +3410,53 @@ class SingleLoginView(TemplateView):
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
- def get_aliyun_email_code(email, response):
|
|
|
|
- print('阿里云开始')
|
|
|
|
|
|
+ def get_aliyun_email_code(email, code_type, response):
|
|
|
|
+ """
|
|
|
|
+ 获取邮箱验证码
|
|
|
|
+ @param email: 邮箱
|
|
|
|
+ @param code_type: 不传: 单点登录, 2: 查看设备密码
|
|
|
|
+ @param response:
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
data_valid = DataValid()
|
|
data_valid = DataValid()
|
|
# 邮箱匹配
|
|
# 邮箱匹配
|
|
if data_valid.email_validate(email) is False:
|
|
if data_valid.email_validate(email) is False:
|
|
return response.json(107)
|
|
return response.json(107)
|
|
- reds = RedisObject()
|
|
|
|
- key = email + '_SingleLogin'
|
|
|
|
- identifying_code = reds.get_data(key=key)
|
|
|
|
- # 是否以获取邮箱验证码
|
|
|
|
- if identifying_code:
|
|
|
|
- return response.json(89)
|
|
|
|
|
|
+ # 查询用户是否存在
|
|
user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
- # 邮箱用户是否已存在
|
|
|
|
if not user_qs.exists():
|
|
if not user_qs.exists():
|
|
return response.json(99)
|
|
return response.json(99)
|
|
|
|
+
|
|
|
|
+ # 确定缓存key
|
|
|
|
+ if code_type is None:
|
|
|
|
+ redis_key = email + '_SingleLogin'
|
|
|
|
+ email_type = 'register_code'
|
|
|
|
+ elif code_type == '2':
|
|
|
|
+ redis_key = email + '_GetDevicePassword'
|
|
|
|
+ email_type = 'get_device_password'
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ redis_obj = RedisObject()
|
|
|
|
+ # 检查是否已获取邮箱验证码
|
|
|
|
+ identifying_code = redis_obj.get_data(key=redis_key)
|
|
|
|
+ if identifying_code:
|
|
|
|
+ return response.json(89)
|
|
|
|
+
|
|
# 生成随机6位数
|
|
# 生成随机6位数
|
|
identifying_code = RandomStr(6, True)
|
|
identifying_code = RandomStr(6, True)
|
|
# 设置随机数缓存生命周期
|
|
# 设置随机数缓存生命周期
|
|
- send_data = TemplateService.email_message(type='register_code', language=response.lang)
|
|
|
|
|
|
+ send_data = TemplateService.email_message(type=email_type, language=response.lang)
|
|
ses = SesClassObject()
|
|
ses = SesClassObject()
|
|
# 发送邮件
|
|
# 发送邮件
|
|
send_res = ses.alyEmailCode(
|
|
send_res = ses.alyEmailCode(
|
|
send_address_list=[email],
|
|
send_address_list=[email],
|
|
subject=send_data['title'],
|
|
subject=send_data['title'],
|
|
- body=send_data['body'].replace("{username}", email).replace("{captcha}", str(identifying_code))
|
|
|
|
|
|
+ body=send_data['body'].replace('{username}', email).replace('{captcha}', str(identifying_code))
|
|
)
|
|
)
|
|
if send_res is not True:
|
|
if send_res is not True:
|
|
return response.json(44)
|
|
return response.json(44)
|
|
- if reds.set_data(key=key, val=identifying_code, expire=600) is not True:
|
|
|
|
|
|
+ if redis_obj.set_data(key=redis_key, val=identifying_code, expire=600) is not True:
|
|
return response.json(10, 'error')
|
|
return response.json(10, 'error')
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|