Files
trafficpumper/app/Support/AuthenticatedRedirect.php
T
2026-08-29 15:53:53 +03:00

53 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Support;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
final class AuthenticatedRedirect
{
private const UNSAFE = ['/', '/login', '/admin/login', '/logout', '/register', '/forgot-password', '/reset-password', '/locale'];
/**
* Müşteri giriş adresinden doğrulanan kullanıcıyı müşteri paneline yönlendirir.
*
* Kullanıcının ek yönetim rolleri hedef paneli değiştirmez; panel bağlamını
* kimlik doğrulamasının başlatıldığı giriş adresi belirler.
*
* @return string Müşteri kontrol panelinin göreli adresi.
*
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
*/
public function landing(): string
{
return route('dashboard', absolute: false);
}
public function intended(Request $r): ?string
{
$value = $r->session()->pull('url.intended');
if (! is_string($value) || $value === '') {
return null;
}$parts = parse_url($value);
if ($parts === false) {
return null;
}if (isset($parts['host'])) {
$port = $parts['port'] ?? (($parts['scheme'] ?? '') === 'https' ? 443 : 80);
if (($parts['scheme'] ?? null) !== $r->getScheme() || $parts['host'] !== $r->getHost() || $port !== $r->getPort()) {
return null;
}$value = ($parts['path'] ?? '/').(isset($parts['query']) ? '?'.$parts['query'] : '');
}$decoded = $value;
for ($i = 0; $i < 3; $i++) {
$decoded = rawurldecode($decoded);
}if (! str_starts_with($decoded, '/') || str_starts_with($decoded, '//') || Str::contains($decoded, ["\r", "\n", '\\'])) {
return null;
}$path = '/'.ltrim((string) parse_url($decoded, PHP_URL_PATH), '/');
if (in_array(rtrim($path, '/') ?: '/', self::UNSAFE, true) || str_starts_with($path, '/admin')) {
return null;
}
return $value;
}
}