-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
32 lines (32 loc) · 907 Bytes
/
backend.py
File metadata and controls
32 lines (32 loc) · 907 Bytes
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
import json
DATA_FILE = "users.json"
def load_data():
try:
with open(DATA_FILE,"r") as f:
return json.load(f)
except:
return {"users":[]}
def save_data(data):
with open(DATA_FILE,"w") as f:
json.dump(data, f, indent=4)
def create_account(name,email,password):
data = load_data()
email = email.lower()
for u in data.get("users",[]):
if u.get("email","").lower() == email:
return False
data["users"].append({
"name": name,
"email": email,
"password": password,
"role": "student"
})
save_data(data)
return True
def login_user(email,password):
data = load_data()
email = email.lower()
for u in data.get("users",[]):
if u.get("email","").lower() == email and u.get("password","") == password:
return u
return None