Skip to content
Snippets Groups Projects
Commit 1f280446 authored by Ludovic Ganée's avatar Ludovic Ganée
Browse files

template custom sur exception possible

parent 7db87390
No related branches found
No related tags found
No related merge requests found
Pipeline #85777 failed
......@@ -129,7 +129,11 @@ class OpenIDConnectAuthenticator extends AbstractAuthenticator implements Persis
if ($user && $user->id === null) {
$json['time'] = time();
$this->logout($json);
throw new UnknownUserException;
$exception = new UnknownUserException();
if (!empty($user->get('username'))) {
$exception->username = $user->get('username');
}
throw $exception;
}
if ($user) {
$json['time'] = time();
......
......@@ -108,6 +108,7 @@ class OpenIDConnectIdentifier extends AbstractIdentifier
->set('auth_url', $this->getAuthUrl());
} catch (PDOException|MissingConnectionException|RecordNotFoundException $e) {
return $Users->newEmptyEntity()
->set('username', $json ? ($json[$this->getConfig('username')] ?? null) : null)
->set('auth_openid', true);
}
} elseif ($json) {
......
......@@ -19,6 +19,11 @@ use Throwable;
*/
class UnknownUserException extends HttpException
{
/**
* @var string|null
*/
public $username = null;
/**
* Construct the exception. Note: The message is NOT binary safe.
* @link https://php.net/manual/en/exception.construct.php
......
......@@ -318,4 +318,25 @@ class AppExceptionRenderer extends WebExceptionRenderer
return $code;
}
/**
* Get template for rendering exception info.
*
* @param Throwable $exception Exception instance.
* @param string $method Method name.
* @param int $code Error code.
* @return string Template name
*/
protected function _template(Throwable $exception, string $method, int $code): string
{
$customTemplate = Configure::read('AppExceptionRenderer.custom_templates.' . get_class($exception));
if ($customTemplate && !empty($customTemplate['template'])) {
if ($customTemplate['layout'] ?? false) {
$builder = $this->controller->viewBuilder();
$builder->setLayout($customTemplate['layout']);
}
return $customTemplate['template'];
}
return parent::_template($exception, $method, $code);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment