Authentication System Complete (50% of Phase 2): - Created Admin AuthController with login/logout - Created AdminAuth middleware for session-based auth - Registered middleware in bootstrap/app.php - Configured all admin routes with protection - Created 4 admin controller files (Dashboard, DocketEntry, Document, Subscriber) Session-based authentication: - Stores admin_id and admin_username in session - Middleware checks for admin_id presence - Separate from Laravel Breeze User auth - Uses AdminUser model with auto-hashing passwords Routes configured: - Public: GET/POST /admin/login - Protected: /admin/dashboard, /admin/docket-entries (CRUD), /admin/documents, /admin/subscribers Remaining work (50%): - Implement controller logic (7 methods for DocketEntry, etc.) - Create 9 Vue admin pages (Login, Dashboard, CRUD forms) - Create AdminSeeder for default admin user - Configure file storage for PDF uploads - Test all admin features See cline_docs/phase2_progress.md for detailed next steps
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AdminUser;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
/**
|
|
* Show the admin login form.
|
|
*/
|
|
public function showLogin(): Response
|
|
{
|
|
return Inertia::render('Admin/Login');
|
|
}
|
|
|
|
/**
|
|
* Handle admin login.
|
|
*/
|
|
public function login(Request $request): RedirectResponse
|
|
{
|
|
$request->validate([
|
|
'username' => 'required|string',
|
|
'password' => 'required|string',
|
|
]);
|
|
|
|
$admin = AdminUser::where('username', $request->username)->first();
|
|
|
|
if (!$admin || !Hash::check($request->password, $admin->password)) {
|
|
return back()->withErrors([
|
|
'username' => 'The provided credentials do not match our records.',
|
|
])->onlyInput('username');
|
|
}
|
|
|
|
// Store admin ID in session
|
|
Session::put('admin_id', $admin->id);
|
|
Session::put('admin_username', $admin->username);
|
|
|
|
return redirect()->route('admin.dashboard');
|
|
}
|
|
|
|
/**
|
|
* Handle admin logout.
|
|
*/
|
|
public function logout(Request $request): RedirectResponse
|
|
{
|
|
Session::forget('admin_id');
|
|
Session::forget('admin_username');
|
|
Session::flush();
|
|
|
|
return redirect()->route('admin.login');
|
|
}
|
|
}
|