From aebab83b866f3a502394f7b7bcef1e6fa79f329d Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 18:10:12 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AF=E3=83=B3=E3=82=BF=E3=82=A4=E3=83=A0?= =?UTF-8?q?=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE=E4=BB=95?= =?UTF-8?q?=E6=A7=98=E5=A4=89=E6=9B=B4=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_auth.py | 61 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/dislocker_auth.py b/dislocker_auth.py index a4b32be..0c08fcd 100644 --- a/dislocker_auth.py +++ b/dislocker_auth.py @@ -334,15 +334,29 @@ def register(): with open(onetime_config_path, "r") as r: onetime_config = json.load(r) - if onetime_password == onetime_config["onetime"]["pc_register"]: + if onetime_password == onetime_config["onetime"]["pc_register"]["password"]: register_result = auth.register(pc_number=pc_number, pc_uuid=pc_uuid) - pc_token = register_result["output_dict"]["pc_token"] - master_password = register_result["output_dict"]["master_password"] - master_password_hash = register_result["output_dict"]["master_password_hash"] - onetime_config["onetime"]["pc_register"] = None - with open(onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200 + if register_result["result"] == 0: + pc_token = register_result["output_dict"]["pc_token"] + master_password = register_result["output_dict"]["master_password"] + master_password_hash = register_result["output_dict"]["master_password_hash"] + onetime_config["onetime"]["pc_register"]["current_count"] += 1 + + if onetime_config["onetime"]["pc_register"]["current_count"] == onetime_config["onetime"]["pc_register"]["max_count"]: + onetime_config["onetime"]["pc_register"]["password"] = None + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200 + else: + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200 + elif register_result["result"] == 1: + if register_result["about"] == "exist": + return jsonify({'message': 'exist'}), 401 + else: + return jsonify({'message': 'damedesu'}), 401 + else: return jsonify({'message': 'damedesu'}), 401 else: @@ -410,22 +424,37 @@ def device_register(): device_register = auth.device_register(mode="keyboard", number=number, device_instance_path=device_instance_path, device_name=device_name) if device_register["result"] == 0: print(f"キーボード {number} 番の登録処理は成功しました.") - onetime_config["onetime"]["device_register"] = None - with open(onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - return jsonify({'message': 'ok'}), 200 + onetime_config["onetime"]["device_register"]["current_count"] += 1 + + if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]: + onetime_config["onetime"]["device_register"] = None + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 + else: + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 else: print(f"キーボード {number} 番の登録処理は失敗しました.") return jsonify({'message': 'error'}), 500 + elif mode == "mouse": print("マウスの登録処理を開始...") device_register = auth.device_register(mode="mouse", number=number, device_instance_path=device_instance_path, device_name=device_name) if device_register["result"] == 0: print(f"マウス {number} 番の登録処理は成功しました.") - onetime_config["onetime"]["device_register"] = None - with open(onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - return jsonify({'message': 'ok'}), 200 + onetime_config["onetime"]["device_register"]["current_count"] += 1 + + if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]: + onetime_config["onetime"]["device_register"] = None + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 + else: + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 else: print(f"マウス {number} 番の登録処理は失敗しました.") return jsonify({'message': 'error'}), 500