Эх сурвалжийг харах

修改密码退出用户登录

peng 11 сар өмнө
parent
commit
3c7dd6abd3

+ 28 - 7
Controller/UserController.py

@@ -26,7 +26,7 @@ from jwt.algorithms import RSAAlgorithm
 from ratelimit import limits
 from ratelimit import limits
 
 
 from Ansjer.config import AuthCode_Expire, SERVER_DOMAIN, TUTK_PUSH_DOMAIN, \
 from Ansjer.config import AuthCode_Expire, SERVER_DOMAIN, TUTK_PUSH_DOMAIN, \
-    LOGGER, CONFIG_US, APP_MAPPING
+    LOGGER, CONFIG_US, APP_MAPPING, DETECT_PUSH_DOMAINS
 from Ansjer.config import BASE_DIR, CONFIG_EUR, CONFIG_INFO, SERVER_DOMAIN_EUR, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
 from Ansjer.config import BASE_DIR, CONFIG_EUR, CONFIG_INFO, SERVER_DOMAIN_EUR, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
 from Controller.CheckUserData import DataValid, date_handler, RandomStr
 from Controller.CheckUserData import DataValid, date_handler, RandomStr
 from Controller.UserDevice.UserSubscriptionController import UserSubscriptionControllerView
 from Controller.UserDevice.UserSubscriptionController import UserSubscriptionControllerView
@@ -3524,26 +3524,31 @@ class SingleLoginView(TemplateView):
         salt = request_dict.get('salt', None)
         salt = request_dict.get('salt', None)
         password_version = request_dict.get('pwdVersion', 'V1')
         password_version = request_dict.get('pwdVersion', 'V1')
         authcode = request_dict.get('authcode', None)
         authcode = request_dict.get('authcode', None)
+        app_bundle_id = request_dict.get('appBundleId', None)
+        token_val = request_dict.get('tokenVal', None)
+        if not all([app_bundle_id, token_val]):
+            return response.json(444, 'appBundleId,tokenVal')
+        new_bundle = APP_MAPPING.get(app_bundle_id, None)
         if password is None or authcode is None:
         if password is None or authcode is None:
             return response.json(444, 'password,authcode')
             return response.json(444, 'password,authcode')
-        authcode = CommonService.decode_data(authcode.strip())
+        # authcode = CommonService.decode_data(authcode.strip())
         if authcode is None:
         if authcode is None:
             return response.json(444, 'password,authcode')
             return response.json(444, 'password,authcode')
 
 
-        password = CommonService.decode_data(password.strip())
+        # password = CommonService.decode_data(password.strip())
         if password is None:
         if password is None:
             return response.json(444, 'password,authcode')
             return response.json(444, 'password,authcode')
         if phone is not None:
         if phone is not None:
             phone = phone.strip()
             phone = phone.strip()
-            return self.do_phone(phone, authcode, password, response, password_version, salt)
+            return self.do_phone(phone, authcode, password, response, password_version, salt, new_bundle, token_val)
         elif email is not None:
         elif email is not None:
             email = email.strip()
             email = email.strip()
-            return self.do_email(email, authcode, password, response, password_version, salt)
+            return self.do_email(email, authcode, password, response, password_version, salt, new_bundle, token_val)
         else:
         else:
             return response.json(444, 'phone')
             return response.json(444, 'phone')
 
 
     @staticmethod
     @staticmethod
-    def do_email(email, authcode, password, response, password_version, salt):
+    def do_email(email, authcode, password, response, password_version, salt, new_bundle, token_val):
         data_valid = DataValid()
         data_valid = DataValid()
         if data_valid.email_validate(email) is not True:
         if data_valid.email_validate(email) is not True:
             return response.json(105)
             return response.json(105)
@@ -3551,6 +3556,7 @@ class SingleLoginView(TemplateView):
         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)
+        user_id = user_qs[0].userID
         if password_version == 'V1':
         if password_version == 'V1':
             re_flag = data_valid.password_validate(password)
             re_flag = data_valid.password_validate(password)
             password = make_password(password)
             password = make_password(password)
@@ -3571,16 +3577,24 @@ class SingleLoginView(TemplateView):
         user_qs.update(userEmail=email, password=password)
         user_qs.update(userEmail=email, password=password)
         if not reds.del_data(key):
         if not reds.del_data(key):
             return response.json(10, '删除缓存失败')
             return response.json(10, '删除缓存失败')
+        key = 'token_user_{}_{}'.format(user_qs[0].userID, new_bundle)
+        LOGGER.info('{}修改密码写入token:{}'.format(user_id, 'temp_value'))
+        reds.set_data(key, 'temp_value')
+        push_url = '{}transparent-transmission/logout-push'.format(DETECT_PUSH_DOMAINS)
+        result = requests.post(push_url, data={'push_token': token_val, 'user_id': user_id,
+                                               'app_bundle_id': new_bundle})
+        LOGGER.info('{}修改密码推送结果:{}'.format(user_id, result.json()))
         return response.json(0)
         return response.json(0)
 
 
     @staticmethod
     @staticmethod
-    def do_phone(phone, authcode, password, response, password_version, salt):
+    def do_phone(phone, authcode, password, response, password_version, salt, new_bundle, token_val):
         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(100)
             return response.json(100)
         user_qs = Device_User.objects.filter(Q(username=phone) | Q(phone=phone))
         user_qs = Device_User.objects.filter(Q(username=phone) | Q(phone=phone))
         if not user_qs.exists():
         if not user_qs.exists():
             return response.json(102)
             return response.json(102)
+        user_id = user_qs[0].userID
         if password_version == 'V1':
         if password_version == 'V1':
             re_flag = data_valid.password_validate(password)
             re_flag = data_valid.password_validate(password)
             password = make_password(password)
             password = make_password(password)
@@ -3601,6 +3615,13 @@ class SingleLoginView(TemplateView):
         user_qs.update(phone=phone, password=password)
         user_qs.update(phone=phone, password=password)
         if not reds.del_data(key):
         if not reds.del_data(key):
             return response.json(10, '删除缓存失败')
             return response.json(10, '删除缓存失败')
+        key = 'token_user_{}_{}'.format(user_qs[0].userID, new_bundle)
+        LOGGER.info('{}修改密码写入token:{}'.format(user_id, 'temp_value'))
+        reds.set_data(key, 'temp_value')
+        push_url = '{}transparent-transmission/logout-push'.format(DETECT_PUSH_DOMAINS)
+        result = requests.post(push_url, data={'push_token': token_val, 'user_id': user_id,
+                                               'app_bundle_id': new_bundle})
+        LOGGER.info('{}修改密码推送结果:{}'.format(user_id, result.json()))
         return response.json(0)
         return response.json(0)
 
 
     @staticmethod
     @staticmethod