initial work

This commit is contained in:
ovosimpatico
2023-11-11 22:25:32 -03:00
parent 2b587d4f48
commit 819b5ffdd6
3 changed files with 75 additions and 0 deletions

1
.gitignore vendored
View File

@@ -160,3 +160,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
db.json

36
libs.py Normal file
View File

@@ -0,0 +1,36 @@
import json
def write_json(key, value):
path = 'db.json'
with open(path,'r') as jsonfile:
datafile = json.load(jsonfile)
datafile[key] = value
with open(path,'w') as jsonfile:
json.dump(datafile, jsonfile, indent=4, sort_keys=True)
def read_json():
path = 'db.json'
with open(path,'r') as jsonfile:
datafile = json.load(jsonfile)
return datafile
def read_json_value(key):
path = 'db.json'
with open(path, 'r') as jsonfile:
datafile = json.load(jsonfile)
if key in datafile:
return datafile[key]
else:
return None
def verify_equal(string1, string2):
return True if string1 == string2 else False
def validate_login(username, password):
if username == read_json_value("username"):
if password == read_json_value("password"):
return True
return False
return False

38
main.py Normal file
View File

@@ -0,0 +1,38 @@
import PySimpleGUI as sg
import time
from libs import *
def login():
sg.theme('DarkAmber')
# Define the window's contents
layout = [[sg.Text("Nome de usuário")],
[sg.Input(key='-username-')],
[sg.Text("Senha")],
[sg.Input(key='-password-', password_char='*')],
[sg.Text(size=(40,1), key='-text-')],
[sg.Button('Login'), sg.Button('Sair')]]
# Create the window
window = sg.Window('Login', layout)
# Display and interact with the Window using an Event Loop
while True:
event, values = window.read()
# See if user wants to quit or window was closed
if event == sg.WINDOW_CLOSED or event == 'Sair':
break
if validate_login(values['-username-'], values['-password-']):
print("loginff")
else:
window['-text-'].update('Nome de usuário ou senha incorretos!')
window.refresh()
time.sleep(2)
window['-text-'].update('')
# Finish up by removing from the screen
window.close()
# login()