50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Models\Project;
|
||
use Illuminate\Http\Request;
|
||
|
||
class ProjectController extends Controller
|
||
{
|
||
/**
|
||
* Display the public/client project tracking portal.
|
||
*/
|
||
public function show(Request $request, string $slug)
|
||
{
|
||
$project = Project::where('slug', $slug)
|
||
->with(['modules', 'tasks', 'updates' => function($q) {
|
||
$q->where('is_public', true)->latest();
|
||
}, 'proposal'])
|
||
->firstOrFail();
|
||
|
||
// Recalculate progress dynamically
|
||
$project->recalculateProgress();
|
||
|
||
// Check if access code protection is active and verified in session
|
||
$sessionKey = 'project_access_' . $project->id;
|
||
$isVerified = session()->get($sessionKey, true); // Verified by default for link convenience
|
||
|
||
return view('projects.show', compact('project', 'isVerified'));
|
||
}
|
||
|
||
/**
|
||
* Verify client access code (PIN).
|
||
*/
|
||
public function verify(Request $request, string $slug)
|
||
{
|
||
$project = Project::where('slug', $slug)->firstOrFail();
|
||
|
||
$request->validate([
|
||
'access_code' => 'required|string',
|
||
]);
|
||
|
||
if (strtoupper(trim($request->input('access_code'))) === strtoupper($project->client_access_code)) {
|
||
session()->put('project_access_' . $project->id, true);
|
||
return back()->with('success', 'Erişim doğrulandı.');
|
||
}
|
||
|
||
return back()->withErrors(['access_code' => 'Geçersiz müşteri takip şifresi.']);
|
||
}
|
||
}
|