diff --git a/lib/Framework/Controller.php b/lib/Framework/Controller.php index 62146f5..c36d74f 100644 --- a/lib/Framework/Controller.php +++ b/lib/Framework/Controller.php @@ -51,6 +51,10 @@ abstract class Controller */ public function render(string $template, array $vars = []): Response { + if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { + $vars['flashes'] = $_SESSION['flashes']; + $_SESSION['flashes'] = []; + } $response = new Response($this->twig->render($template, $vars)); return $response; } @@ -59,4 +63,9 @@ abstract class Controller { return $this->kernel->getRouter()->getUrlForRoute($route); } + + public function addFlash(string $category, string $content): void + { + $_SESSION['flashes'][] = ['category' => $category, 'content' => $content]; + } } \ No newline at end of file diff --git a/lib/Framework/Twig.php b/lib/Framework/Twig.php index e016404..3352137 100644 --- a/lib/Framework/Twig.php +++ b/lib/Framework/Twig.php @@ -30,7 +30,7 @@ class Twig public function addFunctions() { - $path = new TwigFunction('path', function(string $route, array $params) { + $path = new TwigFunction('path', function(string $route, array $params = []) { return $this->kernel->getRouter()->getUrlForRoute($route, $params); }); $this->environment->addFunction($path); diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index a687da7..cc00b3c 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -27,6 +27,7 @@ class SecurityController extends Controller $_SESSION['isAuthenticated'] = true; return new RedirectResponse($this->generateRoute('default')); } + $this->addFlash('danger', 'Username or password incorrect'); return new RedirectResponse($this->generateRoute('login')); } } \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index eb069de..605a2e9 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -4,40 +4,36 @@ Webcron management :: {% block title %}{% endblock %} - - - - - - - - - - - + + + + + + + -
- -
-
-
-
-
- +
+
+
+
-
-
- {% block content %}{% endblock %} +
+ +
+ {% block content %}{% endblock %} +
+
diff --git a/templates/flashes.html.twig b/templates/flashes.html.twig new file mode 100644 index 0000000..18c3040 --- /dev/null +++ b/templates/flashes.html.twig @@ -0,0 +1,6 @@ +{% for flash in flashes %} + +{% endfor %} \ No newline at end of file diff --git a/templates/job/index.html.twig b/templates/job/index.html.twig index b29ff80..eec1d14 100644 --- a/templates/job/index.html.twig +++ b/templates/job/index.html.twig @@ -22,11 +22,11 @@ {{ job.data.host }} {{ job.delay | interval }} {{ job.nextrun | date("d/m/Y H:i:s") }} - - - - - + + + + + {% endfor %} diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index e7bf721..8fa3968 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -4,41 +4,38 @@ Webcron management :: Log in - - - + + - - - + + -
-

Webcron management

-
- {% if not error == "" %} -
- × - Error! {{ error }} -
- {% endif %} +
+
+
+ {{ include('flashes.html.twig') }} +

Webcron management

+ -
- - +
+ + +
+
+ + +
+
+ + +
+ +
-
- - -
-
- - -
- - +
\ No newline at end of file