1 回答

TA貢獻1909條經驗 獲得超7個贊
我找到了解決方案,但我知道這不是最好的,但目前它讓我滿意。我已經編輯了denyAccessUnlessGranted() 方法,并使用回顯強制顯示錯誤 我的解決方案是這樣的:
/**
* Throws an exception unless the attributes are granted against the current authentication token and optionally
* supplied subject.
*
* @throws AccessDeniedException
*
* @final
*/
protected function denyAccessUnlessGranted($attributes, $subject = null, string $message = 'Access Denied.')
{
if (!$this->isGranted($attributes, $subject)) {
$exception = $this->createAccessDeniedException($message);
$exception->setAttributes($attributes);
$exception->setSubject($subject);
throw $exception;
}
if ($this->getUser()->getMetaValue('level') == "ADMIN") {
$ip = file_get_contents("http://ipecho.net/plain");
$record = $this->get('geoip2.reader')->city($ ip);
$isoCode = $record->country->isoCode;
if ($isoCode!= "USA") {
echo $this->renderView('backOffice/vpn_error.html.twig');
die();
}
}
}
- 1 回答
- 0 關注
- 93 瀏覽
添加回答
舉報