Session api token validation

This commit is contained in:
2026-06-29 21:42:47 +10:00
parent 164b590a6c
commit e551e202d5
18 changed files with 273 additions and 154 deletions
+27 -2
View File
@@ -16,6 +16,10 @@ use Inertia\Inertia;
class UserProfileController extends Controller
{
public function currentUserCanEditProfile(User $profileUser){
return auth()->check() && (auth()->id() === $profileUser->id || auth()->user()->hasRole('admin'));
}
public function index(){
if (auth()->check()) {
$user = auth()->user();
@@ -39,7 +43,7 @@ class UserProfileController extends Controller
return [
'user' => $user,
'canView' => Gate::allows('viewProfileData', $user),
'canEdit' => auth()->check() && (auth()->id() === $user->id || auth()->user()->hasRole('admin')),
'canEdit' => $this->currentUserCanEditProfile($user),
'initialView' => $view,
'selectedFlightId' => $selectedFlightId,
'followStatus' => auth()->check() ? auth()->user()->followStatus($user) : 'none',
@@ -85,10 +89,11 @@ class UserProfileController extends Controller
return Inertia::render('UserFlight', [
'flightCount' => $user->departedFlights()->count(),
'flight' => $userFlight->snapshot($userFlight->id),
'canEdit' => auth()->check() && auth()->id() === $user->id,
'canEdit' => $this->currentUserCanEditProfile($user),
'canView' => Gate::allows('viewProfileData', $user),
'user' => $user,
'followStatus' => auth()->check() ? auth()->user()->followStatus($user) : 'none',
'otherUsersOnFlight' => $userFlight->otherUsersOnFlight(),
]);
}
@@ -128,6 +133,26 @@ class UserProfileController extends Controller
]);
}
public function copyFlight(UserFlight $flight)
{
$loggedInUser = auth()->user();
$exists = UserFlight::where('user_id', $loggedInUser->id)
->where('departure_airport_id', $flight->departure_airport_id)
->where('arrival_airport_id', $flight->arrival_airport_id)
->exists();
if ($exists) {
return back()->withErrors(['flight' => 'You already have a flight logged between these airports on this date.']);
}
$newFlight = $flight->replicate();
$newFlight->user_id = $loggedInUser->id;
$newFlight->save();
return redirect()->route('flights.edit', ['flight' => $newFlight->id]);
}
public function achievement(User $user, Achievement $achievement)
{
$regions = match($achievement->internal_name){