# Quick Setup Commands - Copy & Paste

## One-Time Setup (Run Once)

### 1. Ensure JWT Package is Installed
```powershell
cd "c:\Apps\LimozX\limozxAPI"
composer require php-open-source-saver/jwt-auth
```

### 2. Generate JWT Secret
```powershell
php artisan jwt:secret
```

**Verify in `.env`:**
```
JWT_SECRET=your_generated_key_here
```

### 3. Run Database Migration
```powershell
php artisan migrate
```

**Expected Output:**
```
Migration table created successfully.
Migrating: 2024_01_01_000000_create_users_table
Migrated: 2024_01_01_000000_create_users_table
```

### 4. Seed Test Data (18 Users)
```powershell
php artisan db:seed --class=UserSeeder
```

**Expected Output:**
```
Seeding: Database\Seeders\UserSeeder
Seeded: Database\Seeders\UserSeeder (executed in 150ms)
```

---

## Daily Development (Run When Starting Work)

### 5. Start Laravel Development Server
```powershell
cd "c:\Apps\LimozX\limozxAPI"
php artisan serve
```

**Expected Output:**
```
   INFO  Server running on [http://127.0.0.1:8000]
   
   Starting Laravel development server: http://127.0.0.1:8000
```

Keep this terminal open. Press `Ctrl+C` to stop.

### 6. In Another Terminal: Start Angular Dev Server
```powershell
cd "c:\Apps\LimozX\LimoxZ"
npm start
```

**Expected Output:**
```
Angular Live Development Server is listening on localhost:4200
```

---

## Quick Testing

### Test 1: Login Endpoint (PowerShell)
```powershell
$body = @{
    email = "admin@limozx.com"
    password = "12345678"
} | ConvertTo-Json

$response = Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/auth/login" `
  -Method POST `
  -ContentType "application/json" `
  -Body $body

$response.Content | ConvertFrom-Json | ConvertTo-Json
```

### Test 2: Get Profile (With Token)
```powershell
# First login to get token
$loginBody = @{
    email = "admin@limozx.com"
    password = "12345678"
} | ConvertTo-Json

$loginResponse = Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/auth/login" `
  -Method POST `
  -ContentType "application/json" `
  -Body $loginBody

$token = ($loginResponse.Content | ConvertFrom-Json).token

# Use token to get profile
$headers = @{
    "Authorization" = "Bearer $token"
    "Content-Type" = "application/json"
}

$profileResponse = Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/auth/profile" `
  -Method GET `
  -Headers $headers

$profileResponse.Content | ConvertFrom-Json | ConvertTo-Json
```

### Test 3: Logout
```powershell
$headers = @{
    "Authorization" = "Bearer $token"
    "Content-Type" = "application/json"
}

$response = Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/auth/logout" `
  -Method POST `
  -Headers $headers

$response.Content | ConvertFrom-Json | ConvertTo-Json
```

---

## Database Inspection

### View All Users
```powershell
php artisan tinker

App\Models\User::select('id', 'name', 'email', 'role', 'tenant')->get()
```

### Count Users by Role
```powershell
php artisan tinker

App\Models\User::groupBy('role')->select('role')->selectRaw('count(*) as count')->get()
```

### Find Specific User
```powershell
php artisan tinker

App\Models\User::where('email', 'admin@limozx.com')->first()
```

### Update User Password (If Needed)
```powershell
php artisan tinker

$user = App\Models\User::find(1);
$user->password = Hash::make('newpassword123');
$user->save();
```

---

## Reset Everything (Start Fresh)

### ⚠️ Warning: This Deletes All Data!

```powershell
# Option 1: Fresh Migrate & Seed
php artisan migrate:fresh --seed --seeder=UserSeeder

# Or Option 2: Manual Reset
php artisan migrate:reset
php artisan migrate
php artisan db:seed --class=UserSeeder
```

---

## API Endpoints Reference

### Login
```
POST   http://127.0.0.1:8000/api/auth/login
Body:  { "email": "...", "password": "..." }
Returns: { "token": "...", "user": {...} }
```

### Get Profile
```
GET    http://127.0.0.1:8000/api/auth/profile
Headers: Authorization: Bearer {token}
Returns: { "data": {...}, "success": true }
```

### Refresh Token
```
POST   http://127.0.0.1:8000/api/auth/refresh
Headers: Authorization: Bearer {token}
Returns: { "token": "...", "access_token": "..." }
```

### Logout
```
POST   http://127.0.0.1:8000/api/auth/logout
Headers: Authorization: Bearer {token}
Returns: { "success": true, "message": "Logout successful" }
```

### Register
```
POST   http://127.0.0.1:8000/api/auth/register
Body:  { "name": "...", "email": "...", "password": "...", "password_confirmation": "..." }
Returns: { "token": "...", "user": {...} }
```

---

## Test All 18 Users Quickly

### Script: Login All Users
```powershell
$users = @(
    @{ email = "admin@limozx.com"; name = "Platform Admin" },
    @{ email = "operator@olacabs.com"; name = "Operator Admin (Ola)" },
    @{ email = "operator@uber.com"; name = "Operator Admin (Uber)" },
    @{ email = "tenant@olacabs.com"; name = "Tenant Admin (Ola)" },
    @{ email = "tenant@uber.com"; name = "Tenant Admin (Uber)" },
    @{ email = "affiliate@premiertravel.com"; name = "Affiliate (Premier)" },
    @{ email = "affiliate@corporatetravel.com"; name = "Affiliate (Corporate)" },
    @{ email = "raj.kumar@techcorp.com"; name = "Corporate Traveler (Sales)" },
    @{ email = "priya.singh@techcorp.com"; name = "Corporate Traveler (Finance)" },
    @{ email = "anil.patel@techcorp.com"; name = "Corporate Traveler (Operations)" },
    @{ email = "driver1@limozx.com"; name = "Driver 1" },
    @{ email = "driver2@limozx.com"; name = "Driver 2" },
    @{ email = "driver3@limozx.com"; name = "Driver 3" },
    @{ email = "driver4@limozx.com"; name = "Driver 4" },
    @{ email = "sarah.customer@email.com"; name = "Customer 1" },
    @{ email = "john.corporate@email.com"; name = "Customer 2" },
    @{ email = "ops@limozx.com"; name = "Operations Manager" },
    @{ email = "finance@limozx.com"; name = "Finance Manager" }
)

foreach ($user in $users) {
    $body = @{
        email = $user.email
        password = "12345678"
    } | ConvertTo-Json

    try {
        $response = Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/auth/login" `
          -Method POST `
          -ContentType "application/json" `
          -Body $body `
          -TimeoutSec 5

        $result = $response.Content | ConvertFrom-Json
        Write-Host "✅ $($user.name) - Login Success (Token: $($result.token.Substring(0,20))...)" -ForegroundColor Green
    } catch {
        Write-Host "❌ $($user.name) - Login Failed" -ForegroundColor Red
    }
}
```

---

## Environment File Checklist

Verify `.env` has these values:

```
APP_NAME=LimozX
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=limozx
DB_USERNAME=root
DB_PASSWORD=

JWT_SECRET=base64:your_secret_key_here
JWT_ALGORITHM=HS256
JWT_TTL=60
```

---

## Troubleshooting Commands

### Check if MySQL is Running
```powershell
# Windows
Get-Service -Name MySQL80 | Select-Object Status

# Or test connection
mysql -u root
```

### Check if PHP is Working
```powershell
php -v
```

### Check if Composer is Installed
```powershell
composer --version
```

### Check Database Connection
```powershell
php artisan tinker
DB::connection()->getPdo()
```

### View Recent Log Errors
```powershell
Get-Content "c:\Apps\LimozX\limozxAPI\storage\logs\laravel.log" -Tail 50
```

### Clear All Caches
```powershell
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
```

---

## File Verification

### Check All Files Exist
```powershell
$files = @(
    "c:\Apps\LimozX\limozxAPI\app\Http\Controllers\Api\Auth\AuthController.php",
    "c:\Apps\LimozX\limozxAPI\app\Models\User.php",
    "c:\Apps\LimozX\limozxAPI\database\migrations\2024_01_01_000000_create_users_table.php",
    "c:\Apps\LimozX\limozxAPI\database\seeders\UserSeeder.php",
    "c:\Apps\LimozX\limozxAPI\routes\api.php"
)

foreach ($file in $files) {
    if (Test-Path $file) {
        Write-Host "✅ $file exists" -ForegroundColor Green
    } else {
        Write-Host "❌ $file NOT FOUND" -ForegroundColor Red
    }
}
```

---

## One-Line Quick Start (After Initial Setup)

Terminal 1 (Laravel):
```powershell
cd "c:\Apps\LimozX\limozxAPI"; php artisan serve
```

Terminal 2 (Angular):
```powershell
cd "c:\Apps\LimozX\LimoxZ"; npm start
```

Terminal 3 (Testing):
```powershell
# Test login
$body = @{ email = "admin@limozx.com"; password = "12345678" } | ConvertTo-Json
$r = Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/auth/login" -Method POST -ContentType "application/json" -Body $body
$r.Content | ConvertFrom-Json | ConvertTo-Json
```

---

## Success Indicators

✅ **You'll know everything works when:**
1. `php artisan serve` starts without errors
2. `npm start` starts Angular dev server
3. Login endpoint returns a token (JWT format)
4. Browser DevTools shows token in localStorage
5. Navigating to dashboard works without redirect to login
6. User profile displays with correct name and role

---

## Password Reset (if needed)

All test users have password: `12345678`

To change a user's password:
```powershell
php artisan tinker

$user = App\Models\User::where('email', 'admin@limozx.com')->first();
$user->update(['password' => Hash::make('newpassword123')]);
```

---

## Next Commands

After successful login testing:

1. **Test all dashboards:**
   - Login as each role
   - Verify correct dashboard loads

2. **Test protected routes:**
   - Try to access protected routes without token
   - Should be redirected to login

3. **Test role-based access:**
   - Login as Operator Admin
   - Verify can only see Operator features
   - Logout and login as Corporate Traveler
   - Verify can only see Corporate Traveler features

4. **Test token expiration:**
   - Get token
   - Wait for TTL (or modify to 10 seconds for testing)
   - Try to use expired token
   - Should get 401 error

5. **Test token refresh:**
   - Get token
   - Call refresh endpoint
   - Get new token
   - Verify old token no longer works

---

## Quick Reference Checklist

- [ ] Run `php artisan migrate`
- [ ] Run `php artisan db:seed --class=UserSeeder`
- [ ] Run `php artisan jwt:secret`
- [ ] Verify JWT_SECRET in `.env`
- [ ] Start Laravel: `php artisan serve`
- [ ] Start Angular: `npm start`
- [ ] Test login endpoint
- [ ] Test all 18 users can login
- [ ] Test role-based dashboards
- [ ] Test token refresh
- [ ] Test logout
- [ ] Test protected routes
- [ ] Verify localStorage has token
- [ ] Test API calls with Authorization header

**Total setup time: ~5-10 minutes** ⏱️

**System ready for testing!** 🚀
