Repository navigation
Expand file tree
/
Copy pathProfileLookupController.php
More file actions
45 lines (38 loc) · 1.88 KB
/
Copy pathProfileLookupController.php
File metadata and controls
45 lines (38 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Actions\CreateProfileLookup;
use App\Http\Requests\CreateProfileLookupRequest;
use App\Http\Requests\ShowProfileLookupRequest;
use App\Models\User;
use App\Queries\ProfileLookupQuery;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Symfony\Component\HttpFoundation\Response;
/**
* A handle nobody on /dev/null has may still be someone's on GitHub. Members look it up from its page, which waits for
* GitHub and then shows the profile it found. Guests and crawlers can't, so they can't spend GitHub's budget: they're
* asked to sign in, on a missing page.
*/
final readonly class ProfileLookupController
{
public function show(ShowProfileLookupRequest $request, #[CurrentUser] ?User $currentUser, ProfileLookupQuery $lookups): Response
{
// A missing page isn't remembered for after sign-in (RememberIntendedUrl), but this one is where the guest
// comes back to, to look the handle up. Like there, prefetches and partial reloads, such as the layout's
// notification polling, aren't the guest opening the page.
if (! $currentUser instanceof User && ! $request->prefetch() && ! $request->hasHeader('X-Inertia-Partial-Data')) {
redirect()->setIntendedUrl($request->fullUrl());
}
return Inertia::render('profile/lookup', [
'handle' => $request->handle(),
'lookup' => fn (): ?array => $currentUser instanceof User ? $lookups->get($request->handle()) : null,
])->withViewData(['robots' => 'noindex'])->toResponse($request)->setStatusCode($currentUser instanceof User ? 200 : 404);
}
public function store(CreateProfileLookupRequest $request, CreateProfileLookup $action): RedirectResponse
{
$action->handle($request->handle());
return back();
}
}