2021-07-29 18:15:38 +02:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace MailAccountAdmin\Frontend\Accounts;
|
|
|
|
|
|
2021-07-30 03:46:43 +02:00
|
|
|
use MailAccountAdmin\Common\UserHelper;
|
2021-07-29 18:15:38 +02:00
|
|
|
use MailAccountAdmin\Frontend\BaseController;
|
2021-07-30 03:46:43 +02:00
|
|
|
use MailAccountAdmin\Repositories\AccountRepository;
|
2021-07-30 22:30:30 +02:00
|
|
|
use MailAccountAdmin\Repositories\AliasRepository;
|
2021-07-29 18:15:38 +02:00
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
2021-07-30 03:46:43 +02:00
|
|
|
use Slim\Views\Twig;
|
2021-07-29 18:15:38 +02:00
|
|
|
|
|
|
|
|
class AccountController extends BaseController
|
|
|
|
|
{
|
2021-07-30 03:46:43 +02:00
|
|
|
/** @var AccountRepository */
|
|
|
|
|
private $accountRepository;
|
2021-07-30 22:30:30 +02:00
|
|
|
/** @var AliasRepository */
|
|
|
|
|
private $aliasRepository;
|
2021-07-30 03:46:43 +02:00
|
|
|
|
2021-07-30 22:30:30 +02:00
|
|
|
public function __construct(Twig $view, UserHelper $userHelper, AccountRepository $accountRepository, AliasRepository $aliasRepository)
|
2021-07-30 03:46:43 +02:00
|
|
|
{
|
|
|
|
|
parent::__construct($view, $userHelper);
|
|
|
|
|
$this->accountRepository = $accountRepository;
|
2021-07-30 22:30:30 +02:00
|
|
|
$this->aliasRepository = $aliasRepository;
|
2021-07-30 03:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-29 18:15:38 +02:00
|
|
|
public function showAccounts(Request $request, Response $response): Response
|
|
|
|
|
{
|
2021-07-30 03:46:43 +02:00
|
|
|
// Parse query parameters for filters
|
|
|
|
|
$queryParams = $request->getQueryParams();
|
|
|
|
|
$filterByDomain = $queryParams['domain'] ?? null;
|
|
|
|
|
|
2021-07-29 18:15:38 +02:00
|
|
|
$renderData = [
|
2021-07-30 03:46:43 +02:00
|
|
|
'filterDomain' => $filterByDomain,
|
|
|
|
|
'accountList' => $this->accountRepository->fetchAccountList($filterByDomain),
|
2021-07-29 18:15:38 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $this->view->render($response, 'accounts.html.twig', $renderData);
|
|
|
|
|
}
|
2021-07-30 22:30:30 +02:00
|
|
|
|
|
|
|
|
public function showAccountDetails(Request $request, Response $response, array $args): Response
|
|
|
|
|
{
|
|
|
|
|
// Parse URL arguments
|
|
|
|
|
$accountId = (int)$args['id'];
|
|
|
|
|
|
|
|
|
|
// Get account data from database
|
|
|
|
|
$accountData = $this->accountRepository->fetchAccountById($accountId);
|
|
|
|
|
$accountUsername = $accountData['username'];
|
|
|
|
|
$accountData['domain'] = explode('@', $accountUsername, 2)[1];
|
|
|
|
|
|
|
|
|
|
// Don't display the password hash, but at least the type of hash (used hash algorithm)
|
|
|
|
|
if ($accountData['password'] === '') {
|
|
|
|
|
$passwordHashType = 'empty';
|
|
|
|
|
} else {
|
|
|
|
|
$passwordHashInfo = password_get_info($accountData['password']);
|
|
|
|
|
$passwordHashType = $passwordHashInfo['algoName'] ?? 'unknown';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get list of aliases for this account
|
|
|
|
|
$aliases = $this->aliasRepository->fetchAliasesForUserId($accountId);
|
|
|
|
|
|
|
|
|
|
$renderData = [
|
|
|
|
|
'id' => $accountId,
|
|
|
|
|
'accountUsername' => $accountUsername,
|
|
|
|
|
'accountData' => $accountData,
|
|
|
|
|
'passwordHashType' => $passwordHashType,
|
|
|
|
|
'aliases' => $aliases,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $this->view->render($response, 'account_details.html.twig', $renderData);
|
|
|
|
|
}
|
2021-07-29 18:15:38 +02:00
|
|
|
}
|