initial work
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
36
libs.py
Normal 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
38
main.py
Normal 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()
|
||||
Reference in New Issue
Block a user