Spaces:
Sleeping
Sleeping
Commit
Β·
01b734e
1
Parent(s):
8496050
Add user auth
Browse files- .gitignore +2 -1
- app.py +46 -34
- menu.py +3 -1
- pages/explore.py +15 -0
- pages/input.py +15 -0
- requirements.txt +2 -1
.gitignore
CHANGED
@@ -6,4 +6,5 @@
|
|
6 |
__pycache__/
|
7 |
|
8 |
# Ignore secrets
|
9 |
-
.streamlit/secrets.toml
|
|
|
|
6 |
__pycache__/
|
7 |
|
8 |
# Ignore secrets
|
9 |
+
.streamlit/secrets.toml
|
10 |
+
.streamlit/gravity-user-db.json
|
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import hmac
|
3 |
|
4 |
# Standard imports
|
@@ -50,36 +51,47 @@ def check_password():
|
|
50 |
|
51 |
def password_entered():
|
52 |
"""Checks whether a password entered by the user is correct."""
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
)
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
# Check if the
|
68 |
-
if
|
69 |
-
st.session_state["
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
# Check if username is in a team
|
74 |
-
if st.session_state["username"] in st.secrets["teams"]:
|
75 |
-
st.session_state["team"] = st.secrets["teams"][st.session_state["username"]]
|
76 |
else:
|
77 |
-
st.session_state["
|
78 |
|
79 |
-
# Don't store the username or password
|
80 |
-
del st.session_state["password"]
|
81 |
-
# del st.session_state["username"]
|
82 |
else:
|
|
|
83 |
st.session_state["password_correct"] = False
|
84 |
|
85 |
# Return True if the username + password is validated
|
@@ -89,16 +101,16 @@ def check_password():
|
|
89 |
# Show inputs for username + password
|
90 |
login_form()
|
91 |
if "password_correct" in st.session_state:
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
return False
|
94 |
|
95 |
-
# # Selectbox to choose role
|
96 |
-
# st.selectbox(
|
97 |
-
# "Select your role:",
|
98 |
-
# [None, "user", "admin", "super-admin"],
|
99 |
-
# key="_role",
|
100 |
-
# on_change=set_role,
|
101 |
-
# )
|
102 |
menu() # Render the dynamic menu!
|
103 |
|
104 |
if not check_password():
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit_gsheets import GSheetsConnection
|
3 |
import hmac
|
4 |
|
5 |
# Standard imports
|
|
|
51 |
|
52 |
def password_entered():
|
53 |
"""Checks whether a password entered by the user is correct."""
|
54 |
+
|
55 |
+
# Create a connection object to Google Sheets
|
56 |
+
conn = st.connection("gsheets", type=GSheetsConnection)
|
57 |
+
|
58 |
+
# Read the user database
|
59 |
+
user_db = conn.read()
|
60 |
+
user_db.dropna(axis=0, how="all", inplace=True)
|
61 |
+
user_db.dropna(axis=1, how="all", inplace=True)
|
62 |
+
|
63 |
+
# Check if the username is in the database
|
64 |
+
if st.session_state["username"] in user_db.username.values:
|
65 |
+
|
66 |
+
st.session_state["username_correct"] = True
|
67 |
+
|
68 |
+
# Check if the password is correct
|
69 |
+
if hmac.compare_digest(
|
70 |
+
st.session_state["password"],
|
71 |
+
user_db.loc[user_db.username == st.session_state["username"], "password"].values[0],
|
72 |
+
):
|
73 |
+
|
74 |
+
st.session_state["password_correct"] = True
|
75 |
+
|
76 |
+
# Check if the username is an admin
|
77 |
+
if st.session_state["username"] in user_db[user_db.role == "admin"].username.values:
|
78 |
+
st.session_state["role"] = "admin"
|
79 |
+
else:
|
80 |
+
st.session_state["role"] = "user"
|
81 |
+
|
82 |
+
# Retrieve and store user name and team
|
83 |
+
st.session_state["name"] = user_db.loc[user_db.username == st.session_state["username"], "name"].values[0]
|
84 |
+
st.session_state["team"] = user_db.loc[user_db.username == st.session_state["username"], "team"].values[0]
|
85 |
+
|
86 |
+
# Don't store the username or password
|
87 |
+
del st.session_state["password"]
|
88 |
+
# del st.session_state["username"]
|
89 |
|
|
|
|
|
|
|
90 |
else:
|
91 |
+
st.session_state["password_correct"] = False
|
92 |
|
|
|
|
|
|
|
93 |
else:
|
94 |
+
st.session_state["username_correct"] = False
|
95 |
st.session_state["password_correct"] = False
|
96 |
|
97 |
# Return True if the username + password is validated
|
|
|
101 |
# Show inputs for username + password
|
102 |
login_form()
|
103 |
if "password_correct" in st.session_state:
|
104 |
+
|
105 |
+
if not st.session_state["username_correct"]:
|
106 |
+
st.error("User not found.")
|
107 |
+
elif not st.session_state["password_correct"]:
|
108 |
+
st.error("The password you entered is incorrect.")
|
109 |
+
else:
|
110 |
+
st.error("An unexpected error occurred.")
|
111 |
+
|
112 |
return False
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
menu() # Render the dynamic menu!
|
115 |
|
116 |
if not check_password():
|
menu.py
CHANGED
@@ -7,7 +7,9 @@ def authenticated_menu():
|
|
7 |
# Show a navigation menu for authenticated users
|
8 |
# st.sidebar.page_link("app.py", label="Switch Accounts", icon="π")
|
9 |
st.sidebar.page_link("pages/user.py", label="Profile", icon="π€")
|
10 |
-
st.sidebar.page_link("pages/
|
|
|
|
|
11 |
if st.session_state.role in ["admin"]:
|
12 |
st.sidebar.page_link("pages/admin.py", label="Manage Users", icon="π§")
|
13 |
|
|
|
7 |
# Show a navigation menu for authenticated users
|
8 |
# st.sidebar.page_link("app.py", label="Switch Accounts", icon="π")
|
9 |
st.sidebar.page_link("pages/user.py", label="Profile", icon="π€")
|
10 |
+
st.sidebar.page_link("pages/input.py", label="Input", icon="π‘")
|
11 |
+
st.sidebar.page_link("pages/validate.py", label="Validate", icon="β
")
|
12 |
+
st.sidebar.page_link("pages/explore.py", label="Explore", icon="π")
|
13 |
if st.session_state.role in ["admin"]:
|
14 |
st.sidebar.page_link("pages/admin.py", label="Manage Users", icon="π§")
|
15 |
|
pages/explore.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from menu import menu_with_redirect
|
3 |
+
|
4 |
+
# Path manipulation
|
5 |
+
from pathlib import Path
|
6 |
+
import sys
|
7 |
+
|
8 |
+
# Custom and other imports
|
9 |
+
import project_config
|
10 |
+
from utils import add_logo
|
11 |
+
|
12 |
+
# Redirect to app.py if not logged in, otherwise show the navigation menu
|
13 |
+
menu_with_redirect()
|
14 |
+
|
15 |
+
st.title("Explore")
|
pages/input.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from menu import menu_with_redirect
|
3 |
+
|
4 |
+
# Path manipulation
|
5 |
+
from pathlib import Path
|
6 |
+
import sys
|
7 |
+
|
8 |
+
# Custom and other imports
|
9 |
+
import project_config
|
10 |
+
from utils import add_logo
|
11 |
+
|
12 |
+
# Redirect to app.py if not logged in, otherwise show the navigation menu
|
13 |
+
menu_with_redirect()
|
14 |
+
|
15 |
+
st.title("Input")
|
requirements.txt
CHANGED
@@ -5,4 +5,5 @@ matplotlib
|
|
5 |
seaborn
|
6 |
pathlib
|
7 |
torch
|
8 |
-
altair<5
|
|
|
|
5 |
seaborn
|
6 |
pathlib
|
7 |
torch
|
8 |
+
altair<5
|
9 |
+
st-gsheets-connection
|