From d15946df2dfb0ae2f0ca9371e5c8071df91ab45a Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 8 Oct 2018 19:30:37 +0200 Subject: Changed `src/` code and templates to use the new user model --- src/Renderer/Twig/Extensions/Authentication.php | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/Renderer/Twig/Extensions/Authentication.php') diff --git a/src/Renderer/Twig/Extensions/Authentication.php b/src/Renderer/Twig/Extensions/Authentication.php index 6a72d825..20ede828 100644 --- a/src/Renderer/Twig/Extensions/Authentication.php +++ b/src/Renderer/Twig/Extensions/Authentication.php @@ -2,11 +2,23 @@ namespace Engelsystem\Renderer\Twig\Extensions; +use Engelsystem\Helpers\Authenticator; use Twig_Extension as TwigExtension; use Twig_Function as TwigFunction; class Authentication extends TwigExtension { + /** @var Authenticator */ + protected $auth; + + /** + * @param Authenticator $auth + */ + public function __construct(Authenticator $auth) + { + $this->auth = $auth; + } + /** * @return TwigFunction[] */ @@ -19,18 +31,26 @@ class Authentication extends TwigExtension ]; } + /** + * @return bool + */ public function isAuthenticated() { - global $user; - - return !empty($user); + return (bool)$this->auth->user(); } + /** + * @return bool + */ public function isGuest() { return !$this->isAuthenticated(); } + /** + * @param $privilege + * @return bool + */ public function checkAuth($privilege) { global $privileges; -- cgit v1.2.3-70-g09d2