-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
109 lines (90 loc) · 3.49 KB
/
login.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import data as dat
import json
from appJar import gui
app = gui("pyOS Login", "360x250")
json_acc = open("accounts.json", "r", encoding="utf-8")
accounts = json.load(json_acc)
json_acc.close()
def update_accs(accs):
global accounts
accounts = accs
def cancel(button):
if button == "Cancel":
dat.user = "*"
app.stop()
def press(button):
if app.getRadioButton("select") == "Login":
dat.user = app.getEntry("Username")
pwd = app.getEntry("Password")
if check_user():
if check_passwd(pwd):
app.stop()
elif app.getRadioButton("select") == "Register":
dat.user = app.getEntry("Username")
register()
def select(radioButton):
if app.getRadioButton("select") == "Login":
app.showLabel("l3")
app.hideLabel("l4")
app.hideEntry("Repeat Password")
if app.getRadioButton("select") == "Register":
app.showLabel("l4")
app.showEntry("Repeat Password")
def check_passwd(passwd):
if passwd == accounts[dat.user]["passwd"]:
return True
else:
app.errorBox("Login Error", "The password you entered was not correct!")
return False
def check_user():
if len(accounts) > 0:
if dat.user in accounts:
dat.set_accs(accounts)
dat.set_user(dat.user)
return True
else:
app.errorBox("Login Error", "The username you entered does not exist!")
return False
else:
app.infoBox("No users!", "There are no accounts yet. Please register a new user!")
return False
def register():
if dat.user in accounts:
app.errorBox("Username Error", "Username already exists! Please choose another name.")
else:
dat.set_user(dat.user)
passwd = app.getEntry("Password")
check_passwd = app.getEntry("Repeat Password")
if not passwd == "":
if passwd == check_passwd:
data = {dat.user: {"passwd": passwd, "home": {}}}
accounts.update(data)
dat.set_accs(accounts)
json_acc = open("accounts.json", "w", encoding="utf-8")
json.dump(accounts, json_acc, ensure_ascii=False, indent=4)
json_acc.close()
app.stop()
print("Hello %s, your login was successfull." % dat.user.capitalize())
else:
app.errorBox("Password Error", "Passwords aren't matching! Please try again.")
else:
app.errorBox("Password Error", "You can't leave your password blank! Please enter something.")
def setup():
app.setBg("RoyalBlue1")
app.setSticky("")
app.setExpand("both")
app.addLabel("title", "pyOS Login Screen", colspan=2)
app.setLabelBg("title", "white")
app.addRadioButton("select", "Login", 1, 0)
app.addRadioButton("select", "Register", 1, 1)
app.setRadioButtonChangeFunction("select", select)
app.addLabel("l2", "Username", 2, 0)
app.addEntry("Username", 2, 1)
app.addLabel("l3", "Password", 3, 0)
app.addSecretEntry("Password", 3, 1)
app.addLabel("l4", "Repeat Password", 4, 0)
app.addSecretEntry("Repeat Password", 4, 1)
app.setRadioButton("select", "Login", callFunction=True)
app.addButton("Submit", press, 5, 0)
app.addButton("Cancel", cancel, 5, 1)
app.go()