From 7f7b8733b698127c1537285bd631f633fe23406f Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 6 Jun 2024 19:40:41 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BB=AE=E3=81=A7=E3=82=AF=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=A2=E3=83=B3=E3=83=88=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 dislocker_client.py diff --git a/dislocker_client.py b/dislocker_client.py new file mode 100644 index 0000000..83e09ce --- /dev/null +++ b/dislocker_client.py @@ -0,0 +1,104 @@ +import psycopg2 +import os +import json +import customtkinter +from winotify import Notification, audio + +class App(customtkinter.CTk): + def __init__(self): + super().__init__() + + + self.title("Dislocker ロック中") + self.attributes('-fullscreen', True) + + Lock() + + def exit(self): + self.toast() + self.destroy() + + def toast(self): + resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resource") + success = Notification( + app_id='Dislocker', + title='ご協力ありがとうございます!', + msg='パスワード認証に成功しました。\n現在使われたパスワードは削除されます。', + icon=resource_path + r'\success.png' + ) + success.set_audio(audio.Default, loop=False) + success.show() + +class Lock(customtkinter.CTkToplevel): + def __init__(self): + super().__init__() + self.title('Dislocker | PC番号 10 | ロックされています') + self.geometry('400x500') + self.resizable(height=False, width=False) + self.lift() + + self.msg_title_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') + self.msg_title_frame.grid(row=0, column=0, sticky="nsew") + + self.msg_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text='ちょっと待って!!') + self.msg_title_1.grid(row=0, column=0, padx=10, pady=10) + + self.msg_subtitle_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') + self.msg_subtitle_frame.grid(row=1, column=0, sticky="nsew") + + self.msg_subtitle_1 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='サインインするには、パスワードが必要です。') + self.msg_subtitle_1.grid(row=0, column=0, padx=10, pady=10) + + self.input_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') + self.input_frame.grid(row=2, column=0, sticky="nsew") + + self.password_entry = customtkinter.CTkEntry(self.input_frame, placeholder_text='パスワード', width=380) + self.password_entry.grid(row=0, column=0, padx=10, pady=10) + + self.button_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') + self.button_frame.grid(row=3, column=0, sticky="nsew") + + self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth) + self.signin_button.grid(row=0, column=0, padx=10, pady=10) + + def auth(self): + self.db = psycopg2.connect(f"host={db_config["host"]} dbname={db_config["db"]} port={db_config["port"]} user={db_config["username"]} password={db_config["password"]}") + cursor = self.db.cursor() + cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (10,)) + pc_info = cursor.fetchall() + auth_password = str(self.password_entry.get()) + if pc_info[0][2] == auth_password: + cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (10,)) + app.notify() + self.db.commit() + self.destroy() + app.exit() + else: + self.msg_subtitle_1.configure(text='サインインするには、パスワードが必要です。\nパスワードが違います!') + + + + + +config_dir_path = "./config/" +db_config_path = config_dir_path + "db.json" +if not os.path.isfile(db_config_path): + if not os.path.isdir(config_dir_path): + os.mkdir(config_dir_path) + + db_config = { + "host": "localhost", + "db": "dislocker", + "username": "user", + "password": "example_pass", + "port": "5432" + } + with open(db_config_path, "w") as w: + json.dump(db_config, w, indent=4) +elif os.path.isfile(db_config_path): + with open(db_config_path, "r") as r: + db_config = json.load(r) + +if __name__ == '__main__': + app = App() + app.mainloop()