Parcourir la source

用户换绑手机号

linhaohong il y a 11 mois
Parent
commit
6e5044e397
2 fichiers modifiés avec 76 ajouts et 0 suppressions
  1. 1 0
      Ansjer/urls.py
  2. 75 0
      Controller/UserController.py

+ 1 - 0
Ansjer/urls.py

@@ -377,6 +377,7 @@ urlpatterns = [
     re_path('customSubscription/(?P<operation>.*)', UserSubscriptionController.UserSubscriptionControllerView.as_view()),
     re_path(r'^basic/serialNo/(?P<operation>.*)', SerialNumberCheckController.SerialNumberView.as_view()),
     re_path('inAppPurchase/(?P<operation>.*)', InAppPurchaseController.InAppPurchaseView.as_view()),
+    re_path('account/changeAccountInfo/(?P<operation>.*)$', UserController.ChangeAccountInfoView.as_view()),
     re_path('deviceCommon/(?P<operation>.*)$', DeviceCommonController.DeviceCommonView.as_view()),
     re_path('customCustomer/(?P<operation>.*)$', CustomCustomerController.CustomCustomerView.as_view()),
 

+ 75 - 0
Controller/UserController.py

@@ -4813,3 +4813,78 @@ def getPasswordSalt(request):
     except Exception as e:
         return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
+
+class ChangeAccountInfoView(View):
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        request_dict = request.GET
+        return self.validation(request_dict, request, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        request_dict = request.POST
+        return self.validation(request_dict, request, operation)
+
+    def validation(self, request_dict, request, operation):
+        language = request_dict.get('lang', 'en')
+        response = ResponseObject(language)
+        if operation == 'verifyCode':
+            return self.verify_code(request_dict, response)
+        elif operation == 'changePhone':
+            return self.change_phone(request_dict, response)
+        else:
+            return response.json(444)
+
+    @staticmethod
+    def verify_code(request_dict, response):
+        phone = request_dict.get('phone', None)
+        authcode = request_dict.get('authcode', None)
+        if phone is None or authcode is None:
+            return response.json(444, 'phone, authcode')
+        authcode = CommonService.decode_data(authcode.strip())
+        if authcode is None:
+            return response.json(444, 'authcode')
+        reds = RedisObject()
+        key = str(phone) + '_ChangePhone'
+        reset_code = reds.get_data(key=key)
+        if reset_code is False:
+            return response.json(90)
+        if authcode != reset_code:
+            return response.json(121)
+        if not reds.del_data(key):
+            return response.json(10, '删除缓存失败')
+        return response.json(0)
+
+    @staticmethod
+    def change_phone(request_dict, response):
+        ord_phone = request_dict.get('ord_phone', None)
+        new_phone = request_dict.get('new_phone', None)
+        authcode = request_dict.get('authcode', None)
+        new_user_qs = Device_User.objects.filter(Q(username=new_phone) | Q(phone=new_phone))
+        if new_user_qs.exists():
+            return response.json(101)
+
+        authcode = CommonService.decode_data(authcode.strip())
+        if authcode is None:
+            return response.json(444, 'authcode')
+        LOGGER.info(f"change_phone, authcode: {authcode}")
+        reds = RedisObject()
+        key = str(new_phone) + '_ChangePhone'
+        reset_code = reds.get_data(key=key)
+        if reset_code is False:
+            return response.json(90)
+        if authcode != reset_code:
+            return response.json(121)
+        if not reds.del_data(key):
+            return response.json(10, '删除缓存失败')
+
+        ord_user_qs = Device_User.objects.filter(Q(username=ord_phone) | Q(phone=ord_phone))
+        if not ord_user_qs.exists():
+            return response.json(102)
+        if ord_user_qs[0].username == ord_phone:
+            ord_user_qs.update(phone=new_phone, username=new_phone)
+        else:
+            ord_user_qs.update(phone=new_phone)
+        return response.json(0)