Browse Source

update expire

lang 4 years ago
parent
commit
3567f93389
2 changed files with 68 additions and 11 deletions
  1. 10 11
      controller/deviceStatus.py
  2. 58 0
      service/CommonService.py

+ 10 - 11
controller/deviceStatus.py

@@ -94,18 +94,17 @@ class deviceStatus(TemplateView):
         UID = request_dict.get("UID", '')
         userID = request_dict.get("userID", '')
         uid_nick = request_dict.get("uid_nick", '')
-        if UID == 'HVTLKFJM6KDTAF9J111A':
-            logger.info('this is my UID1111-------------------------------------')
-        logger.info('class:deviceStatus-------function:addOrUpdate------------------')
-        logger.info(UID)
-        logger.info(userID)
-        logger.info(uid_nick)
+        encrypt_pwd = request_dict.get("password", '')
+        region = request_dict.get("region", 'EN')
+
 
-        if UID == '' or userID == '' or uid_nick == '':
+        if UID == '' or userID == '' or uid_nick == '' or encrypt_pwd == '':
             return JsonResponse({'code':101,'msg':'fail'})
 
-        if UID == 'HVTLKFJM6KDTAF9J111A':
-            logger.info('this is my UID-------------------------------------')
+        commonService = CommonService()
+        password = commonService.decode_pwd(encrypt_pwd)
+        logger.info(encrypt_pwd)
+        logger.info(password)
 
         alexAuth = AlexaAuthModel.objects.filter(userID=userID)
         if not alexAuth.exists():
@@ -135,10 +134,10 @@ class deviceStatus(TemplateView):
         try:
             uid_rtsp_qs = UidRtspModel.objects.get(uid=UID)
         except UidRtspModel.DoesNotExist:
-            uid_rtsp_qs = UidRtspModel.objects.create(uid=UID, password='admin',
+            uid_rtsp_qs = UidRtspModel.objects.create(uid=UID, password=password,
                                                       nick=uid_nick, addTime=now_time,
                                                       updTime=now_time, rtsp_url=rtsp_url,
-                                                      region='EN')
+                                                      region=region)
         else:
             # if uid_rtsp_qs.password != uid_a['password']:
             uid_rtsp_qs.password = 'admin'

+ 58 - 0
service/CommonService.py

@@ -16,6 +16,7 @@ import datetime
 import time
 from pathlib import Path
 from random import Random
+import base64
 import ipdb
 import simplejson as json
 from django.core import serializers
@@ -42,5 +43,62 @@ class CommonService:
             str += characterSet[random.randint(0, length)]
         return str
 
+    # 加密
+    # @staticmethod
+    def encrypt_pwd(self, userPwd):
+        for i in range(1, 4):
+            if i == 1:
+                userPwd = self.RandomStr(3, False)+userPwd+self.RandomStr(3, False)
+                userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
+            if i == 2:
+                userPwd = self.RandomStr(2, False)+str(userPwd)+self.RandomStr(2, False)
+                userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
+            if i == 3:
+                userPwd = self.RandomStr(1, False)+str(userPwd)+self.RandomStr(1, False)
+                userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
+        return userPwd
+
+    # 解密
+    @staticmethod
+    def decode_pwd(password):
+        for i in range(1, 4):
+            if i == 1:
+                # 第一次先解密
+                password = base64.b64decode(password)
+                password = password.decode('utf-8')
+                # 截去第一位,最后一位
+                password = password[1:-1]
+            if i == 2:
+                # 第2次先解密
+                password = base64.b64decode(password)
+                password = password.decode('utf-8')
+                # 去前2位,后2位
+                password = password[2:-2]
+            if i == 3:
+                # 第3次先解密
+                password = base64.b64decode(password)
+                password = password.decode('utf-8')
+                # 去前3位,后3位
+                password = password[3:-3]
+        return password
+
+    # 生成随机字符串
+    @staticmethod
+    def RandomStr(randomlength=8, number=False):
+        str = ''
+        if number == False:
+            characterSet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsT' \
+                           'tUuVvWwXxYyZz0123456789'
+        else:
+            characterSet = '0123456789'
+
+        length = len(characterSet) - 1
+
+        random = Random()
+        for index in range(randomlength):
+            str += characterSet[random.randint(0, length)]
+
+        return str
+
 # data = CommonService.encrypt_data(20)
 # print(data)