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){
@@ -39,6 +39,10 @@ class HandleInertiaRequests extends Middleware
'permissions' => $request->user()?->getAllPermissions()->pluck('name') ?? [],
'apiToken' => session('api_token'),
],
'flash' => [
'success' => $request->session()->get('success'),
'error' => $request->session()->get('error'),
],
'achievement_notifications' => fn() => $request->user()
? $request->user()
->notifications()
+14
View File
@@ -182,6 +182,20 @@ class UserFlight extends Model
return !$this->isDomestic();
}
public function otherUsersOnFlight(){
return UserFlight::where('user_id', '!=', $this->user_id)
->where('departure_airport_id', $this->departure_airport_id)
->where('arrival_airport_id', $this->arrival_airport_id)
->where('flight_number', $this->flight_number)
->where('airline_id', $this->airline_id)
->whereRaw('DATE(departure_date AT TIME ZONE \'UTC\') = ?', [
Carbon::parse($this->departure_date)->utc()->toDateString()
])
->with('user')
->get()
->pluck('user.name');
}
public static function snapshot($userFlightId): array
{
return UserFlight::with([
+1 -1
View File
@@ -14,7 +14,7 @@ class FlightObserver
//Make queued task if the site gets big
$flight->user->followers()
->get()
->each(fn ($follower) => Cache::forget("user_following_flights_{$follower->id}"));
->each(fn ($follower) => Cache::forget("user_following_flights_{$follower->user_id}"));
}
+3 -3
View File
@@ -79,7 +79,7 @@ class SettingsRegistry
'type' => 'checkbox',
'label' => 'Hide Map Filters By Default',
'category' => 'FlightsGoneBy Settings',
'default' => false,
'default' => true,
],
[
'key' => 'hide_impossible_achievements',
@@ -111,8 +111,8 @@ class SettingsRegistry
'options' => [
['value' => 'airline', 'label' => 'Airline'],
['value' => 'flight_number', 'label' => 'Flight Number'],
['value' => 'from', 'label' => 'From'],
['value' => 'to', 'label' => 'To'],
['value' => 'departure_airport', 'label' => 'From'],
['value' => 'arrival_airport', 'label' => 'To'],
['value' => 'departure_date', 'label' => 'Departure Date'],
['value' => 'departure_time', 'label' => 'Departure Time'],
['value' => 'arrival_time', 'label' => 'Arrival Time'],