srbhavya01 commited on
Commit
75f9a29
·
verified ·
1 Parent(s): 6f24918

Update login.py

Browse files
Files changed (1) hide show
  1. login.py +12 -60
login.py CHANGED
@@ -1,89 +1,41 @@
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")
 
1
  import streamlit as st
 
2
  import random
3
+ from database import create_table, add_user
4
 
5
+ create_table()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  st.title("💪 FitPlan AI Login")
8
 
9
+ email = st.text_input("Enter Email")
10
 
 
11
  if "otp" not in st.session_state:
12
  st.session_state.otp = None
13
 
14
+ # Generate OTP
 
 
 
 
15
  if st.button("Send OTP"):
16
 
17
  if email:
18
 
19
+ otp = random.randint(100000,999999)
20
+
21
+ st.session_state.otp = otp
22
+ st.success(f"Your OTP is: {otp}")
23
 
24
+ # Save user in database
25
+ add_user(email)
 
26
 
27
  else:
28
  st.warning("Enter email first")
29
 
30
 
 
 
 
 
31
  user_otp = st.text_input("Enter OTP")
32
 
33
  if st.button("Verify OTP"):
34
 
35
+ if str(st.session_state.otp) == user_otp:
36
 
37
+ st.session_state.logged_in = True
38
  st.success("Login Successful 🎉")
39
 
 
 
40
  else:
41
  st.error("Invalid OTP")