diff --git a/public/static/style.css b/public/static/style.css index 6db3384..39b8f80 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -15,22 +15,73 @@ body { /* --- Header --- */ header { margin: 1em; + display: flex; + justify-content: space-between; + align-content: center; + align-items: center; } header h1 { margin: 1em; } +/* --- Navigation bar --- */ +nav { +} + +nav ul { + display: flex; + padding: 0 1.5em; + border: 0; + border-bottom: 1px solid #000000; +} + +nav ul li { + margin: 0 0 -1px -1px; + list-style: none; + z-index: 1; +} + +nav a { + display: block; + width: 100%; + height: 100%; + padding: 0.5em 1em; + border: 1px solid #999999; + border-bottom-color: #000000; +} + +nav a:link, nav a:visited { + background-color: #eeeeee; + color: blue; + text-decoration: none; +} + +nav a:hover, nav a:focus { + background-color: #ffffff; + text-decoration: underline; +} + +nav li.nav_current_page { + z-index: 10; +} + +nav li.nav_current_page a { + background-color: #ffffff; + border-color: #000000; + border-bottom-color: #ffffff; +} + +/* --- Main section --- */ +main { + margin: 2em; +} + /* --- Login page --- */ main.login_page { margin: 2em; padding: 1em; - border: 1px gray solid; - width: auto; -} - -main.login_page h2 { - margin: 0 0 0.5em 0; + border: 1px solid #666666; } main.login_page table td { @@ -38,6 +89,10 @@ main.login_page table td { } /* --- Text and other styling --- */ +h2 { + margin: 0 0 0.5em 0; +} + .error { background: #ff4444; width: 30em; diff --git a/src/Frontend/BaseController.php b/src/Frontend/BaseController.php index 894488d..70875b4 100644 --- a/src/Frontend/BaseController.php +++ b/src/Frontend/BaseController.php @@ -17,5 +17,9 @@ class BaseController { $this->view = $view; $this->userHelper = $userHelper; + + // Register globals + $twigEnv = $view->getEnvironment(); + $twigEnv->addGlobal('current_user_name', $userHelper->isLoggedIn() ? $userHelper->getCurrentUser()->getUsername() : null); } } diff --git a/src/Frontend/Login/LoginController.php b/src/Frontend/Login/LoginController.php index f486c44..73899d9 100644 --- a/src/Frontend/Login/LoginController.php +++ b/src/Frontend/Login/LoginController.php @@ -59,14 +59,17 @@ class LoginController extends BaseController $user = null; } - if ($user !== null && password_verify($loginPassword, $user->getPasswordHash())) { - $_SESSION['username'] = $user->getUsername(); - return $response - ->withHeader('Location', '/') - ->withStatus(303); - } else { + if ($user === null || !password_verify($loginPassword, $user->getPasswordHash())) { return $this->renderLoginPage($response, ['error' => 'Wrong username or password!']); + } elseif (!$user->isActive()) { + return $this->renderLoginPage($response, ['error' => 'User is inactive!']); } + + // Set login session + $_SESSION['username'] = $user->getUsername(); + return $response + ->withHeader('Location', '/') + ->withStatus(303); } public function logoutUser(Request $request, Response $response): Response diff --git a/templates/base.html.twig b/templates/base.html.twig index 916fab1..fde124d 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -1,18 +1,29 @@ - + {% block title %}Untitled page{% endblock %} - MailAccountAdmin - - + +

MailAccountAdmin

+
+ Hello, {{ current_user_name }}. | Logout +
+ +
{% block content %} Nothing to see here... diff --git a/templates/dashboard.html.twig b/templates/dashboard.html.twig index cf4cb89..2a6f139 100644 --- a/templates/dashboard.html.twig +++ b/templates/dashboard.html.twig @@ -6,15 +6,4 @@

Dashboard

Hello, {{ username }}!

- -
-        ID: {{ user.getId() }}
-        username: {{ user.getUsername() }}
-        password: {{ user.getPasswordHash() }}
-        is_active: {{ user.isActive() }}
-        created_at: {{ user.getCreatedAt() | date() }}
-        modified_at: {{ user.getModifiedAt() | date() }}
-    
- - Logout. {% endblock %} diff --git a/templates/login.html.twig b/templates/login.html.twig index b22a5b8..07fafb6 100644 --- a/templates/login.html.twig +++ b/templates/login.html.twig @@ -1,10 +1,10 @@ - + Login - MailAccountAdmin - - + + @@ -18,7 +18,7 @@
{% if error is defined %} -
{{ error }}
+
{{ error }}
{% endif %} @@ -32,7 +32,9 @@ - +
+ +