Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,8 +23,21 @@ def send_email(to_email, otp):
|
|
| 23 |
payload = {
|
| 24 |
"sender": {"name": "StepToDeen", "email": GMAIL_USER},
|
| 25 |
"to": [{"email": to_email}],
|
| 26 |
-
"subject": "
|
| 27 |
-
"htmlContent": f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
response = requests.post(url, json=payload, headers=headers)
|
| 30 |
if response.status_code not in (200, 201):
|
|
@@ -37,16 +50,16 @@ def send_otp():
|
|
| 37 |
email = data.get('email', '').strip().lower()
|
| 38 |
|
| 39 |
if not email:
|
| 40 |
-
return jsonify({"success": False, "message": "
|
| 41 |
|
| 42 |
otp = str(random.randint(100000, 999999))
|
| 43 |
otp_store[email] = {"otp": otp, "expires": time.time() + 300}
|
| 44 |
|
| 45 |
try:
|
| 46 |
send_email(email, otp)
|
| 47 |
-
return jsonify({"success": True, "message": "
|
| 48 |
except Exception as e:
|
| 49 |
-
return jsonify({"success": False, "message": f"
|
| 50 |
|
| 51 |
|
| 52 |
@app.route('/verify-otp', methods=['POST'])
|
|
@@ -58,22 +71,22 @@ def verify_otp():
|
|
| 58 |
record = otp_store.get(email)
|
| 59 |
|
| 60 |
if not record:
|
| 61 |
-
return jsonify({"success": False, "message": "
|
| 62 |
|
| 63 |
if time.time() > record['expires']:
|
| 64 |
del otp_store[email]
|
| 65 |
-
return jsonify({"success": False, "message": "
|
| 66 |
|
| 67 |
if record['otp'] == code:
|
| 68 |
del otp_store[email]
|
| 69 |
-
return jsonify({"success": True, "message": "
|
| 70 |
|
| 71 |
-
return jsonify({"success": False, "message": "
|
| 72 |
|
| 73 |
|
| 74 |
@app.route('/')
|
| 75 |
def home():
|
| 76 |
-
return "OTP Server
|
| 77 |
|
| 78 |
|
| 79 |
if __name__ == '__main__':
|
|
|
|
| 23 |
payload = {
|
| 24 |
"sender": {"name": "StepToDeen", "email": GMAIL_USER},
|
| 25 |
"to": [{"email": to_email}],
|
| 26 |
+
"subject": "Your StepToDeen Verification Code",
|
| 27 |
+
"htmlContent": f"""
|
| 28 |
+
<div style="font-family: Arial, sans-serif; max-width: 480px; margin: auto; padding: 24px; border: 1px solid #e2e8f0; border-radius: 12px;">
|
| 29 |
+
<h2 style="color: #047857; text-align: center;">StepToDeen</h2>
|
| 30 |
+
<p style="font-size: 15px; color: #333;">Hello,</p>
|
| 31 |
+
<p style="font-size: 15px; color: #333;">Use the verification code below to continue:</p>
|
| 32 |
+
<div style="text-align: center; margin: 24px 0;">
|
| 33 |
+
<span style="font-size: 32px; font-weight: bold; letter-spacing: 6px; color: #047857; background: #f0fdf4; padding: 12px 24px; border-radius: 8px; display: inline-block;">{otp}</span>
|
| 34 |
+
</div>
|
| 35 |
+
<p style="font-size: 14px; color: #666;">This code will expire in <b>5 minutes</b>.</p>
|
| 36 |
+
<p style="font-size: 14px; color: #666;">If you didn't request this code, please ignore this email.</p>
|
| 37 |
+
<hr style="border: none; border-top: 1px solid #e2e8f0; margin: 20px 0;">
|
| 38 |
+
<p style="font-size: 12px; color: #999; text-align: center;">© StepToDeen — Do not share this code with anyone.</p>
|
| 39 |
+
</div>
|
| 40 |
+
"""
|
| 41 |
}
|
| 42 |
response = requests.post(url, json=payload, headers=headers)
|
| 43 |
if response.status_code not in (200, 201):
|
|
|
|
| 50 |
email = data.get('email', '').strip().lower()
|
| 51 |
|
| 52 |
if not email:
|
| 53 |
+
return jsonify({"success": False, "message": "Email is required"}), 400
|
| 54 |
|
| 55 |
otp = str(random.randint(100000, 999999))
|
| 56 |
otp_store[email] = {"otp": otp, "expires": time.time() + 300}
|
| 57 |
|
| 58 |
try:
|
| 59 |
send_email(email, otp)
|
| 60 |
+
return jsonify({"success": True, "message": "Verification code sent to your email"})
|
| 61 |
except Exception as e:
|
| 62 |
+
return jsonify({"success": False, "message": f"Error: {str(e)}"}), 500
|
| 63 |
|
| 64 |
|
| 65 |
@app.route('/verify-otp', methods=['POST'])
|
|
|
|
| 71 |
record = otp_store.get(email)
|
| 72 |
|
| 73 |
if not record:
|
| 74 |
+
return jsonify({"success": False, "message": "Request a code first"}), 400
|
| 75 |
|
| 76 |
if time.time() > record['expires']:
|
| 77 |
del otp_store[email]
|
| 78 |
+
return jsonify({"success": False, "message": "Code expired, request a new one"}), 400
|
| 79 |
|
| 80 |
if record['otp'] == code:
|
| 81 |
del otp_store[email]
|
| 82 |
+
return jsonify({"success": True, "message": "Verification successful"})
|
| 83 |
|
| 84 |
+
return jsonify({"success": False, "message": "Invalid code"}), 400
|
| 85 |
|
| 86 |
|
| 87 |
@app.route('/')
|
| 88 |
def home():
|
| 89 |
+
return "OTP Server is running ✅"
|
| 90 |
|
| 91 |
|
| 92 |
if __name__ == '__main__':
|