34 lines
1 KiB
PHP
34 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Lib;
|
|
|
|
use Illuminate\Routing\Route as RoutingRoute;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
abstract class ToolboxHelper
|
|
{
|
|
/**
|
|
* * Needed rules as backend and frontend shares the same login functions
|
|
* Determine if login is allowed only if:
|
|
* Intended url was a BO route (and not already logged in as web guard),
|
|
* else customer is not already logged in.
|
|
*
|
|
* ! The only way to log in as admin is to access a bo route first.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public static function isLoginAccessAllowed(): bool
|
|
{
|
|
$isBo = false;
|
|
|
|
$path = \parse_url(\session()->get('url.intended', url('/')), \PHP_URL_PATH);
|
|
|
|
collect(Route::getRoutes()->getRoutes())
|
|
->map(function (RoutingRoute $route) use (&$isBo, $path) {
|
|
if (trim($path, '/') === $route->uri() and trim($route->getPrefix(), '/') === 'bo') {
|
|
$isBo = true;
|
|
}
|
|
});
|
|
return $isBo ? auth('web')->guest() : auth('customer')->guest();
|
|
}
|
|
}
|