addind authentication
Browse files- .gitignore +3 -0
- app.py +152 -46
.gitignore
CHANGED
|
@@ -8,3 +8,6 @@ __pycache__
|
|
| 8 |
|
| 9 |
# windsurf rules
|
| 10 |
.windsurfrules
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# windsurf rules
|
| 10 |
.windsurfrules
|
| 11 |
+
|
| 12 |
+
# secrets
|
| 13 |
+
.streamlit/secrets.toml
|
app.py
CHANGED
|
@@ -1,48 +1,154 @@
|
|
| 1 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
|
| 4 |
+
# Authentication function
|
| 5 |
+
def check_password():
|
| 6 |
+
"""Returns `True` if the user had the correct password."""
|
| 7 |
+
|
| 8 |
+
def password_entered():
|
| 9 |
+
"""Checks whether a password entered by the user is correct."""
|
| 10 |
+
if (
|
| 11 |
+
st.session_state["username"] == st.secrets["username"]
|
| 12 |
+
and st.session_state["password"] == st.secrets["password"]
|
| 13 |
+
):
|
| 14 |
+
st.session_state["password_correct"] = True
|
| 15 |
+
del st.session_state["password"] # don't store password
|
| 16 |
+
del st.session_state["username"] # don't store username
|
| 17 |
+
else:
|
| 18 |
+
st.session_state["password_correct"] = False
|
| 19 |
+
|
| 20 |
+
# Create a visually appealing login form
|
| 21 |
+
if (
|
| 22 |
+
"password_correct" not in st.session_state
|
| 23 |
+
or not st.session_state["password_correct"]
|
| 24 |
+
):
|
| 25 |
+
# Add custom CSS for styling
|
| 26 |
+
st.markdown(
|
| 27 |
+
"""
|
| 28 |
+
<style>
|
| 29 |
+
.login-container {
|
| 30 |
+
background-color: #f0f2f6;
|
| 31 |
+
padding: 30px;
|
| 32 |
+
border-radius: 10px;
|
| 33 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 34 |
+
margin-bottom: 20px;
|
| 35 |
+
text-align: center;
|
| 36 |
+
}
|
| 37 |
+
.login-title {
|
| 38 |
+
font-size: 24px;
|
| 39 |
+
font-weight: bold;
|
| 40 |
+
margin-bottom: 20px;
|
| 41 |
+
color: #0f52ba;
|
| 42 |
+
}
|
| 43 |
+
.login-subtitle {
|
| 44 |
+
font-size: 16px;
|
| 45 |
+
margin-bottom: 30px;
|
| 46 |
+
color: #555;
|
| 47 |
+
}
|
| 48 |
+
.stButton button {
|
| 49 |
+
background-color: #0f52ba;
|
| 50 |
+
color: white;
|
| 51 |
+
font-weight: bold;
|
| 52 |
+
border-radius: 5px;
|
| 53 |
+
padding: 10px 20px;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
""",
|
| 57 |
+
unsafe_allow_html=True,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Create a centered layout
|
| 61 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 62 |
+
|
| 63 |
+
with col2:
|
| 64 |
+
# Login container with title and subtitle
|
| 65 |
+
st.markdown(
|
| 66 |
+
"""
|
| 67 |
+
<div class="login-container">
|
| 68 |
+
<div class="login-title">NPO DB Query</div>
|
| 69 |
+
<div class="login-subtitle">Please log in to continue</div>
|
| 70 |
+
</div>
|
| 71 |
+
""",
|
| 72 |
+
unsafe_allow_html=True,
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# Show error message if login failed
|
| 76 |
+
if (
|
| 77 |
+
"password_correct" in st.session_state
|
| 78 |
+
and not st.session_state["password_correct"]
|
| 79 |
+
):
|
| 80 |
+
st.error("😕 User not known or password incorrect")
|
| 81 |
+
|
| 82 |
+
# Login form with improved input fields
|
| 83 |
+
st.text_input("Username", key="username", placeholder="Enter your username")
|
| 84 |
+
st.text_input(
|
| 85 |
+
"Password",
|
| 86 |
+
type="password",
|
| 87 |
+
key="password",
|
| 88 |
+
placeholder="Enter your password",
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
# Full-width login button
|
| 92 |
+
st.button("Login", on_click=password_entered, use_container_width=True)
|
| 93 |
+
|
| 94 |
+
return False
|
| 95 |
+
else:
|
| 96 |
+
# Password correct
|
| 97 |
+
return True
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# Only show the app if authentication is successful
|
| 101 |
+
if check_password():
|
| 102 |
+
st.set_page_config(
|
| 103 |
+
page_title="NPO DB Query",
|
| 104 |
+
page_icon="💻",
|
| 105 |
+
layout="wide",
|
| 106 |
+
initial_sidebar_state="expanded",
|
| 107 |
+
menu_items={
|
| 108 |
+
"About": "**📡 NPO DB Query v0.2.8**",
|
| 109 |
+
},
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
pages = {
|
| 113 |
+
"Apps": [
|
| 114 |
+
st.Page("apps/database_page.py", title="🏡Generate Databases"),
|
| 115 |
+
st.Page(
|
| 116 |
+
"apps/parameters_distribution.py", title="📊Parameters distribution"
|
| 117 |
+
),
|
| 118 |
+
st.Page("apps/core_dump_page.py", title="📠Parse dump core"),
|
| 119 |
+
st.Page("apps/gps_converter.py", title="🧭GPS Converter"),
|
| 120 |
+
st.Page("apps/distance.py", title="🛰Distance Calculator"),
|
| 121 |
+
st.Page(
|
| 122 |
+
"apps/multi_points_distance_calculator.py",
|
| 123 |
+
title=" 🗺 Multi Points Distance Calculator",
|
| 124 |
+
),
|
| 125 |
+
st.Page(
|
| 126 |
+
"apps/sector_kml_generator.py",
|
| 127 |
+
title="📡 Sector KML Generator",
|
| 128 |
+
),
|
| 129 |
+
st.Page(
|
| 130 |
+
"apps/import_physical_db.py", title="🌏Physical Database Verification"
|
| 131 |
+
),
|
| 132 |
+
],
|
| 133 |
+
"KPI Analysis": [
|
| 134 |
+
st.Page(
|
| 135 |
+
"apps/kpi_analysis/wbts_capacty.py",
|
| 136 |
+
title=" 📊 WBTS Capacity BB and CE Analysis",
|
| 137 |
+
),
|
| 138 |
+
st.Page(
|
| 139 |
+
"apps/kpi_analysis/gsm_capacity.py",
|
| 140 |
+
title=" 📊 GSM Capacity Analysis",
|
| 141 |
+
),
|
| 142 |
+
],
|
| 143 |
+
"Documentations": [
|
| 144 |
+
st.Page(
|
| 145 |
+
"documentations/database_doc.py", title="📚Databases Documentation"
|
| 146 |
+
),
|
| 147 |
+
st.Page(
|
| 148 |
+
"documentations/core_dump_doc.py", title="📗Dump core Documentation"
|
| 149 |
+
),
|
| 150 |
+
],
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
pg = st.navigation(pages)
|
| 154 |
+
pg.run()
|