|
@@ -2,8 +2,8 @@ import re
|
|
|
import threading
|
|
|
import time
|
|
|
import traceback
|
|
|
-
|
|
|
-import oss2
|
|
|
+from Controller.CheckUserData import RandomStr
|
|
|
+import oss2, base64
|
|
|
from django.db.models import Q
|
|
|
from django.views.generic.base import View
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -35,10 +35,13 @@ class EquipmentManagerV3(View):
|
|
|
if tko.code == 0:
|
|
|
response.lang = tko.lang
|
|
|
userID = tko.userID
|
|
|
- # if operation == 'add':
|
|
|
- # return self.do_add(userID, request_dict, response)
|
|
|
- if operation == 'query':
|
|
|
+ # 手机端添加设备,查询,修改
|
|
|
+ if operation == 'add':
|
|
|
+ return self.do_add(userID, request_dict, response, request)
|
|
|
+ elif operation == 'query':
|
|
|
return self.do_query(userID, request_dict, response)
|
|
|
+ elif operation == 'modify':
|
|
|
+ return self.do_modify(userID, request_dict, response)
|
|
|
elif operation == 'query_reset':
|
|
|
return self.do_query_reset(userID, request_dict, response)
|
|
|
else:
|
|
@@ -52,6 +55,8 @@ class EquipmentManagerV3(View):
|
|
|
NickName = request_dict.get('NickName', None)
|
|
|
View_Account = request_dict.get('View_Account', None)
|
|
|
View_Password = request_dict.get('View_Password', '')
|
|
|
+ print("准备解密")
|
|
|
+ View_Password = self.decode_pwd(View_Password)
|
|
|
Type = request_dict.get('Type', None)
|
|
|
ChannelIndex = request_dict.get('ChannelIndex', None)
|
|
|
if all([UID, NickName, View_Account, Type, ChannelIndex]):
|
|
@@ -81,7 +86,7 @@ class EquipmentManagerV3(View):
|
|
|
'uid': UID,
|
|
|
'addTime': nowTime,
|
|
|
'updTime': nowTime,
|
|
|
- 'ip': CommonService.get_ip_address(request),
|
|
|
+ 'ip': CommonService.get_ip_address(request_dict),
|
|
|
'channel': ChannelIndex,
|
|
|
'nickname': NickName,
|
|
|
}
|
|
@@ -115,6 +120,51 @@ class EquipmentManagerV3(View):
|
|
|
else:
|
|
|
return response.json(444, {'param': 'UID,NickName,View_Account,View_Password,Type,ChannelIndex'})
|
|
|
|
|
|
+ def do_modify(self, userID, request_dict, response):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ deviceContent = request_dict.get('content', None)
|
|
|
+ id = request_dict.get('id', None)
|
|
|
+ if not deviceContent or not id:
|
|
|
+ return response.json(444, 'content,id')
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if userID is None:
|
|
|
+ return response.json(309)
|
|
|
+ try:
|
|
|
+ deviceData = json.loads(deviceContent)
|
|
|
+ print(deviceData['View_Password'])
|
|
|
+ deviceData['View_Password'] = self.decode_pwd(deviceData['View_Password'])
|
|
|
+ dev_info_qs = Device_Info.objects.filter(userID_id=userID, id=id)
|
|
|
+ dev_info_qs.update(**deviceData)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(177, repr(e))
|
|
|
+ else:
|
|
|
+ qs = Device_Info.objects.filter(userID_id=userID, id=id)
|
|
|
+ res = CommonService.qs_to_dict(qs)
|
|
|
+ if qs.exists():
|
|
|
+ uid = qs[0].UID
|
|
|
+ nickname = qs[0].NickName
|
|
|
+ # 增加设备影子信息修改昵称 start
|
|
|
+ us_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
+ if us_qs.exists():
|
|
|
+ us_qs.update(nickname=nickname)
|
|
|
+ else:
|
|
|
+ ChannelIndex = qs[0].ChannelIndex
|
|
|
+ nowTime = int(time.time())
|
|
|
+ uid_set_create_dict = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ 'ip': CommonService.get_ip_address(request),
|
|
|
+ 'channel': ChannelIndex,
|
|
|
+ 'nickname': nickname,
|
|
|
+ }
|
|
|
+ UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
+ Device_Info.objects.filter(UID=uid).update(NickName=nickname)
|
|
|
+ return response.json(0, res)
|
|
|
# 新查询设备字段
|
|
|
def do_query(self, userID, request_dict, response):
|
|
|
token = request_dict.get('token', None)
|
|
@@ -190,6 +240,7 @@ class EquipmentManagerV3(View):
|
|
|
for index, item in enumerate(data):
|
|
|
if (page - 1) * line <= index:
|
|
|
if index < page * line:
|
|
|
+ item['View_Password']=self.encrypt_pwd(item['View_Password'])
|
|
|
items.append(item)
|
|
|
return response.json(0, items)
|
|
|
else:
|
|
@@ -207,17 +258,23 @@ class EquipmentManagerV3(View):
|
|
|
# print('NickName搜索缓存')
|
|
|
for index, item in enumerate(redis_value):
|
|
|
if NickName ==item['NickName']:
|
|
|
+ # 加密
|
|
|
+ item['View_Password'] = self.encrypt_pwd(item['View_Password'])
|
|
|
return response.json(0, item)
|
|
|
if uid:
|
|
|
# print('uid搜索缓存')
|
|
|
for index, item in enumerate(redis_value):
|
|
|
if uid == item['UID']:
|
|
|
+ # 加密
|
|
|
+ item['View_Password'] = self.encrypt_pwd(item['View_Password'])
|
|
|
return response.json(0, item)
|
|
|
items = []
|
|
|
# print('缓存分页')
|
|
|
for index, item in enumerate(redis_value):
|
|
|
if (page - 1) * line <= index:
|
|
|
if index < page * line:
|
|
|
+ # 加密
|
|
|
+ item['View_Password'] = self.encrypt_pwd(item['View_Password'])
|
|
|
items.append(item)
|
|
|
return response.json(0, items)
|
|
|
else:
|
|
@@ -230,3 +287,40 @@ class EquipmentManagerV3(View):
|
|
|
('id', 'NickName', 'UID', 'ChannelIndex', 'Type', 'isShare')
|
|
|
res = CommonService.qs_to_list(dvql)
|
|
|
return response.json(0, res)
|
|
|
+
|
|
|
+ # 加密
|
|
|
+ def encrypt_pwd(self,userPwd):
|
|
|
+ for i in range(1, 4):
|
|
|
+ if i == 1:
|
|
|
+ userPwd = RandomStr(3, False)+userPwd+RandomStr(3, False)
|
|
|
+ userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
|
+ if i == 2:
|
|
|
+ userPwd = RandomStr(2, False)+str(userPwd)+RandomStr(2, False)
|
|
|
+ userPwd =base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
|
+ if i == 3:
|
|
|
+ userPwd = RandomStr(1, False)+str(userPwd)+RandomStr(1, False)
|
|
|
+ userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
|
+ return userPwd
|
|
|
+
|
|
|
+ # 解密
|
|
|
+ def decode_pwd(self, 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
|