Files
PVHBackend/api/email.py
T
Black_Raven b20eb2ed0c fix(Blueprints) way of api
Now /api is creating reverse proxy
2026-04-02 12:37:58 +03:00

30 lines
1007 B
Python

from flask import jsonify, request
from utils.mail import send_lead_to_email
from flask import Blueprint
# Создаем blueprint для API
api_email = Blueprint('api_email', __name__, url_prefix='/email')
@api_email.route('/', methods=['POST'])
def post_email():
if not request.is_json:
return jsonify({"error": "Content-Type must be application/json"}), 400
data = request.get_json()
# Извлекаем поля с проверкой наличия
name = data.get('name')
phone = data.get('phone')
email = data.get('email')
if not name or not phone or not email:
return jsonify({"error": "Missing required fields: name, phone, email"}), 400
# Отправляем заявку на почту
success = send_lead_to_email(name, phone, email)
if success:
return jsonify({"status": "success", "message": "Lead sent successfully"}), 200
else:
return jsonify({"status": "error", "message": "Failed to send email"}), 500