Bladeren bron

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJServer into peng

peng 2 jaren geleden
bovenliggende
commit
0b64daf049
2 gewijzigde bestanden met toevoegingen van 40 en 36 verwijderingen
  1. 2 2
      Ansjer/urls.py
  2. 38 34
      Controller/SuperPasswordTool.py

+ 2 - 2
Ansjer/urls.py

@@ -22,7 +22,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     OrderTaskController, HistoryUIDController, UIDManageUserController, SerialNumberController, CompanyController, \
     RegionController, VPGController, LanguageController, TestController, DeviceConfirmRegion, S3GetStsController, \
     DetectControllerV2, PcInfo, PctestController, DeviceDebug, PaymentCycle, \
-    DeviceLogController, CouponController, AiController, ShadowController, AppAccountManagement
+    DeviceLogController, CouponController, AiController, ShadowController, SuperPasswordTool
 from Controller.Cron import CronTaskController
 from Controller.MessagePush import EquipmentMessagePush
 from Controller.Surveys import CloudStorageController
@@ -358,7 +358,7 @@ urlpatterns = [
     # KVS模块
     url(r'^kvs/', include("Ansjer.server_urls.kvs_url")),
     # 超级密码模块
-    re_path('appAccout/(?P<operation>.*)', AppAccountManagement.AppAccoutView.as_view()),
+    re_path('appAccout/(?P<operation>.*)', SuperPasswordTool.SuperPasswordView.as_view()),
 
     # 传感器网关
     re_path('sensorGateway/(?P<operation>.*)', SensorGatewayController.SensorGateway.as_view()),

+ 38 - 34
Controller/AppAccountManagement.py → Controller/SuperPasswordTool.py

@@ -12,7 +12,7 @@ import time
 from django.db import transaction
 
 from Controller.CheckUserData import RandomStr
-from Model.models import Device_User, Device_Info, DeviceSuperPassword, SysMsgModel
+from Model.models import Device_User, DeviceSuperPassword, SysMsgModel
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -21,7 +21,7 @@ from django.views import View
 from Service.CommonService import CommonService
 
 
-class AppAccoutView(View):
+class SuperPasswordView(View):
     def get(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
         operation = kwargs.get('operation')
@@ -35,15 +35,21 @@ class AppAccoutView(View):
         return self.validation(request_dict, request, operation)
 
     def validation(self, request_dict, request, operation):
-        token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
-        lang = request_dict.get('lang', token.lang)
-        response = ResponseObject(lang)
-        userID = token.userID
-        if operation == 'getAuthorizationCode':  # 获取用户请求/生成授权码
+        token = request_dict.get('token', None)
+        response = ResponseObject()
+        tko = TokenObject(token)
+        if tko.code != 0:
+            tko = TokenObject(
+                request.META.get('HTTP_AUTHORIZATION'))
+            if tko.code != 0:
+                return response.json(tko.code)
+            response.lang = tko.lang
+        userID = tko.userID
+        if operation == 'getAuthorizationCode':  # 用户提交请求
             return self.getAuthorizationCode(request_dict, response, userID)
-        if operation == 'customerServiceManagement':  # 编辑超级密码请求表
+        if operation == 'customerServiceManagement':  # 审核用户请求/生成超级密码
             return self.customerServiceManagement(request_dict, response)
-        if operation == 'getDeviceSuperPassword':  # 查询超级密码请求表
+        if operation == 'getDeviceSuperPassword':  # 查询用户请求表
             return self.getDeviceSuperPassword(request_dict, response)
         if operation == 'verifyTheVerificationCode':  # 检验验证码
             return self.verifyTheVerificationCode(request_dict, response, userID)
@@ -54,6 +60,7 @@ class AppAccoutView(View):
 
     def getAuthorizationCode(self, request_dict, response, userID):
         """
+        用户提交请求
         @param uid:设备id
         @param request_dict:请求参数
         @param response:响应对象
@@ -74,8 +81,8 @@ class AppAccoutView(View):
         try:
             now = int(time.time())
             addTime = now
-            device_info_qs = Device_Info.objects.filter(UID=uid, userID_id=userID)
-            if not device_info_qs.exists():
+            device_user_qs = Device_User.objects.filter(userID=userID)
+            if not device_user_qs.exists():
                 return response.json(173)
             if buyTime:
                 buyTime = datetime.datetime.strptime(buyTime, '%Y-%m-%d')
@@ -83,11 +90,6 @@ class AppAccoutView(View):
             DeviceSuperPassword.objects.create(uid=uid, orderID=orderID, describe=describe,
                                                purchase_channel=purchase_channel, addTime=addTime, userID_id=userID,
                                                buyTime=buyTime, status=0, lang=lang)
-            # 验证码生成
-            super_code = RandomStr(6, True)
-            super_password_id = "super_password_%s" % userID
-            redisObj = RedisObject()
-            redisObj.set_data(key=super_password_id, val=super_code, expire=86400)
 
             return response.json(0)
         except Exception as e:
@@ -96,6 +98,7 @@ class AppAccoutView(View):
 
     def customerServiceManagement(self, request_dict, response):
         """
+        审核用户请求/生成超级密码
         @param request_dict:请求参数
         @param response:响应对象
         @param hint:提示内容
@@ -115,29 +118,25 @@ class AppAccoutView(View):
                 if not device_super_password_qs.exists():
                     return response.json(173)
                 status = int(status)
-                authcode = ''
                 if status == 1:
-                    device_super_password_qs.update(status=status)
-                    super_password_id = 'super_password_' + userID
+                    # 验证码生成
+                    super_code = RandomStr(6, True)
+                    super_password_id = "super_password_%s" % userID
                     redisObj = RedisObject()
-                    # redis里面的验证码
-                    redis_super_code = redisObj.get_data(key=super_password_id)
-                    # 验证用户输入的验证码和redis中的验证码
-                    if redis_super_code is False:
-                        return response.json(120)
-                    authcode = CommonService.encode_data(redis_super_code)
-                if status == 0 and len(hint) > 1:
-                    device_super_password_qs.update(status=status, hint=hint)
-                    msg = hint
+                    redis = redisObj.set_data(key=super_password_id, val=super_code, expire=86400)
+                    if redis is False:
+                        return response.json(121)
+                    device_super_password_qs.update(status=status)
+                    if lang == 'en':
+                        msg = "Your authorization code is " + super_code + ",valid within 24 hours"
+                    else:
+                        msg = "您的授权代码:" + super_code + ",24小时内有效"
                     SysMsgModel.objects.create(userID_id=userID, msg=msg, addTime=now, updTime=now, uid=uid,
                                                eventType=2)
                     return response.json(0)
-                authcode = CommonService.decode_data(authcode)
-                if status == 1:
-                    if lang == 'en':
-                        msg = "Your authorization code is " + authcode + ",valid within 24 hours"
-                    else:
-                        msg = "您的授权代码:" + authcode + ",24小时内有效"
+                if status == 0 and len(hint) > 1:
+                    device_super_password_qs.update(status=status, hint=hint)
+                    msg = hint
                     SysMsgModel.objects.create(userID_id=userID, msg=msg, addTime=now, updTime=now, uid=uid,
                                                eventType=2)
                     return response.json(0)
@@ -148,6 +147,7 @@ class AppAccoutView(View):
 
     def getDeviceSuperPassword(self, request_dict, response):
         """
+        查询用户请求表
         @param request_dict:请求参数
         @param response:响应对象
         @return:
@@ -192,6 +192,7 @@ class AppAccoutView(View):
 
     def verifyTheVerificationCode(self, request_dict, response, userID):
         """
+        检验验证码
         @param request_dict:请求参数
         @param response:响应对象
         @param userID:用户ID
@@ -201,6 +202,8 @@ class AppAccoutView(View):
         authcode = request_dict.get('authcode', None)
         if authcode:
             authcode = CommonService.decode_data(authcode)
+            if not len(authcode) == 6:
+                return response.json(121)
             super_password_id = 'super_password_' + userID
             redisObj = RedisObject()
             # redis里面的验证码
@@ -215,6 +218,7 @@ class AppAccoutView(View):
 
     def deleteInformation(self, request_dict, response):
         """
+        删除信息
         @param request_dict:请求参数
         @param response:响应对象
         @param id:主键