Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- Dockerfile +2 -2
- README.md +12 -5
- app/api/auth.py +19 -2
- app/api/seed.py +17 -0
- requirements.txt +1 -0
Dockerfile
CHANGED
|
@@ -32,5 +32,5 @@ ENV HOST=0.0.0.0
|
|
| 32 |
ENV PORT=7860
|
| 33 |
ENV DATABASE_URL=sqlite:///./vortex.db
|
| 34 |
|
| 35 |
-
# Command to run the application
|
| 36 |
-
CMD ["
|
|
|
|
| 32 |
ENV PORT=7860
|
| 33 |
ENV DATABASE_URL=sqlite:///./vortex.db
|
| 34 |
|
| 35 |
+
# Command to run the application
|
| 36 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--proxy-headers", "--forwarded-allow-ips='*'"]
|
README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: VortexCommerce Backend
|
| 3 |
+
emoji: ๐
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# VortexCommerce Backend
|
| 12 |
+
|
| 13 |
+
AI-Powered Bilingual E-Commerce Platform backend.
|
| 14 |
+
|
| 15 |
+
## Admin Credentials
|
| 16 |
+
- **Email**: admin@vortex.com
|
| 17 |
+
- **Password**: admin123
|
app/api/auth.py
CHANGED
|
@@ -101,8 +101,22 @@ async def admin_login(request: LoginRequest, db: Session = Depends(get_db)):
|
|
| 101 |
try:
|
| 102 |
user = db.query(User).filter(User.email == request.email).first()
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
raise HTTPException(
|
| 107 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 108 |
detail="Invalid email or password",
|
|
@@ -110,11 +124,14 @@ async def admin_login(request: LoginRequest, db: Session = Depends(get_db)):
|
|
| 110 |
|
| 111 |
# Crucial step: Verify admin role
|
| 112 |
if user.role != UserRole.ADMIN:
|
|
|
|
| 113 |
raise HTTPException(
|
| 114 |
status_code=status.HTTP_403_FORBIDDEN,
|
| 115 |
detail="Access denied. Admin privileges required.",
|
| 116 |
)
|
| 117 |
|
|
|
|
|
|
|
| 118 |
tokens = _generate_tokens(user.id)
|
| 119 |
user_data = UserResponse.model_validate(user).model_dump()
|
| 120 |
user_data["created_at"] = user_data["created_at"].isoformat()
|
|
|
|
| 101 |
try:
|
| 102 |
user = db.query(User).filter(User.email == request.email).first()
|
| 103 |
|
| 104 |
+
if not user:
|
| 105 |
+
print(f">>> [AUTH] Admin login attempt failed: User not found ({request.email})")
|
| 106 |
+
raise HTTPException(
|
| 107 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 108 |
+
detail="Invalid email or password",
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
if not user.password_hash:
|
| 112 |
+
print(f">>> [AUTH] Admin login attempt failed: No password hash for user ({request.email})")
|
| 113 |
+
raise HTTPException(
|
| 114 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 115 |
+
detail="Invalid email or password",
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
if not verify_password(request.password, user.password_hash):
|
| 119 |
+
print(f">>> [AUTH] Admin login attempt failed: Password mismatch ({request.email})")
|
| 120 |
raise HTTPException(
|
| 121 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 122 |
detail="Invalid email or password",
|
|
|
|
| 124 |
|
| 125 |
# Crucial step: Verify admin role
|
| 126 |
if user.role != UserRole.ADMIN:
|
| 127 |
+
print(f">>> [AUTH] Admin login attempt failed: User is not an admin ({request.email}, role: {user.role})")
|
| 128 |
raise HTTPException(
|
| 129 |
status_code=status.HTTP_403_FORBIDDEN,
|
| 130 |
detail="Access denied. Admin privileges required.",
|
| 131 |
)
|
| 132 |
|
| 133 |
+
print(f">>> [AUTH] Admin login successful: {request.email}")
|
| 134 |
+
|
| 135 |
tokens = _generate_tokens(user.id)
|
| 136 |
user_data = UserResponse.model_validate(user).model_dump()
|
| 137 |
user_data["created_at"] = user_data["created_at"].isoformat()
|
app/api/seed.py
CHANGED
|
@@ -114,6 +114,23 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 114 |
db.execute(text("DELETE FROM products"))
|
| 115 |
db.execute(text("DELETE FROM categories"))
|
| 116 |
db.execute(text("DELETE FROM coupons"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
db.commit()
|
| 118 |
|
| 119 |
# 1. Create Categories (Hierarchy)
|
|
|
|
| 114 |
db.execute(text("DELETE FROM products"))
|
| 115 |
db.execute(text("DELETE FROM categories"))
|
| 116 |
db.execute(text("DELETE FROM coupons"))
|
| 117 |
+
db.execute(text("DELETE FROM users WHERE role = 'ADMIN'"))
|
| 118 |
+
db.commit()
|
| 119 |
+
|
| 120 |
+
# 0. Create Default Admin if matches criteria
|
| 121 |
+
admin_email = "admin@vortex.com"
|
| 122 |
+
admin_user = db.query(User).filter(User.email == admin_email).first()
|
| 123 |
+
if not admin_user:
|
| 124 |
+
print(f">>> [SEED] Creating default admin: {admin_email}")
|
| 125 |
+
admin_user = User(
|
| 126 |
+
email=admin_email,
|
| 127 |
+
name="Platform Administrator",
|
| 128 |
+
password_hash=hash_password("admin123"),
|
| 129 |
+
role=UserRole.ADMIN,
|
| 130 |
+
auth_provider=AuthProvider.LOCAL,
|
| 131 |
+
is_active=True
|
| 132 |
+
)
|
| 133 |
+
db.add(admin_user)
|
| 134 |
db.commit()
|
| 135 |
|
| 136 |
# 1. Create Categories (Hierarchy)
|
requirements.txt
CHANGED
|
@@ -15,4 +15,5 @@ aiosqlite==0.20.0
|
|
| 15 |
python-dotenv==1.0.1
|
| 16 |
reportlab==4.0.9
|
| 17 |
email-validator==2.1.0.post1
|
|
|
|
| 18 |
urllib3<2
|
|
|
|
| 15 |
python-dotenv==1.0.1
|
| 16 |
reportlab==4.0.9
|
| 17 |
email-validator==2.1.0.post1
|
| 18 |
+
requests==2.31.0
|
| 19 |
urllib3<2
|