Explorar o código

优化查看设备密码获取验证码

locky hai 5 meses
pai
achega
addb68d176
Modificáronse 1 ficheiros con 20 adicións e 19 borrados
  1. 20 19
      Controller/UserController.py

+ 20 - 19
Controller/UserController.py

@@ -3395,40 +3395,40 @@ class SingleLoginView(TemplateView):
         uid = request_dict.get('uid', None)
         if not any([email, phone]):
             return response.json(444)
+
         try:
-            # 查询主用户信息
-            device_info_qs = Device_Info.objects.filter(UID=uid).values('vodPrimaryMaster')
-            if not device_info_qs.exists():
-                return response.json(173)
-            primary_master = device_info_qs[0]['vodPrimaryMaster']
-            # 邮箱验证码
-            if email is not None:
-                email = email.strip()
+            # 查看设备密码,传uid和检验主用户
+            if code_type == '2':
                 if uid is None:
                     return response.json(444)
-                # 判断是否为主用户
-                if email != primary_master:
+                user_info = email if email is not None else phone
+                # 查询主用户信息
+                device_info_qs = Device_Info.objects.filter(UID=uid).values('vodPrimaryMaster')
+                if not device_info_qs.exists():
+                    return response.json(173)
+                if user_info != device_info_qs[0]['vodPrimaryMaster']:
                     return response.json(12)
-                return self.get_aliyun_email_code(email, code_type, response)
+            # 邮箱验证码
+            if email is not None:
+                email = email.strip()
+                return self.get_aliyun_email_code(email, code_type, uid, response)
             # 手机验证码
             else:
                 phone = phone.strip()
-                # 判断是否为主用户
-                if phone != primary_master:
-                    return response.json(12)
                 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)
+                return self.get_phone_code(country_code, phone, sign_name, code_type, uid, response)
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     @staticmethod
-    def get_aliyun_email_code(email, code_type, response):
+    def get_aliyun_email_code(email, code_type, uid, response):
         """
         获取邮箱验证码
         @param email: 邮箱
         @param code_type:  不传: 单点登录, 2: 查看设备密码
+        @param uid:
         @param response:
         @return:
         """
@@ -3446,7 +3446,7 @@ class SingleLoginView(TemplateView):
             redis_key = email + '_SingleLogin'
             email_type = 'register_code'
         elif code_type == '2':
-            redis_key = email + '_GetDevicePassword'
+            redis_key = email + uid + '_GetDevicePassword'
             email_type = 'get_device_password'
         else:
             return response.json(444)
@@ -3475,13 +3475,14 @@ class SingleLoginView(TemplateView):
         return response.json(0)
 
     @staticmethod
-    def get_phone_code(country_code, phone, sign_name, code_type, response):
+    def get_phone_code(country_code, phone, sign_name, code_type, uid, response):
         """
         获取手机验证码
         @param country_code: 国家编码
         @param phone: 手机号码
         @param sign_name: 短信签名
         @param code_type: 验证码类型, None: 单点登录, 1: 修改手机号码, 2: 查看设备密码
+        @param uid:
         @param response:
         @return:
         """
@@ -3500,7 +3501,7 @@ class SingleLoginView(TemplateView):
             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'
+            redis_key = str(phone) + uid + '_GetDevicePassword'
             temp_msg = 'SMS_479855154' if country_code == '86' else 'SMS_479785146'
         else:
             return response.json(444)