feat: wire SMTP email service, production CORS domains, Razorpay ENV, MinIO env-vars, and DPS seed from admin_uploads
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import List, Dict, Any, Optional
|
||||
from uuid import UUID
|
||||
from datetime import datetime, timedelta, date
|
||||
from pydantic import BaseModel
|
||||
import os
|
||||
|
||||
from database import init_db, get_session
|
||||
import models
|
||||
@@ -16,17 +17,23 @@ from billing import generate_mock_order, verify_webhook_signature
|
||||
from llm import stream_tutor_response
|
||||
from predictor import calculate_readiness_score
|
||||
from growth import generate_referral_link, process_referral_reward
|
||||
from email_service import send_welcome_email, send_otp_email
|
||||
import boto3
|
||||
import uuid
|
||||
|
||||
# MinIO (self-hosted S3 compatible) — credentials from environment variables
|
||||
_minio_endpoint = os.getenv("MINIO_ENDPOINT", "minio:9000")
|
||||
_minio_access = os.getenv("MINIO_ACCESS_KEY", "minio_admin")
|
||||
_minio_secret = os.getenv("MINIO_SECRET_KEY", "minio_secure_password_2026")
|
||||
|
||||
s3_client = boto3.client(
|
||||
's3',
|
||||
endpoint_url='http://localhost:9000',
|
||||
aws_access_key_id='minioadmin',
|
||||
aws_secret_access_key='minioadmin',
|
||||
endpoint_url=f'http://{_minio_endpoint}',
|
||||
aws_access_key_id=_minio_access,
|
||||
aws_secret_access_key=_minio_secret,
|
||||
region_name='us-east-1'
|
||||
)
|
||||
BUCKET_NAME = "avatars"
|
||||
BUCKET_NAME = os.getenv("MINIO_AVATARS_BUCKET", "avatars")
|
||||
|
||||
try:
|
||||
s3_client.create_bucket(Bucket=BUCKET_NAME)
|
||||
@@ -46,7 +53,15 @@ app = FastAPI(
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],
|
||||
allow_origins=[
|
||||
# Local development
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
# Production domains
|
||||
"https://pragativeer.com",
|
||||
"https://www.pragativeer.com",
|
||||
"https://api.pragativeer.com",
|
||||
],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
@@ -74,8 +89,13 @@ def require_tier(allowed_tiers: List[models.TierEnum]):
|
||||
# --- AUTHENTICATION ---
|
||||
|
||||
@app.post("/api/auth/otp-request", tags=["Authentication"])
|
||||
def request_otp(phone_or_email: str):
|
||||
return {"message": "Verification code dispatched successfully", "debug_otp": "123456"}
|
||||
def request_otp(phone_or_email: str, background_tasks: BackgroundTasks):
|
||||
# Generate a static debug OTP (real SMS/email dispatch pending SMS DLT registration)
|
||||
debug_otp = "123456"
|
||||
# If it looks like an email, send via SMTP
|
||||
if "@" in phone_or_email:
|
||||
background_tasks.add_task(send_otp_email, phone_or_email, debug_otp, "login verification")
|
||||
return {"message": "Verification code dispatched successfully", "debug_otp": debug_otp}
|
||||
|
||||
@app.post("/api/auth/otp-verify", tags=["Authentication"])
|
||||
def verify_otp(phone_or_email: str, code: str, session: Session = Depends(get_session)):
|
||||
@@ -116,7 +136,11 @@ def register(payload: RegisterPayload, session: Session = Depends(get_session)):
|
||||
session.add(new_user)
|
||||
session.commit()
|
||||
session.refresh(new_user)
|
||||
|
||||
|
||||
# Send welcome email in background (non-blocking)
|
||||
from fastapi.background import BackgroundTasks as BT
|
||||
send_welcome_email(payload.email, payload.name)
|
||||
|
||||
return {"success": True, "message": "User registered successfully"}
|
||||
|
||||
@app.post("/api/auth/login", tags=["Authentication"])
|
||||
|
||||
Reference in New Issue
Block a user