linhaohong 1 жил өмнө
parent
commit
a1ea576b3d

+ 2 - 0
Ansjer/urls.py

@@ -279,6 +279,8 @@ 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()),
+
 
 
     # 后台界面接口 -------------------------------------------------------------------------------------------------------

+ 116 - 0
Controller/UserController.py

@@ -5044,3 +5044,119 @@ def getPasswordSalt(request):
         return response.json(0, {'iterations': iterations, 'salt': salt})
     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):
+        response = ResponseObject()
+        if operation == 'sendPhoneCode':
+            return self.send_phone_code(request_dict, response)
+        elif 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 send_phone_code(request_dict, response):
+        phone = request_dict.get('phone', None)
+        sign_name = request_dict.get('sign_name', None)
+        country_code = request_dict.get('country_code', None)
+        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_ms = '周视'
+            else:
+                sign_ms = 'Ansjer'
+        else:
+            # 国际短信推送模板
+            temp_msg = 'SMS_172165867'
+            rec_phone = country_code + phone
+            sign_ms = 'Ansjer'
+
+        # 发送手机验证码
+        alisms = AliSmsObject()
+        res = alisms.send_code_sms(phone=rec_phone, code=identifying_code, sign_name=sign_ms, 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"])
+
+    @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')
+
+        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)