summaryrefslogtreecommitdiff
path: root/src/Renderer/Twig/Extensions/Authentication.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Renderer/Twig/Extensions/Authentication.php')
-rw-r--r--src/Renderer/Twig/Extensions/Authentication.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Renderer/Twig/Extensions/Authentication.php b/src/Renderer/Twig/Extensions/Authentication.php
new file mode 100644
index 00000000..6a72d825
--- /dev/null
+++ b/src/Renderer/Twig/Extensions/Authentication.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Engelsystem\Renderer\Twig\Extensions;
+
+use Twig_Extension as TwigExtension;
+use Twig_Function as TwigFunction;
+
+class Authentication extends TwigExtension
+{
+ /**
+ * @return TwigFunction[]
+ */
+ public function getFunctions()
+ {
+ return [
+ new TwigFunction('is_user', [$this, 'isAuthenticated']),
+ new TwigFunction('is_guest', [$this, 'isGuest']),
+ new TwigFunction('has_permission_to', [$this, 'checkAuth']),
+ ];
+ }
+
+ public function isAuthenticated()
+ {
+ global $user;
+
+ return !empty($user);
+ }
+
+ public function isGuest()
+ {
+ return !$this->isAuthenticated();
+ }
+
+ public function checkAuth($privilege)
+ {
+ global $privileges;
+
+ return in_array($privilege, $privileges);
+ }
+}