Spaces:
Sleeping
Sleeping
Create login.py
Browse files
login.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import smtplib
|
| 3 |
+
import random
|
| 4 |
+
from email.mime.text import MIMEText
|
| 5 |
+
|
| 6 |
+
# -----------------------
|
| 7 |
+
# Email Configuration
|
| 8 |
+
# -----------------------
|
| 9 |
+
|
| 10 |
+
SENDER_EMAIL = "your_email@gmail.com"
|
| 11 |
+
SENDER_PASSWORD = "your_app_password"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# -----------------------
|
| 15 |
+
# Function to Send OTP
|
| 16 |
+
# -----------------------
|
| 17 |
+
|
| 18 |
+
def send_otp(email):
|
| 19 |
+
|
| 20 |
+
otp = random.randint(100000, 999999)
|
| 21 |
+
|
| 22 |
+
msg = MIMEText(f"Your FitPlan AI login OTP is: {otp}")
|
| 23 |
+
msg["Subject"] = "FitPlan AI Login OTP"
|
| 24 |
+
msg["From"] = SENDER_EMAIL
|
| 25 |
+
msg["To"] = email
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
server = smtplib.SMTP("smtp.gmail.com", 587)
|
| 29 |
+
server.starttls()
|
| 30 |
+
server.login(SENDER_EMAIL, SENDER_PASSWORD)
|
| 31 |
+
server.sendmail(SENDER_EMAIL, email, msg.as_string())
|
| 32 |
+
server.quit()
|
| 33 |
+
|
| 34 |
+
return otp
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
st.error("Email sending failed")
|
| 38 |
+
return None
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# -----------------------
|
| 42 |
+
# Streamlit UI
|
| 43 |
+
# -----------------------
|
| 44 |
+
|
| 45 |
+
st.set_page_config(page_title="FitPlan AI Login", page_icon="💪")
|
| 46 |
+
|
| 47 |
+
st.title("💪 FitPlan AI Login")
|
| 48 |
+
|
| 49 |
+
email = st.text_input("Enter your Email")
|
| 50 |
+
|
| 51 |
+
# Store OTP in session
|
| 52 |
+
if "otp" not in st.session_state:
|
| 53 |
+
st.session_state.otp = None
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# -----------------------
|
| 57 |
+
# Send OTP Button
|
| 58 |
+
# -----------------------
|
| 59 |
+
|
| 60 |
+
if st.button("Send OTP"):
|
| 61 |
+
|
| 62 |
+
if email:
|
| 63 |
+
|
| 64 |
+
otp = send_otp(email)
|
| 65 |
+
|
| 66 |
+
if otp:
|
| 67 |
+
st.session_state.otp = otp
|
| 68 |
+
st.success("OTP sent to your email")
|
| 69 |
+
|
| 70 |
+
else:
|
| 71 |
+
st.warning("Enter email first")
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# -----------------------
|
| 75 |
+
# Verify OTP
|
| 76 |
+
# -----------------------
|
| 77 |
+
|
| 78 |
+
user_otp = st.text_input("Enter OTP")
|
| 79 |
+
|
| 80 |
+
if st.button("Verify OTP"):
|
| 81 |
+
|
| 82 |
+
if st.session_state.otp and int(user_otp) == st.session_state.otp:
|
| 83 |
+
|
| 84 |
+
st.success("Login Successful 🎉")
|
| 85 |
+
|
| 86 |
+
st.write("Welcome to FitPlan AI")
|
| 87 |
+
|
| 88 |
+
else:
|
| 89 |
+
st.error("Invalid OTP")
|