def save_face(): try: timestamp = request.form['timestamp'] token = request.form['token'] if token != Tool.get_md5(app.config.get('TOKEN') + str(timestamp)): return 'Fail' name = request.form['name'] desc = request.form['desc'] ip = request.form['ip'] cmd = request.form['cmd'] face_img = request.files['face'] path = os.path.split( os.path.realpath(__file__) )[0] + os.path.sep + "static" + os.path.sep + "faces" + os.path.sep + name if not os.path.exists(path): os.mkdir(path) face_path = path + os.path.sep + face_img.filename face_img.save(face_path) user_id = FaceDao.add_user( User(username=name, ip=ip, cmd=cmd, desc=desc)) if user_id != -1: face_relative_path = 'faces/' + name + '/' + face_img.filename FaceDao.add_face( Face(face=face_relative_path, time_point=time.time(), user_id=user_id)) return json.dumps({"code": 0}) except Exception as e: return json.dumps({"code": -1})
def sync_list(): try: timestamp = request.form['timestamp'] token = request.form['token'] if token != Tool.get_md5(app.config.get('TOKEN') + str(timestamp)): return 'Fail' sync_time = request.form['sync_time'] faces = FaceDao.list_new_faces(sync_time) if len(faces) > 0: return json.dumps({'code': 0, 'data': faces}) else: return json.dumps({'code': 1}) except Exception as e: return json.dumps({'code': -1})
def register(self): app_id = self.le_app_id.text().strip(' ') if app_id == '': self.btn_save.setText('请输入APP ID') self.le_app_id.setFocus() return security = self.le_security.text().strip(' ') if security == '': self.btn_save.setText('请输入密钥') self.le_security.setFocus() return self.btn_save.setDisabled(True) result, data = Tool.client_register(app_id, Tool.get_md5(security)) if result: DbHelper.insert_client(data, app_id, security) self.le_app_id.setDisabled(True) self.le_security.setDisabled(True) self.btn_save.setText("注册成功") elif data is not None: self.btn_save.setDisabled(False) self.btn_save.setText(data) else: self.btn_save.setDisabled(False) self.btn_save.setText("注册失败")
def login(self): app_id = self.le_app_id.text().strip(' ') if app_id == '': self.btn_login.setText('请输入APP ID') self.le_app_id.setFocus() return security = self.le_security.text().strip(' ') if security == '': self.btn_login.setText('请输入密钥') self.le_security.setFocus() return self.btn_login.setDisabled(True) result, data = Tool.client_login(app_id, Tool.get_md5(security)) if result: DbHelper.insert_client(data, app_id, security) self.btn_login.setText("已连接") self.le_app_id.setDisabled(True) self.le_security.setDisabled(True) self.btn_logout.setDisabled(False) self.btn_logout.setText("注销") self.btn_logout.setFocus() else: self.btn_login.setDisabled(False) self.btn_login.setText("APP ID或者密钥不正确")