|
@@ -3391,24 +3391,24 @@ class SingleLoginView(TemplateView):
|
|
phone = request_dict.get('phone', None)
|
|
phone = request_dict.get('phone', None)
|
|
sign_name = request_dict.get('sign_name', None)
|
|
sign_name = request_dict.get('sign_name', None)
|
|
country_code = request_dict.get('country_code', None)
|
|
country_code = request_dict.get('country_code', None)
|
|
- # code_type = 1 表示修改绑定手机号
|
|
|
|
code_type = request_dict.get('code_type', None)
|
|
code_type = request_dict.get('code_type', None)
|
|
- if email is not None:
|
|
|
|
- email = email.strip()
|
|
|
|
- # 阿里云的发送邮箱的调用方法
|
|
|
|
- return self.get_aliyun_email_code(email, response)
|
|
|
|
- elif phone is not None and code_type == "1":
|
|
|
|
- phone = phone.strip()
|
|
|
|
- country_code = str(country_code.strip())
|
|
|
|
- # 短信签名
|
|
|
|
- sign_name = CommonService.confirm_msg_sign_name(sign_name)
|
|
|
|
- return self.get_change_phone_code(country_code, phone, response, sign_name)
|
|
|
|
- elif phone is not None:
|
|
|
|
- phone = phone.strip()
|
|
|
|
- country_code = str(country_code.strip())
|
|
|
|
- return self.get_phone_code(country_code, phone, response, sign_name)
|
|
|
|
- else:
|
|
|
|
|
|
+ if not any([email, phone]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
+ try:
|
|
|
|
+ # 邮箱验证码
|
|
|
|
+ if email is not None:
|
|
|
|
+ email = email.strip()
|
|
|
|
+ # 阿里云的发送邮箱的调用方法
|
|
|
|
+ return self.get_aliyun_email_code(email, response)
|
|
|
|
+ # 手机验证码
|
|
|
|
+ else:
|
|
|
|
+ phone = phone.strip()
|
|
|
|
+ country_code = str(country_code.strip())
|
|
|
|
+ # 短信签名
|
|
|
|
+ sign_name = CommonService.confirm_msg_sign_name(sign_name)
|
|
|
|
+ return self.get_phone_code(country_code, phone, sign_name, code_type, response)
|
|
|
|
+ except Exception as 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):
|
|
def get_aliyun_email_code(email, response):
|
|
@@ -3445,39 +3445,59 @@ class SingleLoginView(TemplateView):
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
- def get_phone_code(country_code, phone, response, sign_name):
|
|
|
|
|
|
+ def get_phone_code(country_code, phone, sign_name, code_type, response):
|
|
|
|
+ """
|
|
|
|
+ 获取手机验证码
|
|
|
|
+ @param country_code: 国家编码
|
|
|
|
+ @param phone: 手机号码
|
|
|
|
+ @param sign_name: 短信签名
|
|
|
|
+ @param code_type: 验证码类型, None: 单点登录, 1: 修改手机号码, 2: 查看设备密码
|
|
|
|
+ @param response:
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
data_valid = DataValid()
|
|
data_valid = DataValid()
|
|
if data_valid.mobile_validate(phone) is not True:
|
|
if data_valid.mobile_validate(phone) is not True:
|
|
return response.json(107)
|
|
return response.json(107)
|
|
- reds = RedisObject()
|
|
|
|
- reds_key = str(phone) + '_SingleLogin'
|
|
|
|
- identifying_code = reds.get_data(key=reds_key)
|
|
|
|
- reds_key_ttl = reds.get_ttl(key=reds_key)
|
|
|
|
- if reds_key_ttl > 240 and identifying_code:
|
|
|
|
- return response.json(90)
|
|
|
|
- user_qs = Device_User.objects.filter(Q(username=phone) | Q(phone=phone))
|
|
|
|
- if not user_qs.exists():
|
|
|
|
- return response.json(102)
|
|
|
|
- identifying_code = RandomStr(6, True)
|
|
|
|
|
|
+ # 根据验证码类型确定缓存key和短信模板
|
|
|
|
+ if code_type is None:
|
|
|
|
+ user_qs = Device_User.objects.filter(Q(username=phone) | Q(phone=phone))
|
|
|
|
+ if not user_qs.exists():
|
|
|
|
+ return response.json(102)
|
|
|
|
+ redis_key = str(phone) + '_SingleLogin'
|
|
|
|
+ # 短信模板
|
|
|
|
+ temp_msg = 'SMS_151675019' if country_code == '86' else 'SMS_172200051'
|
|
|
|
+ elif code_type == '1':
|
|
|
|
+ redis_key = str(phone) + '_ChangePhone'
|
|
|
|
+ temp_msg = 'SMS_151675018' if country_code == '86' else 'SMS_172165867'
|
|
|
|
+ elif code_type == '2':
|
|
|
|
+ redis_key = str(phone) + '_GetDevicePassword'
|
|
|
|
+ temp_msg = 'SMS_479855154' if country_code == '86' else 'SMS_479785146'
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ # 根据手机区号处理发送手机号码和签名
|
|
if country_code == '86':
|
|
if country_code == '86':
|
|
- # 国内短信推送模板
|
|
|
|
- temp_msg = 'SMS_151675019'
|
|
|
|
rec_phone = phone
|
|
rec_phone = phone
|
|
else:
|
|
else:
|
|
- # 国际短信推送模板
|
|
|
|
- temp_msg = 'SMS_172200051'
|
|
|
|
rec_phone = country_code + phone
|
|
rec_phone = country_code + phone
|
|
sign_name = 'Ansjer'
|
|
sign_name = 'Ansjer'
|
|
|
|
|
|
|
|
+ redis_obj = RedisObject()
|
|
|
|
+ identifying_code = redis_obj.get_data(key=redis_key)
|
|
|
|
+ reds_key_ttl = redis_obj.get_ttl(key=redis_key)
|
|
|
|
+ if reds_key_ttl > 240 and identifying_code:
|
|
|
|
+ return response.json(90)
|
|
|
|
+ identifying_code = RandomStr(6, True)
|
|
|
|
+
|
|
# 发送手机验证码
|
|
# 发送手机验证码
|
|
alisms = AliSmsObject()
|
|
alisms = AliSmsObject()
|
|
res = alisms.send_code_sms(phone=rec_phone, code=identifying_code, sign_name=sign_name, temp_msg=temp_msg)
|
|
res = alisms.send_code_sms(phone=rec_phone, code=identifying_code, sign_name=sign_name, temp_msg=temp_msg)
|
|
- if res["Code"] == "OK":
|
|
|
|
- if reds.set_data(key=reds_key, val=identifying_code, expire=300) is not True:
|
|
|
|
|
|
+ if res['Code'] == 'OK':
|
|
|
|
+ if redis_obj.set_data(key=redis_key, val=identifying_code, expire=300) is not True:
|
|
return response.json(10, '生成缓存系统错误')
|
|
return response.json(10, '生成缓存系统错误')
|
|
return response.json(0)
|
|
return response.json(0)
|
|
else:
|
|
else:
|
|
- return response.json(10, res["Message"])
|
|
|
|
|
|
+ return response.json(10, res['Message'])
|
|
|
|
|
|
def change_password(self, request_dict, response):
|
|
def change_password(self, request_dict, response):
|
|
phone = request_dict.get('phone', None)
|
|
phone = request_dict.get('phone', None)
|
|
@@ -3586,40 +3606,6 @@ class SingleLoginView(TemplateView):
|
|
LOGGER.info('{}修改密码推送结果:{}'.format(user_id, result.json()))
|
|
LOGGER.info('{}修改密码推送结果:{}'.format(user_id, result.json()))
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
- @staticmethod
|
|
|
|
- def get_change_phone_code(country_code, phone, response, sign_name):
|
|
|
|
- data_valid = DataValid()
|
|
|
|
- if data_valid.mobile_validate(phone) is not True:
|
|
|
|
- return response.json(107)
|
|
|
|
- reds = RedisObject()
|
|
|
|
- reds_key = str(phone) + '_ChangePhone'
|
|
|
|
- identifying_code = reds.get_data(key=reds_key)
|
|
|
|
- reds_key_ttl = reds.get_ttl(key=reds_key)
|
|
|
|
- if reds_key_ttl > 240 and identifying_code:
|
|
|
|
- return response.json(90)
|
|
|
|
- identifying_code = RandomStr(6, True)
|
|
|
|
- if country_code == '86':
|
|
|
|
- # 国内短信推送模板
|
|
|
|
- temp_msg = 'SMS_151675018'
|
|
|
|
- rec_phone = phone
|
|
|
|
- if sign_name == 'zosi':
|
|
|
|
- sign_name = '周视'
|
|
|
|
- else:
|
|
|
|
- # 国际短信推送模板
|
|
|
|
- temp_msg = 'SMS_172165867'
|
|
|
|
- rec_phone = country_code + phone
|
|
|
|
- sign_name = 'Ansjer'
|
|
|
|
-
|
|
|
|
- # 发送手机验证码
|
|
|
|
- alisms = AliSmsObject()
|
|
|
|
- res = alisms.send_code_sms(phone=rec_phone, code=identifying_code, sign_name=sign_name, temp_msg=temp_msg)
|
|
|
|
- if res["Code"] == "OK":
|
|
|
|
- if reds.set_data(key=reds_key, val=identifying_code, expire=300) is not True:
|
|
|
|
- return response.json(10, '生成缓存系统错误')
|
|
|
|
- return response.json(0)
|
|
|
|
- else:
|
|
|
|
- return response.json(10, res["Message"])
|
|
|
|
-
|
|
|
|
|
|
|
|
class UnbundingWXView(TemplateView):
|
|
class UnbundingWXView(TemplateView):
|
|
|
|
|