Implement Account model; small style changes; Twig debug setting
This commit is contained in:
parent
7859ef77ee
commit
32add30c9d
10 changed files with 263 additions and 56 deletions
|
|
@ -5,6 +5,7 @@ namespace MailAccountAdmin\Frontend\Accounts;
|
|||
|
||||
use MailAccountAdmin\Common\UserHelper;
|
||||
use MailAccountAdmin\Frontend\BaseController;
|
||||
use MailAccountAdmin\Models\Account;
|
||||
use MailAccountAdmin\Repositories\AccountRepository;
|
||||
use MailAccountAdmin\Repositories\AliasRepository;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
|
@ -25,6 +26,9 @@ class AccountController extends BaseController
|
|||
$this->aliasRepository = $aliasRepository;
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts - List all accounts
|
||||
|
||||
public function showAccounts(Request $request, Response $response): Response
|
||||
{
|
||||
// Parse query parameters for filters
|
||||
|
|
@ -39,21 +43,22 @@ class AccountController extends BaseController
|
|||
return $this->view->render($response, 'accounts.html.twig', $renderData);
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts/{id} - Show account details
|
||||
|
||||
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];
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
|
||||
// Don't display the password hash, but at least the type of hash (used hash algorithm)
|
||||
if ($accountData['password'] === '') {
|
||||
if ($account->getPasswordHash() === '') {
|
||||
$passwordHashType = 'empty';
|
||||
} else {
|
||||
$passwordHashInfo = password_get_info($accountData['password']);
|
||||
$passwordHashInfo = password_get_info($account->getPasswordHash());
|
||||
$passwordHashType = $passwordHashInfo['algoName'] ?? 'unknown';
|
||||
}
|
||||
|
||||
|
|
@ -62,8 +67,8 @@ class AccountController extends BaseController
|
|||
|
||||
$renderData = [
|
||||
'id' => $accountId,
|
||||
'accountUsername' => $accountUsername,
|
||||
'accountData' => $accountData,
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'account' => $account,
|
||||
'passwordHashType' => $passwordHashType,
|
||||
'aliases' => $aliases,
|
||||
];
|
||||
|
|
@ -71,26 +76,27 @@ class AccountController extends BaseController
|
|||
return $this->view->render($response, 'account_details.html.twig', $renderData);
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts/new - Create new account
|
||||
|
||||
public function showAccountCreate(Request $request, Response $response): Response
|
||||
{
|
||||
return $this->showAccounts($request, $response);
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts/{id}/edit - Edit account
|
||||
|
||||
public function showAccountEdit(Request $request, Response $response, array $args): Response
|
||||
{
|
||||
// Parse URL arguments
|
||||
$accountId = (int)$args['id'];
|
||||
|
||||
// Get account data from database
|
||||
$accountData = $this->accountRepository->fetchAccountById($accountId);
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
|
||||
$renderData = [
|
||||
'id' => $accountId,
|
||||
'accountUsername' => $accountData['username'],
|
||||
'accountData' => $accountData,
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'account_edit.html.twig', $renderData);
|
||||
// Render page
|
||||
return $this->renderEditPage($response, $account);
|
||||
}
|
||||
|
||||
public function editAccount(Request $request, Response $response, array $args): Response
|
||||
|
|
@ -100,18 +106,31 @@ class AccountController extends BaseController
|
|||
return $this->showAccountEdit($request, $response, $args);
|
||||
}
|
||||
|
||||
private function renderEditPage(Response $response, Account $account, array $extraRenderData = []): Response
|
||||
{
|
||||
$renderData = [
|
||||
'id' => $account->getId(),
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'account' => $account,
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'account_edit.html.twig', array_merge($renderData, $extraRenderData));
|
||||
}
|
||||
|
||||
// -- /accounts/{id}/delete - Delete account
|
||||
|
||||
public function showAccountDelete(Request $request, Response $response, array $args): Response
|
||||
{
|
||||
// Parse URL arguments
|
||||
$accountId = (int)$args['id'];
|
||||
|
||||
// Get account data and list of aliases from database
|
||||
$accountData = $this->accountRepository->fetchAccountById($accountId);
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
$aliases = $this->aliasRepository->fetchAliasesForUserId($accountId);
|
||||
|
||||
$renderData = [
|
||||
'id' => $accountId,
|
||||
'accountUsername' => $accountData['username'],
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'aliases' => $aliases,
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue