Automation init...2
This commit is contained in:
parent
7b7149fbc5
commit
c3858bafd4
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
abstract class AdminController extends BaseController
|
||||
{
|
||||
private $_datas = [];
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
//사용자 기본 Role 지정
|
||||
$this->_datas[SESSION['NAMES']['ISLOGIN']] = false;
|
||||
$this->_datas['currentRoles'] = [DEFAULTS["ROLE"]];
|
||||
if ($this->_session->get(SESSION['NAMES']['ISLOGIN'])) {
|
||||
$this->_datas[SESSION['NAMES']['ISLOGIN']] = true;
|
||||
$this->_datas['auth'] = $this->_session->get(SESSION['NAMES']['AUTH']);
|
||||
$currentRoles = explode(DEFAULTS['DELIMITER_ROLE'], $this->_datas['auth'][AUTH['FIELDS']['ROLE']]);
|
||||
$this->_datas['currentRoles'] = is_array($currentRoles) ? $currentRoles : [DEFAULTS["ROLE"]];
|
||||
}
|
||||
}
|
||||
|
||||
final public function __get($name): array|null
|
||||
{
|
||||
if (!array_key_exists($name, $this->_datas)) {
|
||||
return null;
|
||||
}
|
||||
return $this->_datas;
|
||||
}
|
||||
|
||||
final public function __set($name, $value): void
|
||||
{
|
||||
$this->_datas[$name] = $value;
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
class Home extends AdminController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
return view('welcome_message');
|
||||
}
|
||||
}
|
||||
25
app/Controllers/CommonController.php
Normal file
25
app/Controllers/CommonController.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
abstract class CommonController extends BaseController
|
||||
{
|
||||
private $_datas = [];
|
||||
|
||||
protected function __construct() {}
|
||||
|
||||
final public function __get($name): array|null
|
||||
{
|
||||
if (!array_key_exists($name, $this->_datas)) {
|
||||
return null;
|
||||
}
|
||||
return $this->_datas;
|
||||
}
|
||||
|
||||
final public function __set($name, $value): void
|
||||
{
|
||||
$this->_datas[$name] = $value;
|
||||
}
|
||||
}
|
||||
@ -2,13 +2,16 @@
|
||||
|
||||
namespace App\Controllers\Mangboard\Admin;
|
||||
|
||||
use App\Controllers\Admin\AdminController;
|
||||
use App\Controllers\CommonController;
|
||||
use App\Models\Mangboard\UserModel;
|
||||
use App\Trait\AuthTrait;
|
||||
|
||||
class UserController extends AdminController
|
||||
class UserController extends CommonController
|
||||
{
|
||||
use AuthTrait;
|
||||
public function __construct()
|
||||
{
|
||||
$this->_datas['session'] = $this->login_check();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
21
app/Traits/AuthTrait.php
Normal file
21
app/Traits/AuthTrait.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Trait;
|
||||
|
||||
trait AuthTrait
|
||||
{
|
||||
public function login_check(): array
|
||||
{
|
||||
//사용자 기본 Role 지정
|
||||
$session = [];
|
||||
$session[SESSION['NAMES']['ISLOGIN']] = false;
|
||||
$session['currentRoles'] = [DEFAULTS["ROLE"]];
|
||||
if ($this->_session->get(SESSION['NAMES']['ISLOGIN'])) {
|
||||
$session[SESSION['NAMES']['ISLOGIN']] = true;
|
||||
$session['auth'] = $this->_session->get(SESSION['NAMES']['AUTH']);
|
||||
$currentRoles = explode(DEFAULTS['DELIMITER_ROLE'], $session['auth'][AUTH['FIELDS']['ROLE']]);
|
||||
$session['currentRoles'] = is_array($currentRoles) ? $currentRoles : [DEFAULTS["ROLE"]];
|
||||
}
|
||||
return $session;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user