Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
st.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
"""
|
37 |
-
st.
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import json
|
3 |
+
|
4 |
+
st.set_page_config(page_title="Reminder App", page_icon=":bell:", layout="centered")
|
5 |
+
|
6 |
+
login, signup = st.tabs(["Login", "Signup"])
|
7 |
+
|
8 |
+
|
9 |
+
@st.cache_data
|
10 |
+
def loadFile():
|
11 |
+
with open("database/test.json") as json_file:
|
12 |
+
return json.load(json_file)
|
13 |
+
|
14 |
+
|
15 |
+
def saveFile(data):
|
16 |
+
with open("database/test.json", "w") as file:
|
17 |
+
json.dump(data, file, indent=4)
|
18 |
+
|
19 |
+
def LoginPage():
|
20 |
+
st.title("Login")
|
21 |
+
username = st.text_input("Username", key="username")
|
22 |
+
password = st.text_input("Password", type="password", key="password")
|
23 |
+
if st.button("Login"):
|
24 |
+
data = loadFile()
|
25 |
+
for user in data["users"]:
|
26 |
+
if username == user["username"] and password == user["password"]:
|
27 |
+
st.success("Logged in as {}".format(username))
|
28 |
+
st.balloons()
|
29 |
+
else:
|
30 |
+
st.error("Incorrect username or password")
|
31 |
+
|
32 |
+
def SignupPage():
|
33 |
+
st.title("Signup")
|
34 |
+
username = st.text_input("Username", key="svusername")
|
35 |
+
email = st.text_input("Email", key="svemail")
|
36 |
+
password = st.text_input("Password", type="password", key="svpassword")
|
37 |
+
if st.button("Signup"):
|
38 |
+
data = loadFile()
|
39 |
+
data["users"].append({"username": username, "password": password, "email": email})
|
40 |
+
saveFile(data)
|
41 |
+
st.success("Successfully signed up as {}".format(username))
|
42 |
+
|
43 |
+
with login:
|
44 |
+
LoginPage()
|
45 |
+
|
46 |
+
with signup:
|
47 |
+
SignupPage()
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|