fix(auth): restrict seeded credentials exclusively to super admin and demo student in backend and api documentation
This commit is contained in:
@@ -169,7 +169,7 @@ FastAPI dependency `require_tier(allowed_tiers: List[models.TierEnum])` inspects
|
|||||||
- **Request Headers:**
|
- **Request Headers:**
|
||||||
- `Accept: application/json`
|
- `Accept: application/json`
|
||||||
- **Request Query Parameters:**
|
- **Request Query Parameters:**
|
||||||
- `phone_or_email` (string, required): e.g. `9876543210` or `student@pragativeer.com`
|
- `phone_or_email` (string, required): e.g. `9876543210` or `demo@pragativeer.com`
|
||||||
- **Response Headers:**
|
- **Response Headers:**
|
||||||
- `Content-Type: application/json`
|
- `Content-Type: application/json`
|
||||||
- **Status Codes & Response Payloads:**
|
- **Status Codes & Response Payloads:**
|
||||||
@@ -233,7 +233,7 @@ PragatiVeer v2 enforces a strict single-device login policy:
|
|||||||
{
|
{
|
||||||
"id": "b0e17378-864d-439e-8806-708dc48a891b",
|
"id": "b0e17378-864d-439e-8806-708dc48a891b",
|
||||||
"phone": "9999999999",
|
"phone": "9999999999",
|
||||||
"email": "student@pragativeer.com",
|
"email": "demo@pragativeer.com",
|
||||||
"name": "Rahul Sharma",
|
"name": "Rahul Sharma",
|
||||||
"student_class": "12",
|
"student_class": "12",
|
||||||
"medium": "English",
|
"medium": "English",
|
||||||
@@ -1156,7 +1156,7 @@ All Admin endpoints require superadmin access:
|
|||||||
- **Request Body Schema:**
|
- **Request Body Schema:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"email": "student@pragativeer.com"
|
"email": "demo@pragativeer.com"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- **Response Headers:**
|
- **Response Headers:**
|
||||||
@@ -1205,15 +1205,12 @@ The following endpoints are specified in [PRD.md](file:///c:/Users/naman/OneDriv
|
|||||||
| **Study Materials Library** | `GET /api/materials` | [materials/page.tsx](file:///c:/Users/naman/OneDrive/Desktop/pragativeer-v2/src/app/dashboard/materials/page.tsx) | MinIO PDF formula sheet catalog and access controls |
|
| **Study Materials Library** | `GET /api/materials` | [materials/page.tsx](file:///c:/Users/naman/OneDrive/Desktop/pragativeer-v2/src/app/dashboard/materials/page.tsx) | MinIO PDF formula sheet catalog and access controls |
|
||||||
| **Voice AI & Live Battle** | `/ws/battles`, `/api/ai-coach/voice` | Future Scope | WebSockets for multiplayer CBT battles & Whisper voice |
|
| **Voice AI & Live Battle** | `/ws/battles`, `/api/ai-coach/voice` | Future Scope | WebSockets for multiplayer CBT battles & Whisper voice |
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. Seeded Credentials Reference
|
## 5. Seeded Credentials Reference
|
||||||
|
|
||||||
|
The platform provides two pre-configured accounts for administration and end-to-end evaluation:
|
||||||
|
|
||||||
| Role | Email | Password | Tier / Features |
|
| Role | Email | Password | Tier / Features |
|
||||||
| :--- | :--- | :--- | :--- |
|
| :--- | :--- | :--- | :--- |
|
||||||
| **AI Coach Student** | `demo@pragativeer.com` | `Pv9#kL2$mQ8!vX4@` | AI Coach (AI Tutor, College Predictor, Spaced Repetition) |
|
| **Super Admin** | `admin@pragativeer.com` | `admin123` | Full access to `/admin` management console & question bank |
|
||||||
| **AI Coach Student** | `student@pragativeer.com` | `Password123!` | Rahul Sharma (Default AI Coach Profile) |
|
| **AI Coach Student** | `demo@pragativeer.com` | `Pv9#kL2$mQ8!vX4@` | Full AI Coach access (AI Tutor SSE stream, College Predictor, CBT Mock Engine, Spaced Repetition) |
|
||||||
| **AI Coach Student** | `neha@pragativeer.com` | `Password123!` | Neha Verma (62-Day Streak presentation account) |
|
|
||||||
| **Pro Tier Student** | `pro@pragativeer.com` | `Password123!` | Priya Singh (Pro Tier, Full CBT engine access) |
|
|
||||||
| **Free Tier Student** | `free@pragativeer.com` | `Password123!` | Amit Kumar (Free Tier, baseline practice) |
|
|
||||||
| **Super Admin** | `admin@pragativeer.com` | `admin123` | Full access to `/admin` management console |
|
|
||||||
|
|||||||
@@ -125,7 +125,11 @@ def login(payload: LoginPayload, session: Session = Depends(get_session)):
|
|||||||
|
|
||||||
# Allow demo/admin mock logic to still work if needed
|
# Allow demo/admin mock logic to still work if needed
|
||||||
if payload.email == "demo@pragativeer.com" and payload.password == "Pv9#kL2$mQ8!vX4@":
|
if payload.email == "demo@pragativeer.com" and payload.password == "Pv9#kL2$mQ8!vX4@":
|
||||||
demo_user = session.exec(select(models.User).where(models.User.email == "student@pragativeer.com")).first()
|
demo_user = session.exec(select(models.User).where((models.User.email == "demo@pragativeer.com") | (models.User.email == "student@pragativeer.com"))).first()
|
||||||
|
if demo_user and demo_user.email != "demo@pragativeer.com":
|
||||||
|
demo_user.email = "demo@pragativeer.com"
|
||||||
|
session.add(demo_user)
|
||||||
|
session.commit()
|
||||||
token_id = str(demo_user.id) if demo_user else "b0e17378-864d-439e-8806-708dc48a891b"
|
token_id = str(demo_user.id) if demo_user else "b0e17378-864d-439e-8806-708dc48a891b"
|
||||||
return {"success": True, "role": "user", "token": token_id}
|
return {"success": True, "role": "user", "token": token_id}
|
||||||
if payload.email == "admin@pragativeer.com" and payload.password == "admin123":
|
if payload.email == "admin@pragativeer.com" and payload.password == "admin123":
|
||||||
|
|||||||
107
backend/seed.py
107
backend/seed.py
@@ -28,110 +28,73 @@ def seed_local_database():
|
|||||||
print("Seeding baseline content entities...")
|
print("Seeding baseline content entities...")
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# 0. Create the baseline student users (Free, Pro, AI Coach)
|
# 1. Super Admin User
|
||||||
free_student_id = UUID("11111111-1111-1111-1111-111111111111")
|
admin_id = UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
|
||||||
free_student = models.User(
|
admin_user = models.User(
|
||||||
id=free_student_id,
|
id=admin_id,
|
||||||
phone="8888888888",
|
phone="9999999998",
|
||||||
email="free@pragativeer.com",
|
email="admin@pragativeer.com",
|
||||||
password_hash=DEFAULT_SEED_HASH,
|
password_hash=bcrypt.hashpw("admin123".encode('utf-8'), bcrypt.gensalt()).decode('utf-8'),
|
||||||
name="Amit Kumar (Free Tier)",
|
name="Super Admin",
|
||||||
student_class=models.ClassEnum.TWELFTH,
|
student_class=models.ClassEnum.TWELFTH,
|
||||||
medium=models.MediumEnum.ENGLISH,
|
medium=models.MediumEnum.ENGLISH,
|
||||||
target_exam=models.ExamEnum.JEE_MAIN,
|
target_exam=models.ExamEnum.JEE_MAIN,
|
||||||
city="Patna",
|
city="New Delhi",
|
||||||
state="Bihar",
|
state="Delhi",
|
||||||
tier=models.TierEnum.FREE,
|
tier=models.TierEnum.AI_COACH,
|
||||||
streak_count=1,
|
streak_count=0,
|
||||||
last_active=datetime.utcnow()
|
last_active=datetime.utcnow()
|
||||||
)
|
)
|
||||||
session.add(free_student)
|
session.add(admin_user)
|
||||||
|
|
||||||
pro_student_id = UUID("22222222-2222-2222-2222-222222222222")
|
# 2. AI Coach Demo Student User
|
||||||
pro_student = models.User(
|
student_id = UUID("b0e17378-864d-439e-8806-708dc48a891b")
|
||||||
id=pro_student_id,
|
student_user = models.User(
|
||||||
phone="7777777777",
|
id=student_id,
|
||||||
email="pro@pragativeer.com",
|
phone="9999999999",
|
||||||
password_hash=DEFAULT_SEED_HASH,
|
email="demo@pragativeer.com",
|
||||||
name="Priya Singh (Pro Tier)",
|
password_hash=bcrypt.hashpw("Pv9#kL2$mQ8!vX4@".encode('utf-8'), bcrypt.gensalt()).decode('utf-8'),
|
||||||
|
name="Rahul Sharma (Demo AI Coach)",
|
||||||
student_class=models.ClassEnum.TWELFTH,
|
student_class=models.ClassEnum.TWELFTH,
|
||||||
medium=models.MediumEnum.ENGLISH,
|
medium=models.MediumEnum.ENGLISH,
|
||||||
target_exam=models.ExamEnum.NEET,
|
target_exam=models.ExamEnum.JEE_MAIN,
|
||||||
city="Kota",
|
|
||||||
state="Rajasthan",
|
|
||||||
tier=models.TierEnum.PRO,
|
|
||||||
streak_count=3,
|
|
||||||
last_active=datetime.utcnow()
|
|
||||||
)
|
|
||||||
session.add(pro_student)
|
|
||||||
|
|
||||||
# Neha Verma — full AI Coach demo profile for manager presentations
|
|
||||||
neha_id = UUID("33333333-3333-3333-3333-333333333333")
|
|
||||||
neha_student = models.User(
|
|
||||||
id=neha_id,
|
|
||||||
phone="6666666666",
|
|
||||||
email="neha@pragativeer.com",
|
|
||||||
password_hash=DEFAULT_SEED_HASH,
|
|
||||||
name="Neha Verma",
|
|
||||||
student_class=models.ClassEnum.TWELFTH,
|
|
||||||
medium=models.MediumEnum.ENGLISH,
|
|
||||||
target_exam=models.ExamEnum.NEET,
|
|
||||||
school="Delhi Public School, R.K. Puram",
|
school="Delhi Public School, R.K. Puram",
|
||||||
city="New Delhi",
|
city="New Delhi",
|
||||||
state="Delhi",
|
state="Delhi",
|
||||||
tier=models.TierEnum.AI_COACH,
|
tier=models.TierEnum.AI_COACH,
|
||||||
trial_end=None,
|
trial_end=None,
|
||||||
subscription_end=datetime.utcnow() + timedelta(days=345),
|
subscription_end=datetime.utcnow() + timedelta(days=345),
|
||||||
streak_count=62,
|
streak_count=6,
|
||||||
longest_streak=62,
|
longest_streak=6,
|
||||||
last_active=datetime.utcnow()
|
last_active=datetime.utcnow()
|
||||||
)
|
)
|
||||||
session.add(neha_student)
|
session.add(student_user)
|
||||||
|
|
||||||
# Seed Neha's Subscription record
|
# Seed Demo Student Subscription record
|
||||||
neha_subscription = models.Subscription(
|
demo_subscription = models.Subscription(
|
||||||
id=uuid4(),
|
id=uuid4(),
|
||||||
user_id=neha_id,
|
user_id=student_id,
|
||||||
tier=models.TierEnum.AI_COACH,
|
tier=models.TierEnum.AI_COACH,
|
||||||
billing_cycle="Annual",
|
billing_cycle="Annual",
|
||||||
start_date=datetime.utcnow() - timedelta(days=20),
|
start_date=datetime.utcnow() - timedelta(days=20),
|
||||||
end_date=datetime.utcnow() + timedelta(days=345),
|
end_date=datetime.utcnow() + timedelta(days=345),
|
||||||
amount=1199900, # ₹11,999 in paise
|
amount=1199900,
|
||||||
payment_id="PAY_NEHA_DEMO_001",
|
payment_id="PAY_DEMO_001",
|
||||||
status="Active",
|
status="Active",
|
||||||
auto_renew=True,
|
auto_renew=True,
|
||||||
)
|
)
|
||||||
session.add(neha_subscription)
|
session.add(demo_subscription)
|
||||||
|
|
||||||
# Seed Neha's Transaction record
|
# Seed Demo Student Transaction record
|
||||||
neha_txn = models.Transaction(
|
demo_txn = models.Transaction(
|
||||||
id=uuid4(),
|
id=uuid4(),
|
||||||
user_id=neha_id,
|
user_id=student_id,
|
||||||
amount=11999.0,
|
amount=11999.0,
|
||||||
tier="Al_Coach",
|
tier="Al_Coach",
|
||||||
status="Success",
|
status="Success",
|
||||||
created_at=datetime.utcnow() - timedelta(days=20),
|
created_at=datetime.utcnow() - timedelta(days=20),
|
||||||
)
|
)
|
||||||
session.add(neha_txn)
|
session.add(demo_txn)
|
||||||
|
|
||||||
|
|
||||||
student_id = UUID("b0e17378-864d-439e-8806-708dc48a891b")
|
|
||||||
student_user = models.User(
|
|
||||||
id=student_id,
|
|
||||||
phone="9999999999",
|
|
||||||
email="student@pragativeer.com",
|
|
||||||
password_hash=DEFAULT_SEED_HASH,
|
|
||||||
name="Rahul Sharma (AI Coach Tier)",
|
|
||||||
student_class=models.ClassEnum.TWELFTH,
|
|
||||||
medium=models.MediumEnum.ENGLISH,
|
|
||||||
target_exam=models.ExamEnum.JEE_MAIN,
|
|
||||||
city="New Delhi",
|
|
||||||
state="Delhi",
|
|
||||||
tier=models.TierEnum.AI_COACH,
|
|
||||||
streak_count=5,
|
|
||||||
last_active=datetime.utcnow()
|
|
||||||
)
|
|
||||||
session.add(student_user)
|
|
||||||
|
|
||||||
admin_id = uuid4()
|
admin_id = uuid4()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user