存在しないPC番号の場合はINSERTでレコードを作るように

This commit is contained in:
suti7yk5032 2024-10-05 09:35:49 +09:00
parent d643e6d1ba
commit ee4061d10b

View file

@ -307,18 +307,29 @@ class Auth():
cursor.execute("SELECT pc_uuid FROM pc_list WHERE pc_number = %s", (pc_number,))
pc_record = cursor.fetchall()
pc_record_uuid = pc_record[0][0]
if pc_record_uuid == None:
cursor.execute("SELECT pc_number FROM pc_list WHERE pc_number = %s", (pc_number,))
pc_record = cursor.fetchall()
pc_record_number = pc_record[0][0]
if pc_record_number == None:
pc_token = self.token_generate(36)
master_password = self.master_password_generate(16)
master_password_hash = self.hash_genarate(master_password)
cursor.execute("UPDATE pc_list SET pc_uuid = %s, pc_token = %s, master_password = %s WHERE pc_number = %s", (pc_uuid, pc_token, master_password, pc_number))
cursor.execute("INSERT INTO pc_list (pc_number, pc_uuid, pc_token, master_password) VALUES (%s, %s, %s, %s)", (pc_number, pc_uuid, pc_token, master_password))
self.db.commit()
return {"result": 0, "about": "ok", "output_dict": {"pc_token": pc_token, "master_password": master_password, "master_password_hash": master_password_hash}}
else:
return {"result": 1, "about": "exist"}
if pc_record_uuid == None:
pc_token = self.token_generate(36)
master_password = self.master_password_generate(16)
master_password_hash = self.hash_genarate(master_password)
cursor.execute("UPDATE pc_list SET pc_uuid = %s, pc_token = %s, master_password = %s WHERE pc_number = %s", (pc_uuid, pc_token, master_password, pc_number))
self.db.commit()
return {"result": 0, "about": "ok", "output_dict": {"pc_token": pc_token, "master_password": master_password, "master_password_hash": master_password_hash}}
else:
return {"result": 1, "about": "exist"}
except Exception as error:
print("停止処理中にエラーが発生しました。\nエラー内容")
print("PCの登録処理中にエラーが発生しました。\nエラー内容")
print(str(error.__class__.__name__))
print(str(error.args))
print(str(error))