chore: commit current workspace changes
This commit is contained in:
@@ -6,6 +6,7 @@ namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\ViewErrorBag;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class ConditionalShareErrorsFromSession extends ShareErrorsFromSession
|
||||
@@ -17,6 +18,8 @@ class ConditionalShareErrorsFromSession extends ShareErrorsFromSession
|
||||
}
|
||||
|
||||
if ($request->attributes->get('skinbase.session_skipped') === true || ! $request->hasSession()) {
|
||||
$this->view->share('errors', new ViewErrorBag());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
23
app/Http/Middleware/EnsureAdminRole.php
Normal file
23
app/Http/Middleware/EnsureAdminRole.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class EnsureAdminRole
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if (! $user || ! $user->isAdmin()) {
|
||||
abort(Response::HTTP_FORBIDDEN, 'Only admins can access this area.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ final class EnsureStaffAccess
|
||||
abort(Response::HTTP_FORBIDDEN, 'Forbidden.');
|
||||
}
|
||||
|
||||
return redirect()->route('home')->with('error', 'You do not have access to this area.');
|
||||
return redirect()->route('index')->with('error', 'You do not have access to this area.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
@@ -22,30 +22,48 @@ class RedirectLegacyProfileSubdomain
|
||||
return redirect()->to($this->targetUrl($request, $canonicalUsername), 301);
|
||||
}
|
||||
|
||||
if ($this->shouldRedirectToCanonicalHost($request)) {
|
||||
return redirect()->to($this->canonicalHostUrl($request), 301);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
private function resolveCanonicalUsername(Request $request): ?string
|
||||
private function shouldRedirectToCanonicalHost(Request $request): bool
|
||||
{
|
||||
return $this->isSingleSubdomainOnConfiguredHost($request);
|
||||
}
|
||||
|
||||
private function isSingleSubdomainOnConfiguredHost(Request $request): bool
|
||||
{
|
||||
$configuredHost = parse_url((string) config('app.url'), PHP_URL_HOST);
|
||||
|
||||
if (! is_string($configuredHost) || $configuredHost === '') {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
$requestHost = strtolower($request->getHost());
|
||||
$configuredHost = strtolower($configuredHost);
|
||||
|
||||
if ($requestHost === $configuredHost || ! str_ends_with($requestHost, '.' . $configuredHost)) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
$subdomain = substr($requestHost, 0, -strlen('.' . $configuredHost));
|
||||
|
||||
if ($subdomain === '' || str_contains($subdomain, '.')) {
|
||||
return $subdomain !== '' && ! str_contains($subdomain, '.');
|
||||
}
|
||||
|
||||
private function resolveCanonicalUsername(Request $request): ?string
|
||||
{
|
||||
if (! $this->isSingleSubdomainOnConfiguredHost($request)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$configuredHost = strtolower((string) parse_url((string) config('app.url'), PHP_URL_HOST));
|
||||
$requestHost = strtolower($request->getHost());
|
||||
$subdomain = substr($requestHost, 0, -strlen('.' . $configuredHost));
|
||||
|
||||
$candidate = UsernamePolicy::normalize($subdomain);
|
||||
|
||||
if ($candidate === '' || $this->isReservedSubdomain($candidate)) {
|
||||
@@ -103,4 +121,16 @@ class RedirectLegacyProfileSubdomain
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
private function canonicalHostUrl(Request $request): string
|
||||
{
|
||||
$target = rtrim((string) config('app.url'), '/') . $request->getPathInfo();
|
||||
$query = $request->getQueryString();
|
||||
|
||||
if (is_string($query) && $query !== '') {
|
||||
$target .= '?' . $query;
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user