Module_2 / login.py
srbhavya01's picture
Create login.py
5c1a508 verified
raw
history blame
1.82 kB
import streamlit as st
import smtplib
import random
from email.mime.text import MIMEText
# -----------------------
# Email Configuration
# -----------------------
SENDER_EMAIL = "your_email@gmail.com"
SENDER_PASSWORD = "your_app_password"
# -----------------------
# Function to Send OTP
# -----------------------
def send_otp(email):
otp = random.randint(100000, 999999)
msg = MIMEText(f"Your FitPlan AI login OTP is: {otp}")
msg["Subject"] = "FitPlan AI Login OTP"
msg["From"] = SENDER_EMAIL
msg["To"] = email
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(SENDER_EMAIL, SENDER_PASSWORD)
server.sendmail(SENDER_EMAIL, email, msg.as_string())
server.quit()
return otp
except Exception as e:
st.error("Email sending failed")
return None
# -----------------------
# Streamlit UI
# -----------------------
st.set_page_config(page_title="FitPlan AI Login", page_icon="๐Ÿ’ช")
st.title("๐Ÿ’ช FitPlan AI Login")
email = st.text_input("Enter your Email")
# Store OTP in session
if "otp" not in st.session_state:
st.session_state.otp = None
# -----------------------
# Send OTP Button
# -----------------------
if st.button("Send OTP"):
if email:
otp = send_otp(email)
if otp:
st.session_state.otp = otp
st.success("OTP sent to your email")
else:
st.warning("Enter email first")
# -----------------------
# Verify OTP
# -----------------------
user_otp = st.text_input("Enter OTP")
if st.button("Verify OTP"):
if st.session_state.otp and int(user_otp) == st.session_state.otp:
st.success("Login Successful ๐ŸŽ‰")
st.write("Welcome to FitPlan AI")
else:
st.error("Invalid OTP")