Update app.py
Browse files
app.py
CHANGED
|
@@ -50,30 +50,39 @@ def authenticate_user(username, password):
|
|
| 50 |
|
| 51 |
# UI Layout
|
| 52 |
st.set_page_config(page_title="Construction To-Do List", layout="wide")
|
| 53 |
-
|
| 54 |
-
choice = st.sidebar.radio("Select Option", ["Sign In", "Sign Up"])
|
| 55 |
-
|
| 56 |
-
if choice == "Sign Up":
|
| 57 |
-
new_username = st.sidebar.text_input("Enter a username")
|
| 58 |
-
new_password = st.sidebar.text_input("Enter a password", type="password")
|
| 59 |
-
if st.sidebar.button("Register") and new_username and new_password:
|
| 60 |
-
register_user(new_username, new_password)
|
| 61 |
-
st.success("Registration successful! Please sign in.")
|
| 62 |
-
st.stop()
|
| 63 |
-
|
| 64 |
-
elif choice == "Sign In":
|
| 65 |
-
username = st.sidebar.text_input("Enter your username")
|
| 66 |
-
password = st.sidebar.text_input("Enter your password", type="password")
|
| 67 |
-
if st.sidebar.button("Login"):
|
| 68 |
-
if authenticate_user(username, password):
|
| 69 |
-
st.success("Login successful!")
|
| 70 |
-
else:
|
| 71 |
-
st.error("Invalid username or password")
|
| 72 |
-
st.stop()
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
if menu == "Dashboard":
|
| 79 |
st.title("🛠️ Construction Program Manager - Dashboard")
|
|
|
|
| 50 |
|
| 51 |
# UI Layout
|
| 52 |
st.set_page_config(page_title="Construction To-Do List", layout="wide")
|
| 53 |
+
init_db()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
if "authenticated" not in st.session_state:
|
| 56 |
+
st.session_state["authenticated"] = False
|
| 57 |
+
st.session_state["username"] = ""
|
| 58 |
+
|
| 59 |
+
if not st.session_state["authenticated"]:
|
| 60 |
+
st.title("🔐 User Authentication")
|
| 61 |
+
choice = st.radio("Select Option", ["Sign In", "Sign Up"])
|
| 62 |
+
|
| 63 |
+
if choice == "Sign Up":
|
| 64 |
+
new_username = st.text_input("Enter a username")
|
| 65 |
+
new_password = st.text_input("Enter a password", type="password")
|
| 66 |
+
if st.button("Register") and new_username and new_password:
|
| 67 |
+
register_user(new_username, new_password)
|
| 68 |
+
st.success("Registration successful! Please sign in.")
|
| 69 |
+
|
| 70 |
+
elif choice == "Sign In":
|
| 71 |
+
username = st.text_input("Enter your username")
|
| 72 |
+
password = st.text_input("Enter your password", type="password")
|
| 73 |
+
if st.button("Login"):
|
| 74 |
+
if authenticate_user(username, password):
|
| 75 |
+
st.session_state["authenticated"] = True
|
| 76 |
+
st.session_state["username"] = username
|
| 77 |
+
st.rerun()
|
| 78 |
+
else:
|
| 79 |
+
st.error("Invalid username or password")
|
| 80 |
+
st.stop()
|
| 81 |
|
| 82 |
+
# Main Dashboard After Login
|
| 83 |
+
st.sidebar.title(f"Welcome, {st.session_state['username']}")
|
| 84 |
+
menu = st.sidebar.radio("Go to", ["Dashboard", "View Tasks by Status"])
|
| 85 |
+
username = st.session_state['username']
|
| 86 |
|
| 87 |
if menu == "Dashboard":
|
| 88 |
st.title("🛠️ Construction Program Manager - Dashboard")
|