# TurboTrades Admin System A comprehensive admin panel for managing users, site configuration, maintenance mode, announcements, and promotions. ## ๐ŸŽฏ Quick Links - **[Quick Start Guide](./ADMIN_QUICK_START.md)** - Common tasks and procedures - **[Full Documentation](./ADMIN_SYSTEM.md)** - Complete API and feature reference - **[Admin Panel](http://localhost:5173/admin)** - Access the dashboard --- ## โœจ Features ### User Management - ๐Ÿ” Search users by username, Steam ID, or email - ๐Ÿ’ฐ Add/remove user balance with audit trail - ๐Ÿ”จ Ban/unban users (temporary or permanent) - ๐Ÿ‘ฎ Manage staff levels (0-5) - ๐Ÿ“Š View user statistics and transaction history - ๐Ÿ“ฆ Bulk user operations ### Site Configuration - ๐Ÿ”ง Maintenance mode with scheduling - ๐Ÿ“ข Site-wide announcements (info, warning, success, error) - ๐ŸŽ Promotional campaigns (deposit bonuses, discounts) - ๐Ÿ’ฑ Trading settings (fees, limits, toggles) - ๐Ÿช Market settings (commission, price ranges) - โšก Feature toggles ### Dashboard & Analytics - ๐Ÿ“ˆ Real-time statistics - ๐Ÿ’ต Financial reports - ๐Ÿ“‹ Transaction monitoring - ๐Ÿ“ฆ Item management - ๐Ÿ”„ Price updates --- ## ๐Ÿš€ Setup ### 1. Install Dependencies Already included in the main project. The admin system uses: - Backend: Fastify, MongoDB (Mongoose), UUID - Frontend: Vue 3, Lucide icons, Vue Toastification ### 2. Configure Admin Access Add admin Steam IDs to `.env`: ```env ADMIN_STEAM_IDS=76561198000000000,76561198000000001 ``` ### 3. Promote Users to Admin Run the make-admin script: ```bash node make-admin.js ``` Example: ```bash node make-admin.js 76561198000000000 5 ``` **Staff Levels:** - `0` - Regular User - `1` - Support Staff - `2` - Moderator - `3` - Admin (full access to admin panel) - `4` - Senior Admin - `5` - Super Admin (can promote others to admin) ### 4. Access Admin Panel Navigate to: `http://localhost:5173/admin` You must be authenticated and have staff level 3+ or be in the `ADMIN_STEAM_IDS` list. --- ## ๐Ÿ“ File Structure ``` TurboTrades/ โ”œโ”€โ”€ models/ โ”‚ โ”œโ”€โ”€ SiteConfig.js # Site configuration model โ”‚ โ”œโ”€โ”€ PromoUsage.js # Promotion usage tracking โ”‚ โ””โ”€โ”€ User.js # User model (includes staff level) โ”‚ โ”œโ”€โ”€ routes/ โ”‚ โ”œโ”€โ”€ admin.js # Existing admin routes (prices, etc) โ”‚ โ”œโ”€โ”€ admin-management.js # NEW: User/config management routes โ”‚ โ””โ”€โ”€ config.js # NEW: Public config endpoints โ”‚ โ”œโ”€โ”€ middleware/ โ”‚ โ””โ”€โ”€ maintenance.js # NEW: Maintenance mode middleware โ”‚ โ”œโ”€โ”€ frontend/src/ โ”‚ โ”œโ”€โ”€ views/ โ”‚ โ”‚ โ””โ”€โ”€ AdminPage.vue # Main admin dashboard โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ components/ โ”‚ โ”œโ”€โ”€ AdminUsersPanel.vue # NEW: User management โ”‚ โ””โ”€โ”€ AdminConfigPanel.vue # NEW: Site configuration โ”‚ โ””โ”€โ”€ docs/ โ”œโ”€โ”€ ADMIN_README.md # This file โ”œโ”€โ”€ ADMIN_QUICK_START.md # Quick reference guide โ””โ”€โ”€ ADMIN_SYSTEM.md # Complete documentation ``` --- ## ๐ŸŽฎ Usage Examples ### Search and Ban a User ```javascript // 1. Search const users = await api.get('/admin/users/search', { params: { query: 'player123' } }); // 2. Ban for 7 days await api.post(`/admin/users/${users.data.users[0]._id}/ban`, { banned: true, reason: 'Violation of ToS - Item duplication', duration: 168 // hours }); ``` ### Add User Balance ```javascript await api.post('/admin/users/USER_ID/balance', { amount: 50.00, reason: 'Compensation for bug #1234', type: 'add' }); ``` ### Enable Maintenance Mode ```javascript await api.patch('/admin/config/maintenance', { enabled: true, message: 'Server maintenance in progress. Back soon!', allowedSteamIds: ['76561198000000000'], scheduledEnd: '2024-01-01T12:00:00Z' }); ``` ### Create Announcement ```javascript await api.post('/admin/announcements', { type: 'success', message: 'New CS2 skins just added to the market!', enabled: true, dismissible: true, endDate: '2024-01-07T23:59:59Z' }); ``` ### Create Promotion ```javascript await api.post('/admin/promotions', { name: 'Weekend Bonus', description: 'Get 10% extra on all deposits this weekend!', type: 'deposit_bonus', enabled: true, startDate: '2024-01-06T00:00:00Z', endDate: '2024-01-07T23:59:59Z', bonusPercentage: 10, minDeposit: 10, maxBonus: 50, maxUsesPerUser: 1 }); ``` --- ## ๐Ÿ”Œ API Endpoints ### User Management | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/admin/users/search` | Search users | | GET | `/api/admin/users/:id` | Get user details | | POST | `/api/admin/users/:id/balance` | Adjust balance | | POST | `/api/admin/users/:id/ban` | Ban/unban user | | POST | `/api/admin/users/:id/staff-level` | Change staff level | | GET | `/api/admin/users/:id/transactions` | Get user transactions | | POST | `/api/admin/users/bulk-ban` | Bulk ban users | ### Site Configuration | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/admin/config` | Get site config | | PATCH | `/api/admin/config/maintenance` | Update maintenance mode | | PATCH | `/api/admin/config/trading` | Update trading settings | | PATCH | `/api/admin/config/market` | Update market settings | ### Announcements | Method | Endpoint | Description | |--------|----------|-------------| | POST | `/api/admin/announcements` | Create announcement | | PATCH | `/api/admin/announcements/:id` | Update announcement | | DELETE | `/api/admin/announcements/:id` | Delete announcement | | GET | `/api/config/announcements` | Get active (public) | ### Promotions | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/admin/promotions` | List all promotions | | POST | `/api/admin/promotions` | Create promotion | | PATCH | `/api/admin/promotions/:id` | Update promotion | | DELETE | `/api/admin/promotions/:id` | Delete promotion | | GET | `/api/admin/promotions/:id/usage` | Get usage stats | | POST | `/api/config/validate-promo` | Validate promo code (public) | ### Public Config | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/config/public` | Get public config | | GET | `/api/config/status` | Get site status | | GET | `/api/config/announcements` | Get active announcements | | GET | `/api/config/promotions` | Get active promotions | --- ## ๐Ÿ›ก๏ธ Security ### Authentication All admin endpoints require: 1. Valid JWT token in Authorization header 2. User has staff level 3+ OR Steam ID in `ADMIN_STEAM_IDS` ### Audit Trail All admin actions are logged with: - Admin username and ID - Action performed - Timestamp - Target user (if applicable) - Reason provided ### Best Practices - โœ… Enable 2FA on admin accounts - โœ… Use strong, unique passwords - โœ… Review admin logs regularly - โœ… Only promote trusted users to admin - โœ… Document significant actions - โŒ Never share admin credentials - โŒ Don't make changes without reason --- ## ๐Ÿงช Testing ### Test Admin Features ```bash # 1. Start the backend npm start # 2. Start the frontend cd frontend npm run dev # 3. Login with admin account # 4. Navigate to /admin # 5. Test each feature ``` ### Test Maintenance Mode ```bash # Enable maintenance via API curl -X PATCH http://localhost:3000/api/admin/config/maintenance \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"enabled": true}' # Try accessing site as regular user (should see maintenance message) # Access site as admin (should work normally) # Disable maintenance curl -X PATCH http://localhost:3000/api/admin/config/maintenance \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"enabled": false}' ``` --- ## ๐Ÿ”ง Troubleshooting ### Can't access admin panel **Problem:** Getting 403 Forbidden **Solution:** - Check if your account has staff level 3+ - Verify your Steam ID is in `ADMIN_STEAM_IDS` - Clear browser cache and re-login ### Maintenance mode not working **Problem:** Users can still access site during maintenance **Solution:** - Verify middleware is registered in index.js - Check scheduled dates are correct - Clear any caching layers - Check browser console for errors ### Promotion not applying **Problem:** Users report promo code not working **Solution:** - Verify promotion is enabled - Check start/end dates - Verify user meets requirements (new user only, min deposit, etc.) - Check usage limits haven't been reached - Validate promo code spelling ### Balance adjustment failed **Problem:** Can't adjust user balance **Solution:** - Verify user ID is correct - Check amount is positive number - Ensure reason is provided (min 3 chars) - Check user has sufficient balance (for removals) --- ## ๐Ÿ“Š Monitoring ### Dashboard Metrics Monitor these key metrics daily: - Total users & new registrations - Active items & listings - Transaction volume & value - Failed transactions - Support tickets - System errors ### Financial Reports Weekly financial review: - Total deposits & withdrawals - Market commission earned - Promotion bonuses given - Net profit/loss - Outstanding balances --- ## ๐Ÿš€ Deployment ### Production Checklist - [ ] Set secure `ADMIN_STEAM_IDS` in production .env - [ ] Enable 2FA for all admin accounts - [ ] Set up admin action logging - [ ] Configure rate limiting on admin endpoints - [ ] Set up monitoring and alerts - [ ] Document emergency procedures - [ ] Train staff on admin features - [ ] Set up backup admin access - [ ] Review security best practices - [ ] Test maintenance mode workflow --- ## ๐Ÿ“š Additional Resources - **[Quick Start Guide](./ADMIN_QUICK_START.md)** - Common tasks - **[Full Documentation](./ADMIN_SYSTEM.md)** - Complete reference - **[API Endpoints](./API_ENDPOINTS.md)** - API documentation - **[Security Features](./SECURITY_FEATURES.md)** - Security guide --- ## ๐Ÿค Contributing When adding admin features: 1. Follow existing code patterns 2. Add appropriate authorization checks 3. Log all significant actions 4. Update documentation 5. Add error handling 6. Test thoroughly --- ## ๐Ÿ“ Version History ### v1.0.0 (Initial Release) - User management system - Site configuration panel - Maintenance mode - Announcements system - Promotions system - Trading & market settings - Dashboard & analytics --- ## ๐Ÿ“ž Support For questions or issues: 1. Check troubleshooting section 2. Review full documentation 3. Check server logs (`backend.log`) 4. Contact senior admin or development team --- ## โš–๏ธ License Part of the TurboTrades platform. Internal use only. --- **Made with โค๏ธ for TurboTrades** *Last Updated: 2024*