Initial Ladill Frontdesk release with deploy pipeline.
Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontdesk;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
||||
use App\Models\Visit;
|
||||
use App\Services\Frontdesk\VisitCheckOutService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SecurityController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'security.view');
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
$occupancy = Visit::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->currentlyInside()
|
||||
->with(['visitor', 'host']);
|
||||
$this->scopeToBranch($request, $occupancy);
|
||||
$occupancy = $occupancy->orderBy('checked_in_at')->get();
|
||||
|
||||
$expiredBadges = $occupancy->filter(fn (Visit $v) => $v->isBadgeExpired());
|
||||
|
||||
return view('frontdesk.security.index', [
|
||||
'occupancy' => $occupancy,
|
||||
'expiredBadges' => $expiredBadges,
|
||||
'organization' => $organization,
|
||||
'canCheckout' => app(\App\Services\Frontdesk\FrontdeskPermissions::class)
|
||||
->can($this->member($request), 'security.checkout'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function evacuation(Request $request): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'security.view');
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
$occupancy = Visit::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->currentlyInside()
|
||||
->with(['visitor', 'host', 'branch']);
|
||||
$this->scopeToBranch($request, $occupancy);
|
||||
$occupancy = $occupancy->orderBy('checked_in_at')->get();
|
||||
|
||||
return view('frontdesk.security.evacuation', compact('occupancy', 'organization'));
|
||||
}
|
||||
|
||||
public function evacuationBadges(Request $request, \App\Services\Frontdesk\BadgeRenderService $badges): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'security.view');
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
$visits = Visit::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->currentlyInside()
|
||||
->with(['visitor', 'host', 'organization']);
|
||||
$this->scopeToBranch($request, $visits);
|
||||
$visits = $visits->orderBy('checked_in_at')->get();
|
||||
|
||||
$rendered = $visits->map(fn (Visit $visit) => $badges->renderHtml($visit));
|
||||
|
||||
return view('frontdesk.security.evacuation-badges', compact('visits', 'rendered', 'organization'));
|
||||
}
|
||||
|
||||
public function checkOut(Request $request, Visit $visit, VisitCheckOutService $checkOut): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'security.checkout');
|
||||
$this->authorizeOwner($request, $visit);
|
||||
$checkOut->checkOut($visit, $this->ownerRef($request));
|
||||
|
||||
return back()->with('success', 'Visitor checked out.');
|
||||
}
|
||||
|
||||
public function verifyForm(Request $request): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'security.verify');
|
||||
|
||||
return view('frontdesk.security.verify', [
|
||||
'organization' => $this->organization($request),
|
||||
]);
|
||||
}
|
||||
|
||||
public function verify(Request $request): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'security.verify');
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
$validated = $request->validate([
|
||||
'lookup' => ['required', 'string', 'max:64'],
|
||||
]);
|
||||
|
||||
$lookup = trim($validated['lookup']);
|
||||
|
||||
$visit = Visit::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->where(function ($q) use ($lookup) {
|
||||
$q->where('badge_code', strtoupper($lookup))
|
||||
->orWhere('qr_token', $lookup);
|
||||
})
|
||||
->with(['visitor', 'host', 'branch'])
|
||||
->latest('checked_in_at')
|
||||
->first();
|
||||
|
||||
return view('frontdesk.security.verify', [
|
||||
'organization' => $organization,
|
||||
'lookup' => $lookup,
|
||||
'visit' => $visit,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user