|
@@ -11,7 +11,7 @@ from django.db import transaction
|
|
|
from django.db.models import Q
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, CONFIG_INFO, CONFIG_US
|
|
|
from Controller.CheckUserData import RandomStr
|
|
|
from Controller.DeviceConfirmRegion import Device_Region
|
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
@@ -50,6 +50,8 @@ class EquipmentManagerV3(View):
|
|
|
return self.not_login_do_mainUserDevice(request_dict, response)
|
|
|
elif operation == 'notLoginMainDelDevice':
|
|
|
return self.test_tool_del_device(request_dict, response)
|
|
|
+ elif operation == 'changeDevicePassword':
|
|
|
+ return self.change_device_password(request_dict, response)
|
|
|
|
|
|
token = request_dict.get('token', None)
|
|
|
tko = TokenObject(token)
|
|
@@ -678,11 +680,29 @@ class EquipmentManagerV3(View):
|
|
|
if deviceData.__contains__('UID'):
|
|
|
del deviceData['UID']
|
|
|
|
|
|
- # print(deviceData['View_Password'])
|
|
|
+ dev_info_qs = Device_Info.objects.filter(userID_id=userID, id=id).values('UID')
|
|
|
+ if not dev_info_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+
|
|
|
if deviceData.__contains__('View_Password'):
|
|
|
encrypt_pwd = deviceData['View_Password']
|
|
|
- deviceData['View_Password'] = self.decode_pwd(deviceData['View_Password'])
|
|
|
- dev_info_qs = Device_Info.objects.filter(userID_id=userID, id=id)
|
|
|
+ view_password = self.decode_pwd(deviceData['View_Password'])
|
|
|
+ deviceData['View_Password'] = view_password
|
|
|
+ # 记录修改密码日志
|
|
|
+ uid = dev_info_qs[0]['UID']
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ content = json.loads(json.dumps(request_dict))
|
|
|
+ log = {
|
|
|
+ 'user_id': 2,
|
|
|
+ 'status': 200,
|
|
|
+ 'time': int(time.time()),
|
|
|
+ 'url': 'v3/equipment/modify',
|
|
|
+ 'content': json.dumps(content),
|
|
|
+ 'ip': ip,
|
|
|
+ 'operation': '{}修改设备密码:{}'.format(uid, view_password),
|
|
|
+ }
|
|
|
+ LogModel.objects.create(**log)
|
|
|
+ # 更新数据
|
|
|
dev_info_qs.update(**deviceData)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
@@ -1157,6 +1177,49 @@ class EquipmentManagerV3(View):
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ def change_device_password(self, request_dict, response):
|
|
|
+ """
|
|
|
+ 修改设备密码
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ version = request_dict.get('version', None)
|
|
|
+ encrypt_pwd = request_dict.get('encrypt_pwd', None)
|
|
|
+ if not all([uid, version, encrypt_pwd]):
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ # 异步请求其他服
|
|
|
+ if CONFIG_INFO == CONFIG_US:
|
|
|
+ change_pwd_thread = threading.Thread(target=self.change_pwd, args=request_dict.dict())
|
|
|
+
|
|
|
+ view_password = self.decode_pwd(encrypt_pwd)
|
|
|
+ Device_Info.objects.filter(UID=uid).update(View_Password=view_password)
|
|
|
+ content = json.loads(json.dumps(request_dict))
|
|
|
+ log = {
|
|
|
+ 'user_id': 2,
|
|
|
+ 'status': 200,
|
|
|
+ 'time': int(time.time()),
|
|
|
+ 'url': 'v3/equipment/changeDevicePassword',
|
|
|
+ 'content': json.dumps(content),
|
|
|
+ 'operation': '{}上报设备密码:{}'.format(uid, view_password),
|
|
|
+ }
|
|
|
+ LogModel.objects.create(**log)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def change_pwd(data):
|
|
|
+ """
|
|
|
+ 请求更新密码线程
|
|
|
+ @param data: 请求数据
|
|
|
+ """
|
|
|
+ orders_domain_name_list = CommonService.get_orders_domain_name_list()
|
|
|
+ for domain_name in orders_domain_name_list:
|
|
|
+ url = '{}v3/equipment/changeDevicePassword'.format(domain_name)
|
|
|
+ requests.post(url=url, data=data, timeout=30)
|
|
|
+
|
|
|
+
|
|
|
def do_get_device_features(self, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
|