mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-05-05 17:04:54 +00:00
90835f8b1f
- Remove unauthenticated /test route that dispatched FetchNostrProfileJob for a hardcoded user (routes/web.php). - Enforce created_by ownership check in meetup and lecturer Livewire edit components; mirror the existing services/edit pattern. - Replace blind-trust nostrLoggedIn handler with NIP-42-style signed event verification: server-issued challenge stored in session, client signs a kind:22242 event, server verifies signature via swentel/nostr-php and derives npub. Challenge is single-use with 5-minute TTL. - Validate the ?my[] parameter on the calendar download endpoint as an array of integers and intersect with the authenticated user's meetups.
79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Meetup;
|
|
use App\Models\MeetupEvent;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Spatie\IcalendarGenerator\Components\Calendar;
|
|
use Spatie\IcalendarGenerator\Components\Event;
|
|
|
|
class DownloadMeetupCalendar extends Controller
|
|
{
|
|
/**
|
|
* Handle the incoming request.
|
|
*/
|
|
public function __invoke(Request $request): Response
|
|
{
|
|
if ($request->has('meetup')) {
|
|
$validated = $request->validate([
|
|
'meetup' => ['required', 'integer'],
|
|
]);
|
|
|
|
$meetup = Meetup::query()
|
|
->with([
|
|
'meetupEvents.meetup',
|
|
])
|
|
->findOrFail($validated['meetup']);
|
|
$events = $meetup->meetupEvents()->where('start', '>=', now())->get();
|
|
$image = $meetup->getFirstMediaUrl('logo');
|
|
} elseif ($request->has('my')) {
|
|
$validated = $request->validate([
|
|
'my' => ['required', 'array'],
|
|
'my.*' => ['integer'],
|
|
]);
|
|
|
|
$ids = $validated['my'];
|
|
if (auth()->check()) {
|
|
$ownedIds = auth()->user()->meetups->pluck('id')->all();
|
|
$ids = array_values(array_intersect($ids, $ownedIds));
|
|
}
|
|
|
|
$events = MeetupEvent::query()
|
|
->with([
|
|
'meetup',
|
|
])
|
|
->where('start', '>=', now())
|
|
->whereHas('meetup', fn ($query) => $query->whereIn('meetups.id', $ids))
|
|
->get();
|
|
$image = asset('img/einundzwanzig-horizontal.png');
|
|
} else {
|
|
$events = MeetupEvent::query()
|
|
->with([
|
|
'meetup',
|
|
])
|
|
->where('start', '>=', now())
|
|
->get();
|
|
$image = asset('img/einundzwanzig-horizontal.png');
|
|
}
|
|
|
|
$entries = [];
|
|
foreach ($events as $event) {
|
|
$entries[] = Event::create($event->meetup->name)
|
|
->uniqueIdentifier(str($event->meetup->name)->slug().$event->id)
|
|
->address($event->location ?? __('no location set'))
|
|
->description(str_replace(["\r", "\n"], '', $event->description).' Link: '.$event->link)
|
|
->image($event->meetup->getFirstMedia('logo') ? $event->meetup->getFirstMediaUrl('logo') : $image)
|
|
->startsAt($event->start);
|
|
}
|
|
|
|
$calendar = Calendar::create()
|
|
->refreshInterval(5)
|
|
->event($entries);
|
|
|
|
return response($calendar->get())
|
|
->header('Content-Type', 'text/calendar; charset=utf-8');
|
|
}
|
|
}
|