Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import firebase_admin
|
|
3 |
from firebase_admin import credentials, auth
|
4 |
import os
|
5 |
import json
|
|
|
|
|
6 |
# Load Firebase credentials from Hugging Face Secrets
|
7 |
firebase_creds = os.getenv("FIREBASE_CREDENTIALS")
|
8 |
if firebase_creds:
|
@@ -20,6 +22,22 @@ if "logged_in" not in st.session_state:
|
|
20 |
if "current_user" not in st.session_state:
|
21 |
st.session_state.current_user = None
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Callback for registration
|
24 |
def register_callback():
|
25 |
email = st.session_state.reg_email
|
@@ -28,9 +46,11 @@ def register_callback():
|
|
28 |
# Create a new user in Firebase
|
29 |
user = auth.create_user(email=email, password=password)
|
30 |
|
31 |
-
#
|
32 |
-
auth.generate_email_verification_link(email)
|
33 |
-
|
|
|
|
|
34 |
st.success("Registration successful! Please check your email to verify your account.")
|
35 |
except Exception as e:
|
36 |
st.error(f"Registration failed: {e}")
|
|
|
3 |
from firebase_admin import credentials, auth
|
4 |
import os
|
5 |
import json
|
6 |
+
import smtplib
|
7 |
+
from email.mime.text import MIMEText
|
8 |
# Load Firebase credentials from Hugging Face Secrets
|
9 |
firebase_creds = os.getenv("FIREBASE_CREDENTIALS")
|
10 |
if firebase_creds:
|
|
|
22 |
if "current_user" not in st.session_state:
|
23 |
st.session_state.current_user = None
|
24 |
|
25 |
+
# Function to send verification email
|
26 |
+
def send_verification_email(email, verification_link):
|
27 |
+
sender_email = "[email protected]"
|
28 |
+
sender_password = "your_email_password"
|
29 |
+
subject = "Verify Your Email"
|
30 |
+
body = f"Please click the link to verify your email: {verification_link}"
|
31 |
+
|
32 |
+
msg = MIMEText(body)
|
33 |
+
msg['Subject'] = subject
|
34 |
+
msg['From'] = sender_email
|
35 |
+
msg['To'] = email
|
36 |
+
|
37 |
+
with smtplib.SMTP_SSL('smtp.example.com', 465) as server:
|
38 |
+
server.login(sender_email, sender_password)
|
39 |
+
server.sendmail(sender_email, [email], msg.as_string())
|
40 |
+
|
41 |
# Callback for registration
|
42 |
def register_callback():
|
43 |
email = st.session_state.reg_email
|
|
|
46 |
# Create a new user in Firebase
|
47 |
user = auth.create_user(email=email, password=password)
|
48 |
|
49 |
+
# Generate email verification link
|
50 |
+
verification_link = auth.generate_email_verification_link(email)
|
51 |
+
|
52 |
+
# Send verification email
|
53 |
+
send_verification_email(email, verification_link)
|
54 |
st.success("Registration successful! Please check your email to verify your account.")
|
55 |
except Exception as e:
|
56 |
st.error(f"Registration failed: {e}")
|