summaryrefslogtreecommitdiff
path: root/src/Renderer
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-08 19:30:37 +0200
committermsquare <msquare@notrademark.de>2018-10-31 13:43:23 +0100
commitd15946df2dfb0ae2f0ca9371e5c8071df91ab45a (patch)
tree49601aafd74da5a781920543ed92bbd180fe5e89 /src/Renderer
parent8e62c4c52c27f9432820915deeb699c3d1f58ce7 (diff)
Changed `src/` code and templates to use the new user model
Diffstat (limited to 'src/Renderer')
-rw-r--r--src/Renderer/Twig/Extensions/Authentication.php26
-rw-r--r--src/Renderer/Twig/Extensions/Globals.php16
2 files changed, 37 insertions, 5 deletions
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;
diff --git a/src/Renderer/Twig/Extensions/Globals.php b/src/Renderer/Twig/Extensions/Globals.php
index f9bffbc8..ef29a819 100644
--- a/src/Renderer/Twig/Extensions/Globals.php
+++ b/src/Renderer/Twig/Extensions/Globals.php
@@ -2,11 +2,23 @@
namespace Engelsystem\Renderer\Twig\Extensions;
+use Engelsystem\Helpers\Authenticator;
use Twig_Extension as TwigExtension;
use Twig_Extension_GlobalsInterface as GlobalsInterface;
class Globals extends TwigExtension implements GlobalsInterface
{
+ /** @var Authenticator */
+ protected $auth;
+
+ /**
+ * @param Authenticator $auth
+ */
+ public function __construct(Authenticator $auth)
+ {
+ $this->auth = $auth;
+ }
+
/**
* Returns a list of global variables to add to the existing list.
*
@@ -14,10 +26,10 @@ class Globals extends TwigExtension implements GlobalsInterface
*/
public function getGlobals()
{
- global $user;
+ $user = $this->auth->user();
return [
- 'user' => isset($user) ? $user : [],
+ 'user' => $user ? $user : [],
];
}
}