認証用サーバーにつなぐように
This commit is contained in:
parent
32a183244f
commit
26902aa0b3
1 changed files with 22 additions and 21 deletions
|
@ -1,10 +1,11 @@
|
||||||
import psycopg2
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import customtkinter
|
import customtkinter
|
||||||
from winotify import Notification, audio
|
from winotify import Notification, audio
|
||||||
import keyboard
|
import keyboard
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import requests
|
||||||
|
import hashlib
|
||||||
|
|
||||||
class App(customtkinter.CTk):
|
class App(customtkinter.CTk):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -89,15 +90,18 @@ class Lock(customtkinter.CTkToplevel):
|
||||||
self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth)
|
self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth)
|
||||||
self.signin_button.grid(row=0, column=0, padx=10, pady=10)
|
self.signin_button.grid(row=0, column=0, padx=10, pady=10)
|
||||||
|
|
||||||
|
def hash_genarate(self, source):
|
||||||
|
hashed = hashlib.md5(source.encode())
|
||||||
|
return hashed.hexdigest()
|
||||||
|
|
||||||
def auth(self):
|
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"]}")
|
auth_url = client_config["auth_host_url"] + "/verify"
|
||||||
cursor = self.db.cursor()
|
auth_json = {
|
||||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (10,))
|
"pc_number": client_config["pc_number"],
|
||||||
pc_info = cursor.fetchall()
|
"password": self.hash_genarate(self.password_entry.get())
|
||||||
auth_password = str(self.password_entry.get())
|
}
|
||||||
if pc_info[0][2] == auth_password:
|
responce = requests.post(auth_url, json=auth_json)
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (10,))
|
if responce.status_code == 200:
|
||||||
self.db.commit()
|
|
||||||
self.destroy()
|
self.destroy()
|
||||||
app.exit()
|
app.exit()
|
||||||
else:
|
else:
|
||||||
|
@ -111,22 +115,19 @@ class Lock(customtkinter.CTkToplevel):
|
||||||
|
|
||||||
|
|
||||||
config_dir_path = "./config/"
|
config_dir_path = "./config/"
|
||||||
db_config_path = config_dir_path + "db.json"
|
client_config_path = config_dir_path + "client.json"
|
||||||
if not os.path.isfile(db_config_path):
|
if not os.path.isfile(client_config_path):
|
||||||
if not os.path.isdir(config_dir_path):
|
if not os.path.isdir(config_dir_path):
|
||||||
os.mkdir(config_dir_path)
|
os.mkdir(config_dir_path)
|
||||||
|
|
||||||
db_config = {
|
client_config = {
|
||||||
"host": "localhost",
|
"auth_host_url": "localhost",
|
||||||
"db": "dislocker",
|
"pc_number": ""
|
||||||
"username": "user",
|
|
||||||
"password": "example_pass",
|
|
||||||
"port": "5432"
|
|
||||||
}
|
}
|
||||||
with open(db_config_path, "w") as w:
|
with open(client_config_path, "w") as w:
|
||||||
json.dump(db_config, w, indent=4)
|
json.dump(client_config, w, indent=4)
|
||||||
elif os.path.isfile(db_config_path):
|
elif os.path.isfile(client_config_path):
|
||||||
with open(db_config_path, "r") as r:
|
with open(client_config_path, "r") as r:
|
||||||
db_config = json.load(r)
|
db_config = json.load(r)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue