Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from bcrypt import hashpw, gensalt, checkpw
|
|
| 5 |
# Path to the Excel file for user storage
|
| 6 |
USER_FILE = "users.xlsx"
|
| 7 |
|
|
|
|
| 8 |
# Load users from Excel
|
| 9 |
def load_users():
|
| 10 |
try:
|
|
@@ -25,18 +26,19 @@ def save_users(users):
|
|
| 25 |
def signup_user(name, phone, email, password):
|
| 26 |
users = load_users()
|
| 27 |
if email in users:
|
| 28 |
-
return "Email already exists. Please use a different email.",
|
| 29 |
hashed_password = hashpw(password.encode(), gensalt()).decode()
|
| 30 |
users[email] = {"Name": name, "Phone": phone, "Email": email, "Password": hashed_password}
|
| 31 |
save_users(users)
|
| 32 |
-
return "Signup successful! Redirecting to login page...",
|
| 33 |
|
| 34 |
# Validate login
|
| 35 |
def validate_login(email, password):
|
| 36 |
users = load_users()
|
| 37 |
if email in users and checkpw(password.encode(), users[email]["Password"].encode()):
|
| 38 |
-
return "Login successful! Redirecting to menu page...",
|
| 39 |
-
return "Invalid email or password. Please try again.",
|
|
|
|
| 40 |
|
| 41 |
# Function to load the menu data
|
| 42 |
def load_menu():
|
|
@@ -258,30 +260,27 @@ modal_and_cart_js = """
|
|
| 258 |
"""
|
| 259 |
def app():
|
| 260 |
with gr.Blocks() as demo:
|
| 261 |
-
#
|
| 262 |
-
|
|
|
|
|
|
|
| 263 |
|
| 264 |
# Login Page
|
| 265 |
-
with gr.Row(visible=
|
| 266 |
gr.Markdown("### Login Page")
|
| 267 |
login_email = gr.Textbox(label="Email")
|
| 268 |
login_password = gr.Textbox(label="Password", type="password")
|
| 269 |
login_btn = gr.Button("Login")
|
| 270 |
login_message = gr.Label()
|
| 271 |
|
| 272 |
-
# Function to handle login
|
| 273 |
-
def login(email, password):
|
| 274 |
-
message, next_page = validate_login(email, password)
|
| 275 |
-
return message, next_page
|
| 276 |
-
|
| 277 |
login_btn.click(
|
| 278 |
-
|
| 279 |
inputs=[login_email, login_password],
|
| 280 |
-
outputs=[login_message,
|
| 281 |
)
|
| 282 |
|
| 283 |
# Signup Page
|
| 284 |
-
with gr.Row(visible=
|
| 285 |
gr.Markdown("### Signup Page")
|
| 286 |
name = gr.Textbox(label="Name")
|
| 287 |
phone = gr.Textbox(label="Phone Number")
|
|
@@ -290,21 +289,15 @@ def app():
|
|
| 290 |
signup_btn = gr.Button("Signup")
|
| 291 |
signup_message = gr.Label()
|
| 292 |
|
| 293 |
-
# Function to handle signup
|
| 294 |
-
def signup(name, phone, email, password):
|
| 295 |
-
message, next_page = signup_user(name, phone, email, password)
|
| 296 |
-
return message, next_page
|
| 297 |
-
|
| 298 |
signup_btn.click(
|
| 299 |
-
|
| 300 |
inputs=[name, phone, email, password],
|
| 301 |
-
outputs=[signup_message,
|
| 302 |
)
|
| 303 |
|
| 304 |
# Menu Page
|
| 305 |
-
with gr.Row(visible=
|
| 306 |
gr.Markdown("### Menu Page")
|
| 307 |
-
# Radio button for selecting preference
|
| 308 |
selected_preference = gr.Radio(
|
| 309 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 310 |
value="All",
|
|
|
|
| 5 |
# Path to the Excel file for user storage
|
| 6 |
USER_FILE = "users.xlsx"
|
| 7 |
|
| 8 |
+
# Load users from Excel
|
| 9 |
# Load users from Excel
|
| 10 |
def load_users():
|
| 11 |
try:
|
|
|
|
| 26 |
def signup_user(name, phone, email, password):
|
| 27 |
users = load_users()
|
| 28 |
if email in users:
|
| 29 |
+
return "Email already exists. Please use a different email.", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 30 |
hashed_password = hashpw(password.encode(), gensalt()).decode()
|
| 31 |
users[email] = {"Name": name, "Phone": phone, "Email": email, "Password": hashed_password}
|
| 32 |
save_users(users)
|
| 33 |
+
return "Signup successful! Redirecting to login page...", gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 34 |
|
| 35 |
# Validate login
|
| 36 |
def validate_login(email, password):
|
| 37 |
users = load_users()
|
| 38 |
if email in users and checkpw(password.encode(), users[email]["Password"].encode()):
|
| 39 |
+
return "Login successful! Redirecting to menu page...", gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
| 40 |
+
return "Invalid email or password. Please try again.", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 41 |
+
|
| 42 |
|
| 43 |
# Function to load the menu data
|
| 44 |
def load_menu():
|
|
|
|
| 260 |
"""
|
| 261 |
def app():
|
| 262 |
with gr.Blocks() as demo:
|
| 263 |
+
# Define visibility states
|
| 264 |
+
login_visible = gr.State(True)
|
| 265 |
+
signup_visible = gr.State(False)
|
| 266 |
+
menu_visible = gr.State(False)
|
| 267 |
|
| 268 |
# Login Page
|
| 269 |
+
with gr.Row(visible=login_visible):
|
| 270 |
gr.Markdown("### Login Page")
|
| 271 |
login_email = gr.Textbox(label="Email")
|
| 272 |
login_password = gr.Textbox(label="Password", type="password")
|
| 273 |
login_btn = gr.Button("Login")
|
| 274 |
login_message = gr.Label()
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
login_btn.click(
|
| 277 |
+
validate_login,
|
| 278 |
inputs=[login_email, login_password],
|
| 279 |
+
outputs=[login_message, login_visible, signup_visible, menu_visible],
|
| 280 |
)
|
| 281 |
|
| 282 |
# Signup Page
|
| 283 |
+
with gr.Row(visible=signup_visible):
|
| 284 |
gr.Markdown("### Signup Page")
|
| 285 |
name = gr.Textbox(label="Name")
|
| 286 |
phone = gr.Textbox(label="Phone Number")
|
|
|
|
| 289 |
signup_btn = gr.Button("Signup")
|
| 290 |
signup_message = gr.Label()
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
signup_btn.click(
|
| 293 |
+
signup_user,
|
| 294 |
inputs=[name, phone, email, password],
|
| 295 |
+
outputs=[signup_message, login_visible, signup_visible, menu_visible],
|
| 296 |
)
|
| 297 |
|
| 298 |
# Menu Page
|
| 299 |
+
with gr.Row(visible=menu_visible):
|
| 300 |
gr.Markdown("### Menu Page")
|
|
|
|
| 301 |
selected_preference = gr.Radio(
|
| 302 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 303 |
value="All",
|