認証用サーバーにつなぐように
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 json
|
||||
import customtkinter
|
||||
from winotify import Notification, audio
|
||||
import keyboard
|
||||
import subprocess
|
||||
import requests
|
||||
import hashlib
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
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.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):
|
||||
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,))
|
||||
self.db.commit()
|
||||
auth_url = client_config["auth_host_url"] + "/verify"
|
||||
auth_json = {
|
||||
"pc_number": client_config["pc_number"],
|
||||
"password": self.hash_genarate(self.password_entry.get())
|
||||
}
|
||||
responce = requests.post(auth_url, json=auth_json)
|
||||
if responce.status_code == 200:
|
||||
self.destroy()
|
||||
app.exit()
|
||||
else:
|
||||
|
@ -111,22 +115,19 @@ class Lock(customtkinter.CTkToplevel):
|
|||
|
||||
|
||||
config_dir_path = "./config/"
|
||||
db_config_path = config_dir_path + "db.json"
|
||||
if not os.path.isfile(db_config_path):
|
||||
client_config_path = config_dir_path + "client.json"
|
||||
if not os.path.isfile(client_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"
|
||||
client_config = {
|
||||
"auth_host_url": "localhost",
|
||||
"pc_number": ""
|
||||
}
|
||||
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:
|
||||
with open(client_config_path, "w") as w:
|
||||
json.dump(client_config, w, indent=4)
|
||||
elif os.path.isfile(client_config_path):
|
||||
with open(client_config_path, "r") as r:
|
||||
db_config = json.load(r)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue