DavMelchi commited on
Commit
2f25a51
·
1 Parent(s): bd3da99

addind authentication

Browse files
Files changed (2) hide show
  1. .gitignore +3 -0
  2. 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
- st.set_page_config(
4
- page_title="NPO DB Query",
5
- page_icon="💻",
6
- layout="wide",
7
- initial_sidebar_state="expanded",
8
- menu_items={
9
- "About": "**📡 NPO DB Query v0.2.8**",
10
- },
11
- )
12
-
13
-
14
- pages = {
15
- "Apps": [
16
- st.Page("apps/database_page.py", title="🏡Generate Databases"),
17
- st.Page("apps/parameters_distribution.py", title="📊Parameters distribution"),
18
- st.Page("apps/core_dump_page.py", title="📠Parse dump core"),
19
- st.Page("apps/gps_converter.py", title="🧭GPS Converter"),
20
- st.Page("apps/distance.py", title="🛰Distance Calculator"),
21
- st.Page(
22
- "apps/multi_points_distance_calculator.py",
23
- title=" 🗺 Multi Points Distance Calculator",
24
- ),
25
- st.Page(
26
- "apps/sector_kml_generator.py",
27
- title="📡 Sector KML Generator",
28
- ),
29
- st.Page("apps/import_physical_db.py", title="🌏Physical Database Verification"),
30
- ],
31
- "KPI Analysis": [
32
- st.Page(
33
- "apps/kpi_analysis/wbts_capacty.py",
34
- title=" 📊 WBTS Capacity BB and CE Analysis",
35
- ),
36
- st.Page(
37
- "apps/kpi_analysis/gsm_capacity.py",
38
- title=" 📊 GSM Capacity Analysis",
39
- ),
40
- ],
41
- "Documentations": [
42
- st.Page("documentations/database_doc.py", title="📚Databases Documentation"),
43
- st.Page("documentations/core_dump_doc.py", title="📗Dump core Documentation"),
44
- ],
45
- }
46
-
47
- pg = st.navigation(pages)
48
- pg.run()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()