Compare commits
No commits in common. "b890432e5b9a5b95e820373c695dc8b1a13ca358" and "e58036b2b35cc935b98c9c4d422132bc89a7e168" have entirely different histories.
b890432e5b
...
e58036b2b3
|
|
@ -31,7 +31,6 @@ nav {
|
|||
|
||||
nav ul {
|
||||
display: flex;
|
||||
margin: -1px 0 0 0;
|
||||
padding: 0 1.5em;
|
||||
border: 0;
|
||||
border-bottom: 1px solid #000000;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ class AuthMiddleware implements MiddlewareInterface
|
|||
// TODO: Lots of stuff. Session middleware, auth handler class, etc...
|
||||
if ($uri->getPath() !== '/login') {
|
||||
// Check authorization via session
|
||||
if (empty($_SESSION['user_id'])) {
|
||||
// TODO username or user ID?
|
||||
if (empty($_SESSION['username'])) {
|
||||
// Not logged in -> Redirect to /login
|
||||
$response = new Response();
|
||||
return $response
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@ class UserHelper
|
|||
|
||||
public function isLoggedIn(): bool
|
||||
{
|
||||
return !empty($_SESSION['user_id']);
|
||||
return !empty($_SESSION['username']);
|
||||
}
|
||||
|
||||
public function getCurrentUser(): AdminUser
|
||||
{
|
||||
$userId = $_SESSION['user_id'] ?? null;
|
||||
if (empty($userId)) {
|
||||
$username = $_SESSION['username'] ?? null;
|
||||
if (empty($username)) {
|
||||
throw new RuntimeException('Not logged in!');
|
||||
}
|
||||
return $this->adminUserRepository->getUserById($userId);
|
||||
return $this->adminUserRepository->getUserByName($username);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ namespace MailAccountAdmin;
|
|||
|
||||
use DI\Container;
|
||||
use MailAccountAdmin\Common\UserHelper;
|
||||
use MailAccountAdmin\Frontend\Accounts\AccountController;
|
||||
use MailAccountAdmin\Frontend\Domains\DomainController;
|
||||
use MailAccountAdmin\Frontend\Login\LoginController;
|
||||
use MailAccountAdmin\Frontend\Dashboard\DashboardController;
|
||||
use MailAccountAdmin\Repositories\AdminUserRepository;
|
||||
|
|
@ -66,7 +64,7 @@ class Dependencies
|
|||
);
|
||||
});
|
||||
|
||||
// Frontend controllers
|
||||
// Login page
|
||||
$container->set(LoginController::class, function (ContainerInterface $c) {
|
||||
return new LoginController(
|
||||
$c->get(self::TWIG),
|
||||
|
|
@ -74,24 +72,14 @@ class Dependencies
|
|||
$c->get(AdminUserRepository::class),
|
||||
);
|
||||
});
|
||||
|
||||
// Dashboard
|
||||
$container->set(DashboardController::class, function (ContainerInterface $c) {
|
||||
return new DashboardController(
|
||||
$c->get(self::TWIG),
|
||||
$c->get(UserHelper::class),
|
||||
);
|
||||
});
|
||||
$container->set(DomainController::class, function (ContainerInterface $c) {
|
||||
return new DomainController(
|
||||
$c->get(self::TWIG),
|
||||
$c->get(UserHelper::class),
|
||||
);
|
||||
});
|
||||
$container->set(AccountController::class, function (ContainerInterface $c) {
|
||||
return new AccountController(
|
||||
$c->get(self::TWIG),
|
||||
$c->get(UserHelper::class),
|
||||
);
|
||||
});
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Frontend\Accounts;
|
||||
|
||||
use MailAccountAdmin\Frontend\BaseController;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class AccountController extends BaseController
|
||||
{
|
||||
public function showAccounts(Request $request, Response $response): Response
|
||||
{
|
||||
$renderData = [
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'accounts.html.twig', $renderData);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,13 @@ class DashboardController extends BaseController
|
|||
{
|
||||
public function showDashboard(Request $request, Response $response): Response
|
||||
{
|
||||
return $this->view->render($response, 'dashboard.html.twig');
|
||||
$currentUser = $this->userHelper->getCurrentUser();
|
||||
|
||||
$renderData = [
|
||||
'username' => $currentUser->getUsername(),
|
||||
'user' => $currentUser,
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'dashboard.html.twig', $renderData);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Frontend\Domains;
|
||||
|
||||
use MailAccountAdmin\Frontend\BaseController;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class DomainController extends BaseController
|
||||
{
|
||||
public function showDomains(Request $request, Response $response): Response
|
||||
{
|
||||
$renderData = [
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'domains.html.twig', $renderData);
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ class LoginController extends BaseController
|
|||
}
|
||||
|
||||
// Set login session
|
||||
$_SESSION['user_id'] = $user->getId();
|
||||
$_SESSION['username'] = $user->getUsername();
|
||||
return $response
|
||||
->withHeader('Location', '/')
|
||||
->withStatus(303);
|
||||
|
|
|
|||
|
|
@ -17,22 +17,6 @@ class AdminUserRepository
|
|||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws AdminUserNotFoundException
|
||||
*/
|
||||
public function getUserById(int $userId): AdminUser
|
||||
{
|
||||
$statement = $this->pdo->prepare('SELECT * FROM admin_users WHERE admin_id = :admin_id LIMIT 1');
|
||||
$statement->execute(['admin_id' => $userId]);
|
||||
|
||||
if ($statement->rowCount() < 1) {
|
||||
throw new AdminUserNotFoundException("Admin with ID '$userId' was not found.");
|
||||
}
|
||||
|
||||
$row = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
return AdminUser::createFromArray($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws AdminUserNotFoundException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace MailAccountAdmin;
|
||||
|
||||
use MailAccountAdmin\Frontend\Accounts\AccountController;
|
||||
use MailAccountAdmin\Frontend\Dashboard\DashboardController;
|
||||
use MailAccountAdmin\Frontend\Domains\DomainController;
|
||||
use MailAccountAdmin\Frontend\Login\LoginController;
|
||||
use Slim\App;
|
||||
|
||||
|
|
@ -20,13 +18,5 @@ class Routes
|
|||
|
||||
// Dashboard
|
||||
$app->get('/', DashboardController::class . ':showDashboard');
|
||||
|
||||
// Domains
|
||||
$app->get('/domains', DomainController::class . ':showDomains');
|
||||
$app->get('/domains/{foo}', DomainController::class . ':showDomains');
|
||||
|
||||
// Accounts
|
||||
$app->get('/accounts', AccountController::class . ':showAccounts');
|
||||
$app->get('/accounts/{foo}', AccountController::class . ':showAccounts');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block title %}Accounts{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Accounts</h2>
|
||||
|
||||
<p>List of accounts ... <b>TODO</b></p>
|
||||
<p><a href="/accounts/42">Test</a></p>
|
||||
{% endblock %}
|
||||
|
|
@ -18,15 +18,9 @@
|
|||
|
||||
<nav>
|
||||
<ul>
|
||||
{% macro navbar_item(path, text) -%}
|
||||
<li{% if current_url() == path or current_url() starts with path ~ '/' %} class="nav_current_page"{% endif %}>
|
||||
<a href="{{ path }}">{{ text }}</a>
|
||||
</li>
|
||||
{%- endmacro -%}
|
||||
|
||||
{{ _self.navbar_item('/', 'Dashboard') }}
|
||||
{{ _self.navbar_item('/domains', 'Domains') }}
|
||||
{{ _self.navbar_item('/accounts', 'Accounts') }}
|
||||
<li class="nav_current_page"><a href="/">Dashboard</a></li>
|
||||
<li><a href="/domains">Domains</a></li>
|
||||
<li><a href="/accounts">Accounts</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
{% block content %}
|
||||
<h2>Dashboard</h2>
|
||||
|
||||
<p>Hello, {{ current_user_name }}!</p>
|
||||
<p>Hello, {{ username }}!</p>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block title %}Domains{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Domains</h2>
|
||||
|
||||
<p>List of domains ... <b>TODO</b></p>
|
||||
<p><a href="/domains/42">Test</a></p>
|
||||
{% endblock %}
|
||||
Loading…
Reference in New Issue