ワンタイムパスワードの仕様変更に対応

This commit is contained in:
suti7yk5032 2024-09-26 18:10:12 +09:00
parent 33dd3aef9b
commit aebab83b86

View file

@ -334,15 +334,29 @@ def register():
with open(onetime_config_path, "r") as r: with open(onetime_config_path, "r") as r:
onetime_config = json.load(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) register_result = auth.register(pc_number=pc_number, pc_uuid=pc_uuid)
pc_token = register_result["output_dict"]["pc_token"] if register_result["result"] == 0:
master_password = register_result["output_dict"]["master_password"] pc_token = register_result["output_dict"]["pc_token"]
master_password_hash = register_result["output_dict"]["master_password_hash"] master_password = register_result["output_dict"]["master_password"]
onetime_config["onetime"]["pc_register"] = None master_password_hash = register_result["output_dict"]["master_password_hash"]
with open(onetime_config_path, "w") as w: onetime_config["onetime"]["pc_register"]["current_count"] += 1
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 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: else:
return jsonify({'message': 'damedesu'}), 401 return jsonify({'message': 'damedesu'}), 401
else: 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) device_register = auth.device_register(mode="keyboard", number=number, device_instance_path=device_instance_path, device_name=device_name)
if device_register["result"] == 0: if device_register["result"] == 0:
print(f"キーボード {number} 番の登録処理は成功しました.") print(f"キーボード {number} 番の登録処理は成功しました.")
onetime_config["onetime"]["device_register"] = None onetime_config["onetime"]["device_register"]["current_count"] += 1
with open(onetime_config_path, "w") as w:
json.dump(onetime_config, w, indent=4) if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]:
return jsonify({'message': 'ok'}), 200 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: else:
print(f"キーボード {number} 番の登録処理は失敗しました.") print(f"キーボード {number} 番の登録処理は失敗しました.")
return jsonify({'message': 'error'}), 500 return jsonify({'message': 'error'}), 500
elif mode == "mouse": elif mode == "mouse":
print("マウスの登録処理を開始...") print("マウスの登録処理を開始...")
device_register = auth.device_register(mode="mouse", number=number, device_instance_path=device_instance_path, device_name=device_name) device_register = auth.device_register(mode="mouse", number=number, device_instance_path=device_instance_path, device_name=device_name)
if device_register["result"] == 0: if device_register["result"] == 0:
print(f"マウス {number} 番の登録処理は成功しました.") print(f"マウス {number} 番の登録処理は成功しました.")
onetime_config["onetime"]["device_register"] = None onetime_config["onetime"]["device_register"]["current_count"] += 1
with open(onetime_config_path, "w") as w:
json.dump(onetime_config, w, indent=4) if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]:
return jsonify({'message': 'ok'}), 200 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: else:
print(f"マウス {number} 番の登録処理は失敗しました.") print(f"マウス {number} 番の登録処理は失敗しました.")
return jsonify({'message': 'error'}), 500 return jsonify({'message': 'error'}), 500