Yogya12 commited on
Commit
d3a6507
·
1 Parent(s): aa77ae9
Files changed (1) hide show
  1. app.py +11 -31
app.py CHANGED
@@ -310,34 +310,19 @@ import os
310
  from email.message import EmailMessage
311
 
312
  def send_otp(email):
313
- otp = str(random.randint(100000, 999999)) # generate OTP
 
 
 
 
314
  otp_store[email] = {
315
  "otp": otp,
316
- "expires": datetime.now() + timedelta(minutes=10)
317
- }
318
-
319
- api_key = os.getenv("RESEND_API_KEY")
320
- sender = os.getenv("RESEND_SENDER", "onboarding@resend.dev")
321
-
322
- headers = {
323
- "Authorization": f"Bearer {api_key}",
324
- "Content-Type": "application/json"
325
- }
326
-
327
- data = {
328
- "from": sender,
329
- "to": [email],
330
- "subject": "Your OTP for EduMate",
331
- "text": f"Your OTP is: {otp}"
332
  }
333
 
334
- try:
335
- response = requests.post("https://api.resend.com/emails", headers=headers, json=data)
336
- response.raise_for_status()
337
- return True
338
- except Exception as e:
339
- print(f"❌ Resend Error: {e}")
340
- return False
341
 
342
  import json # add at top if not already
343
 
@@ -846,26 +831,21 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as app:
846
  btn_signup.click(on_signup, [email, pwd, username_box, agree_checkbox], status)
847
 
848
  def on_verify(em, otp_inp):
849
- em = sanitize_input(em)
850
- otp_inp = sanitize_input(otp_inp)
851
- otp_data = otp_store.get(em)
852
-
853
  if (
854
  otp_data and
855
  otp_inp == otp_data.get("otp") and
856
  datetime.now() < otp_data.get("expires")
857
  ):
858
- # OTP is valid — continue signup
859
  pw = otp_data.get("pw")
860
  un = otp_data.get("un")
861
  if pw and un:
862
  saved = save_user(em, pw, un)
863
  if saved:
864
  del otp_store[em]
 
865
  return "✅ Signup complete—please login"
866
- return "❌ User already exists or DB error"
867
 
868
- return "❌ Wrong OTP or expired"
869
 
870
 
871
 
 
310
  from email.message import EmailMessage
311
 
312
  def send_otp(email):
313
+ email = sanitize_input(email)
314
+ otp = str(random.randint(100000, 999999))
315
+ otp_data = otp_store.get(email, {})
316
+
317
+ # Preserve pw and un if already stored during signup
318
  otp_store[email] = {
319
  "otp": otp,
320
+ "expires": datetime.now() + timedelta(minutes=10),
321
+ "pw": otp_data.get("pw"),
322
+ "un": otp_data.get("un")
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  }
324
 
325
+ ...
 
 
 
 
 
 
326
 
327
  import json # add at top if not already
328
 
 
831
  btn_signup.click(on_signup, [email, pwd, username_box, agree_checkbox], status)
832
 
833
  def on_verify(em, otp_inp):
834
+
 
 
 
835
  if (
836
  otp_data and
837
  otp_inp == otp_data.get("otp") and
838
  datetime.now() < otp_data.get("expires")
839
  ):
 
840
  pw = otp_data.get("pw")
841
  un = otp_data.get("un")
842
  if pw and un:
843
  saved = save_user(em, pw, un)
844
  if saved:
845
  del otp_store[em]
846
+ user_email.update(value=em) # 🔥 this is critical!
847
  return "✅ Signup complete—please login"
 
848
 
 
849
 
850
 
851