Implement basic database access and login
This commit is contained in:
parent
8be7988d97
commit
b24fe56c8a
14 changed files with 307 additions and 31 deletions
33
src/Common/UserHelper.php
Normal file
33
src/Common/UserHelper.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Common;
|
||||
|
||||
use http\Exception\RuntimeException;
|
||||
use MailAccountAdmin\Models\AdminUser;
|
||||
use MailAccountAdmin\Repositories\AdminUserRepository;
|
||||
|
||||
class UserHelper
|
||||
{
|
||||
/** @var AdminUserRepository */
|
||||
private $adminUserRepository;
|
||||
|
||||
public function __construct(AdminUserRepository $adminUserRepository)
|
||||
{
|
||||
$this->adminUserRepository = $adminUserRepository;
|
||||
}
|
||||
|
||||
public function isLoggedIn(): bool
|
||||
{
|
||||
return !empty($_SESSION['username']);
|
||||
}
|
||||
|
||||
public function getCurrentUser(): AdminUser
|
||||
{
|
||||
$username = $_SESSION['username'] ?? null;
|
||||
if (empty($username)) {
|
||||
throw new RuntimeException('Not logged in!');
|
||||
}
|
||||
return $this->adminUserRepository->getUserByName($username);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue