cfmgrv4 init...1
This commit is contained in:
parent
2bbea6a4b0
commit
904e79a7b6
@ -6,15 +6,14 @@ use App\Controllers\BaseController;
|
|||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use App\Traits\AuthTrait;
|
|
||||||
|
|
||||||
abstract class CommonController extends BaseController
|
abstract class CommonController extends BaseController
|
||||||
{
|
{
|
||||||
use AuthTrait;
|
|
||||||
private $_viewDatas = [];
|
private $_viewDatas = [];
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
parent::initController($request, $response, $logger);
|
parent::initController($request, $response, $logger);
|
||||||
|
$this->session = service('session');
|
||||||
helper("common");
|
helper("common");
|
||||||
}
|
}
|
||||||
final public function __get($name)
|
final public function __get($name)
|
||||||
|
|||||||
@ -18,7 +18,7 @@ abstract class MVController extends CommonController
|
|||||||
{
|
{
|
||||||
parent::initController($request, $response, $logger);
|
parent::initController($request, $response, $logger);
|
||||||
helper('common');
|
helper('common');
|
||||||
$this->session = $this->session_AuthTrait();
|
$this->session = service('session');
|
||||||
}
|
}
|
||||||
abstract protected function getModel(): mixed;
|
abstract protected function getModel(): mixed;
|
||||||
//Field별 Form Rule용
|
//Field별 Form Rule용
|
||||||
@ -89,7 +89,9 @@ abstract class MVController extends CommonController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected function create_form_process(): void {}
|
protected function create_form_process(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
final protected function create_form_procedure(): RedirectResponse|string
|
final protected function create_form_procedure(): RedirectResponse|string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -265,7 +267,6 @@ abstract class MVController extends CommonController
|
|||||||
$this->getModel()->transRollback();
|
$this->getModel()->transRollback();
|
||||||
log_message("error", $e->getMessage());
|
log_message("error", $e->getMessage());
|
||||||
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
|
||||||
$this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
||||||
return redirect()->back()->withInput();
|
return redirect()->back()->withInput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,7 +317,7 @@ abstract class MVController extends CommonController
|
|||||||
}
|
}
|
||||||
//검색일 처리
|
//검색일 처리
|
||||||
$this->start = $this->request->getVar('start') ?: DEFAULTS['EMPTY'];
|
$this->start = $this->request->getVar('start') ?: DEFAULTS['EMPTY'];
|
||||||
$this->end = $this->request->getVar('end') ?: DEFAULTS['EMPTY'];
|
$this->end = $this->request->getVar('end') ?: DEFAULTS['EMPTY'];
|
||||||
$this->getModel()->setList_DateFilter($this->start, $this->end);
|
$this->getModel()->setList_DateFilter($this->start, $this->end);
|
||||||
}
|
}
|
||||||
//Totalcount 처리
|
//Totalcount 처리
|
||||||
@ -331,8 +332,8 @@ abstract class MVController extends CommonController
|
|||||||
private function list_pagination_process($pager_group = 'default', int $segment = 0, $template = 'default_full'): string
|
private function list_pagination_process($pager_group = 'default', int $segment = 0, $template = 'default_full'): string
|
||||||
{
|
{
|
||||||
//Page, Per_page필요부분
|
//Page, Per_page필요부분
|
||||||
$this->page = (int)$this->request->getVar('page') ?: 1;
|
$this->page = (int) $this->request->getVar('page') ?: 1;
|
||||||
$this->per_page = (int)$this->request->getVar('per_page') ?: intval(getenv("mvc.default.list.per_page"));
|
$this->per_page = (int) $this->request->getVar('per_page') ?: intval(getenv("mvc.default.list.per_page"));
|
||||||
//줄수 처리용
|
//줄수 처리용
|
||||||
$page_options = array("" => "줄수선택");
|
$page_options = array("" => "줄수선택");
|
||||||
for ($i = $this->per_page; $i <= $this->total_count; $i += $this->per_page) {
|
for ($i = $this->per_page; $i <= $this->total_count; $i += $this->per_page) {
|
||||||
@ -352,7 +353,7 @@ abstract class MVController extends CommonController
|
|||||||
$segment,
|
$segment,
|
||||||
$pager_group
|
$pager_group
|
||||||
);
|
);
|
||||||
$this->page = $pager->getCurrentPage($pager_group);
|
$this->page = $pager->getCurrentPage($pager_group);
|
||||||
$this->total_page = $pager->getPageCount($pager_group);
|
$this->total_page = $pager->getPageCount($pager_group);
|
||||||
return $pager->links($pager_group, $template);
|
return $pager->links($pager_group, $template);
|
||||||
}
|
}
|
||||||
@ -364,7 +365,7 @@ abstract class MVController extends CommonController
|
|||||||
$this->order_value = $this->request->getVar('order_value') ?: DEFAULTS['EMPTY'];
|
$this->order_value = $this->request->getVar('order_value') ?: DEFAULTS['EMPTY'];
|
||||||
$this->getModel()->setList_OrderBy(
|
$this->getModel()->setList_OrderBy(
|
||||||
$this->order_field !== DEFAULTS['EMPTY'] &&
|
$this->order_field !== DEFAULTS['EMPTY'] &&
|
||||||
$this->order_value !== DEFAULTS['EMPTY'] ? "{$this->order_field} {$this->order_value}" : ""
|
$this->order_value !== DEFAULTS['EMPTY'] ? "{$this->order_field} {$this->order_value}" : ""
|
||||||
);
|
);
|
||||||
if ($this->page) {
|
if ($this->page) {
|
||||||
$this->getModel()->limit(
|
$this->getModel()->limit(
|
||||||
@ -390,7 +391,9 @@ abstract class MVController extends CommonController
|
|||||||
//모델 처리
|
//모델 처리
|
||||||
$this->entitys = $this->list_entitys_process();
|
$this->entitys = $this->list_entitys_process();
|
||||||
//setting return_url to session flashdata
|
//setting return_url to session flashdata
|
||||||
$this->session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . $this->uri->getQuery() ? "?" . $this->uri->getQuery() : "");
|
// RETURN_URL을 일반 세션 데이터로 저장
|
||||||
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . ($this->uri->getQuery() ? "?" . $this->uri->getQuery() : ""));
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
$this->view_path . "/index",
|
$this->view_path . "/index",
|
||||||
['viewDatas' => $this->getViewDatas()]
|
['viewDatas' => $this->getViewDatas()]
|
||||||
@ -398,7 +401,7 @@ abstract class MVController extends CommonController
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
log_message("error", $e->getMessage());
|
log_message("error", $e->getMessage());
|
||||||
return alert_CommonHelper($e->getMessage(), "back");
|
return alert_CommonHelper($e->getMessage(), "back");
|
||||||
// return redirect()->back()->with('return_message', $e->getMessage());
|
// return redirect()->back()->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +456,7 @@ abstract class MVController extends CommonController
|
|||||||
$reader = new Html();
|
$reader = new Html();
|
||||||
$loaded_data = $reader->loadFromString($html);
|
$loaded_data = $reader->loadFromString($html);
|
||||||
list($full_path, $file_name) = $this->output_save_process($output_type, $loaded_data);
|
list($full_path, $file_name) = $this->output_save_process($output_type, $loaded_data);
|
||||||
$full_path .= DIRECTORY_SEPARATOR . $file_name;
|
$full_path .= DIRECTORY_SEPARATOR . $file_name;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!$uid) {
|
if (!$uid) {
|
||||||
|
|||||||
@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Controllers;
|
namespace App\Controllers;
|
||||||
|
|
||||||
use CodeIgniter\HTTP\RedirectResponse;
|
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
|
||||||
use CodeIgniter\Validation\Validation;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use CodeIgniter\Validation\Validation;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\RedirectResponse;
|
||||||
use App\Models\UserModel;
|
use App\Models\UserModel;
|
||||||
|
|
||||||
|
use App\Libraries\MyAuth\LocalAuth;
|
||||||
|
use App\Libraries\MyAuth\GoogleAuth;
|
||||||
|
|
||||||
class UserController extends FrontController
|
class UserController extends FrontController
|
||||||
{
|
{
|
||||||
private $_model = null;
|
private $_model = null;
|
||||||
@ -80,40 +82,41 @@ class UserController extends FrontController
|
|||||||
return $this->create_form_procedure();
|
return $this->create_form_procedure();
|
||||||
}
|
}
|
||||||
//로그인처리
|
//로그인처리
|
||||||
protected function create_process(): void
|
|
||||||
{
|
|
||||||
// $this->create_validate($this->action, $this->fields);
|
|
||||||
$this->formDatas = $this->getFormDatas();
|
|
||||||
if (!isset($this->formDatas['id']) || !$this->formDatas['id']) {
|
|
||||||
throw new \Exception("사용자ID를 입력해주세요!");
|
|
||||||
}
|
|
||||||
if (!isset($this->formDatas['passwd']) || !$this->formDatas['passwd']) {
|
|
||||||
throw new \Exception("암호를 입력해주세요!");
|
|
||||||
}
|
|
||||||
$entity = $this->getModel()->getEntityByID($this->formDatas['id']);
|
|
||||||
if (is_null($entity) || !isset($entity->passwd)) {
|
|
||||||
throw new \Exception("사용자ID: {$this->formDatas['id']}가 존재하지 않습니다.");
|
|
||||||
}
|
|
||||||
if (password_verify($this->formDatas['passwd'], $entity->passwd)) {
|
|
||||||
//Session에 Login 정보전달
|
|
||||||
$this->session->set([
|
|
||||||
SESSION_NAMES['AUTH'] => [
|
|
||||||
'uid' => $entity->getPK(),
|
|
||||||
'name' => $entity->getTitle(),
|
|
||||||
'email' => $entity->email,
|
|
||||||
'role' => $entity->role
|
|
||||||
],
|
|
||||||
SESSION_NAMES['ISLOGIN'] => true
|
|
||||||
]);
|
|
||||||
$this->message = "로그인 성공";
|
|
||||||
} else {
|
|
||||||
throw new \Exception("로그인 실패");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function create(): RedirectResponse|string
|
public function create(): RedirectResponse|string
|
||||||
{
|
{
|
||||||
$this->init(__FUNCTION__);
|
$this->init('login');
|
||||||
return $this->create_procedure();
|
//Transaction Start
|
||||||
|
$this->getModel()->transStart();
|
||||||
|
try {
|
||||||
|
$site = $this->request->getVar('site');
|
||||||
|
switch ($site) {
|
||||||
|
case 'local':
|
||||||
|
$this->create_validate($this->action, $this->fields);
|
||||||
|
$this->formDatas = $this->getFormDatas();
|
||||||
|
$auth = new LocalAuth();
|
||||||
|
$entity = $auth->checkUser($this->formDatas);
|
||||||
|
break;
|
||||||
|
case 'google':
|
||||||
|
$auth = new GoogleAuth();
|
||||||
|
$entity = $auth->checkUser();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \Exception("{$site}는 아직 지원하지 않는 사이트입니다.");
|
||||||
|
}
|
||||||
|
$auth->setLogin($entity);
|
||||||
|
$this->message = "로그인 성공";
|
||||||
|
$this->getModel()->transCommit();
|
||||||
|
log_message("notice", $this->message);
|
||||||
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $this->message);
|
||||||
|
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
//Transaction Rollback
|
||||||
|
$this->getModel()->transRollback();
|
||||||
|
log_message("error", $e->getMessage());
|
||||||
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], "로그인 실패하였습니다.\n" . $e->getMessage());
|
||||||
|
$this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
||||||
|
return redirect()->back()->withInput();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//로그아웃
|
//로그아웃
|
||||||
public function logout(): RedirectResponse
|
public function logout(): RedirectResponse
|
||||||
|
|||||||
@ -1,24 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
//로그인체크 한후 권한체크
|
|
||||||
function isRole_CommonHelper(array $userRoles, $categoryEntity, $roleField = 'isaccess')
|
|
||||||
{
|
|
||||||
return in_array($categoryEntity->getRole($roleField), $userRoles);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getValueByKey_CommonHelper($key, array $attributes)
|
|
||||||
{
|
|
||||||
$options = array();
|
|
||||||
$replace_attributes = array();
|
|
||||||
foreach ($attributes as $idx => $value) {
|
|
||||||
if ($idx == $key) {
|
|
||||||
$replace_attributes[$idx] = $value;
|
|
||||||
} else {
|
|
||||||
array_push($options, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array($replace_attributes, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRandomString_CommonHelper($length = 10, $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
function getRandomString_CommonHelper($length = 10, $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
{
|
{
|
||||||
return substr(str_shuffle($characters), 0, $length);
|
return substr(str_shuffle($characters), 0, $length);
|
||||||
@ -149,80 +129,6 @@ function alert_CommonHelper(string $msg, $url = null)
|
|||||||
return "<script type=\"text/javascript\">{$msg}</script>";
|
return "<script type=\"text/javascript\">{$msg}</script>";
|
||||||
} //
|
} //
|
||||||
|
|
||||||
// STATUS가 use가 아닐때 option을 disabled되게 하기위함 (override form_dropdown)
|
|
||||||
function form_dropdown_test($data = '', $options = [], $selected = [], $extra = ''): string
|
|
||||||
{
|
|
||||||
$defaults = [];
|
|
||||||
if (is_array($data)) {
|
|
||||||
if (isset($data['selected'])) {
|
|
||||||
$selected = $data['selected'];
|
|
||||||
unset($data['selected']); // select tags don't have a selected attribute
|
|
||||||
}
|
|
||||||
if (isset($data['options'])) {
|
|
||||||
$options = $data['options'];
|
|
||||||
unset($data['options']); // select tags don't use an options attribute
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$defaults = ['name' => $data];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_array($selected)) {
|
|
||||||
$selected = [$selected];
|
|
||||||
}
|
|
||||||
if (!is_array($options)) {
|
|
||||||
$options = [$options];
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no selected state was submitted we will attempt to set it automatically
|
|
||||||
if (empty($selected)) {
|
|
||||||
if (is_array($data)) {
|
|
||||||
if (isset($data['name'], $_POST[$data['name']])) {
|
|
||||||
$selected = [$_POST[$data['name']]];
|
|
||||||
}
|
|
||||||
} elseif (isset($_POST[$data])) {
|
|
||||||
$selected = [$_POST[$data]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Standardize selected as strings, like the option keys will be
|
|
||||||
foreach ($selected as $key => $item) {
|
|
||||||
$selected[$key] = (string) $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
$extra = stringify_attributes($extra);
|
|
||||||
$multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : '';
|
|
||||||
$form = '<select ' . rtrim(parse_form_attributes($data, $defaults)) . $extra . $multiple . ">\n";
|
|
||||||
|
|
||||||
foreach ($options as $key => $val) {
|
|
||||||
// Keys should always be strings for strict comparison
|
|
||||||
$key = (string) $key;
|
|
||||||
|
|
||||||
if (is_array($val)) {
|
|
||||||
if (empty($val)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$form .= '<optgroup label="' . $key . "\">\n";
|
|
||||||
|
|
||||||
foreach ($val as $optgroupKey => $optgroupVal) {
|
|
||||||
// Keys should always be strings for strict comparison
|
|
||||||
$optgroupKey = (string) $optgroupKey;
|
|
||||||
|
|
||||||
$sel = in_array($optgroupKey, $selected, true) ? ' selected="selected"' : '';
|
|
||||||
$form .= '<option value="' . $optgroupKey . '"' . $sel . '>' . $optgroupVal . "</option>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$form .= "</optgroup>\n";
|
|
||||||
} else {
|
|
||||||
$form .= '<option value="' . $key . '"'
|
|
||||||
. (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>'
|
|
||||||
. $val . "</option>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $form . "</select>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
function getListButtonLabel_CommonHelper(string $action, string $label, array $viewDatas, array $extras = []): string
|
function getListButtonLabel_CommonHelper(string $action, string $label, array $viewDatas, array $extras = []): string
|
||||||
{
|
{
|
||||||
switch ($viewDatas['action_form']) {
|
switch ($viewDatas['action_form']) {
|
||||||
|
|||||||
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Libraries\MyAuth;
|
namespace App\Libraries\MyAuth;
|
||||||
|
|
||||||
use App\Libraries\MySocket\Web\GoogleSocket;
|
use \Google\Service\Oauth2;
|
||||||
|
use App\Models\UserModel;
|
||||||
|
use App\Models\SNSUserModel;
|
||||||
|
use App\Libraries\MySocket\GoogleSocket;
|
||||||
use App\Entities\UserEntity;
|
use App\Entities\UserEntity;
|
||||||
use App\Entities\SNSUserEntity;
|
use App\Entities\SNSUserEntity;
|
||||||
|
|
||||||
@ -10,6 +13,7 @@ class GoogleAuth extends MyAuth
|
|||||||
{
|
{
|
||||||
private $_mySocket = null;
|
private $_mySocket = null;
|
||||||
private $_site = "GOOGLE";
|
private $_site = "GOOGLE";
|
||||||
|
private $_model = null;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -18,7 +22,8 @@ class GoogleAuth extends MyAuth
|
|||||||
public function getMySocket(): GoogleSocket
|
public function getMySocket(): GoogleSocket
|
||||||
{
|
{
|
||||||
if ($this->_mySocket === null) {
|
if ($this->_mySocket === null) {
|
||||||
$this->_mySocket = new GoogleSocket(getenv('yamap.host.url'));
|
$this->_mySocket = new GoogleSocket();
|
||||||
|
$this->_mySocket->setAccessToken();
|
||||||
}
|
}
|
||||||
return $this->_mySocket;
|
return $this->_mySocket;
|
||||||
}
|
}
|
||||||
@ -28,83 +33,87 @@ class GoogleAuth extends MyAuth
|
|||||||
$button = "";
|
$button = "";
|
||||||
if (!$this->getMySocket()->getAccessToken()) {
|
if (!$this->getMySocket()->getAccessToken()) {
|
||||||
$button = anchor(
|
$button = anchor(
|
||||||
$this->getMySocket()->getClient()->createAuthUrl(),
|
getenv("socket.google.api.url"),
|
||||||
ICONS['GOOGLE'],
|
ICONS['GOOGLE'],
|
||||||
["target" => "_self"]
|
["target" => "_self"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $button;
|
return $button;
|
||||||
}
|
}
|
||||||
public function execute(): UserEntity
|
|
||||||
|
final protected function getModel(): SNSUSerModel
|
||||||
{
|
{
|
||||||
return new UserEntity();
|
if ($this->_model === null) {
|
||||||
// try {
|
$this->_model = new SNSUserModel();
|
||||||
// //Google 접근 권한 설정.
|
}
|
||||||
// $this->getMySocket()->setAccessToken();
|
return $this->_model;
|
||||||
// //Google 서비스 설정
|
}
|
||||||
// //$service = new \Google\Service\Oauth2($this->getMySocket());
|
|
||||||
// $service = new \Google\Service\Oauth2($this->getMySocket());
|
// throw new \Exception(__METHOD__ . "에서 데이터 처리 필요");
|
||||||
// $result = $service->userinfo->get();
|
// DEBUG - 2023-07-13 12:54:51 --> \Google\Service\Oauth2\Userinfo::__set_state(array(
|
||||||
// log_message("debug", var_export($result, true));
|
// 'internal_gapi_mappings' =>
|
||||||
// // throw new \Exception(__METHOD__ . "에서 데이터 처리 필요");
|
// 'familyName' => 'family_name',
|
||||||
// // DEBUG - 2023-07-13 12:54:51 --> \Google\Service\Oauth2\Userinfo::__set_state(array(
|
// 'givenName' => 'given_name',
|
||||||
// // 'internal_gapi_mappings' =>
|
// 'verifiedEmail' => 'verified_email',
|
||||||
// // array (
|
// ),
|
||||||
// // 'familyName' => 'family_name',
|
// 'modelData' =>
|
||||||
// // 'givenName' => 'given_name',
|
// array (
|
||||||
// // 'verifiedEmail' => 'verified_email',
|
// 'verified_email' => true,
|
||||||
// // ),
|
// 'given_name' => '이름',
|
||||||
// // 'modelData' =>
|
// 'family_name' => '성',
|
||||||
// // array (
|
// ),
|
||||||
// // 'verified_email' => true,
|
// 'processed' =>
|
||||||
// // 'given_name' => '이름',
|
// array (
|
||||||
// // 'family_name' => '성',
|
// ),
|
||||||
// // ),
|
// 'email' => 'twsdfsew342s@gmail.com',
|
||||||
// // 'processed' =>
|
// 'familyName' => '성',
|
||||||
// // array (
|
// 'gender' => NULL,
|
||||||
// // ),
|
// 'givenName' => '이름',
|
||||||
// // 'email' => 'twsdfsew342s@gmail.com',
|
// 'hd' => NULL,
|
||||||
// // 'familyName' => '성',
|
// 'id' => '103667492432234234236838324',
|
||||||
// // 'gender' => NULL,
|
// 'link' => NULL,
|
||||||
// // 'givenName' => '이름',
|
// 'locale' => 'ko',
|
||||||
// // 'hd' => NULL,
|
// 'name' => '성이름',
|
||||||
// // 'id' => '103667492432234234236838324',
|
// 'picture' => 'https://lh3.googleusercontent.com/a/AAcHTteFSgefsdfsdRJBkJA2tBEmg4PQrvI1Ta_5IXu5=s96-c',
|
||||||
// // 'link' => NULL,
|
// 'verifiedEmail' => true,
|
||||||
// // 'locale' => 'ko',
|
// ))
|
||||||
// // 'name' => '성이름',
|
public function checkUser(): UserEntity
|
||||||
// // 'picture' => 'https://lh3.googleusercontent.com/a/AAcHTteFSgefsdfsdRJBkJA2tBEmg4PQrvI1Ta_5IXu5=s96-c',
|
{
|
||||||
// // 'verifiedEmail' => true,
|
try {
|
||||||
// // ))
|
//Google 서비스 설정
|
||||||
// //조건에 해당하는 이미 등록된 사용자가 있는지 검사
|
$service = new Oauth2($this->getMySocket());
|
||||||
// $snsEntity = null;
|
$authInfo = $service->userinfo->get();
|
||||||
// try {
|
log_message("debug", var_export($authInfo, true));
|
||||||
// $snsEntity = $this->getUserSNSModel()->asObject(SNSUSerEntity::class)->where(
|
//기존 등록된 사용자가 있는지 검사
|
||||||
// array("site" => $this->_site, "id" => $result['id'])
|
$this->getModel()->where(SNSUserModel::SITE, $this->_site);
|
||||||
// )->first();
|
$entity = $this->getModel()->getEntityByID($authInfo['id']);
|
||||||
// } catch (\Exception $e) {
|
if ($entity === null) {
|
||||||
// $snsEntity = new SNSUSerEntity([
|
//없다면 새로 등록
|
||||||
// 'site' => $this->_site,
|
$formDatas = [
|
||||||
// 'id' => $result['id'],
|
'site' => $this->_site,
|
||||||
// 'name' => $result['name'],
|
'id' => $authInfo['id'],
|
||||||
// 'email' => $result['email'],
|
'name' => $authInfo['name'],
|
||||||
// 'detail' => json_encode($result),
|
'email' => $authInfo['email'],
|
||||||
// 'status' => 'standby',
|
'detail' => json_encode($authInfo),
|
||||||
// ]);
|
'status' => 'standby',
|
||||||
// $snsEntity = $this->getUserSNSModel()->create($snsEntity);
|
];
|
||||||
// }
|
$entity = $this->getModel()->create($formDatas);
|
||||||
// //상태가 use(승인완료)가 아니라면
|
}
|
||||||
// if ($snsEntity->status !== DEFAULTS['STATUS']) {
|
//상태가 use(승인완료)가 아니라면
|
||||||
// throw new \Exception("{$this->_site}}의{$result['email']}:{$result['name']}님은 " . $snsEntity->status . "입니다");
|
if (
|
||||||
// }
|
$entity->status !== DEFAULTS['STATUS']
|
||||||
// //user_id가 연결되어있지 않았다면
|
) {
|
||||||
// if (!$snsEntity->getID()) {
|
throw new \Exception("{$this->_site}}의{$authInfo['email']}:{$authInfo['name']}님은 " . $entity->status . "입니다");
|
||||||
// throw new \Exception("{$this->_site}의{$result['email']}:{$result['name']}님은 아직 사용자 지정이 되지 않았습니다. ");
|
}
|
||||||
// }
|
//local db 사용와의 연결 확인
|
||||||
// //인증된 사용자 정보를 가져온후 로그인처리
|
$userModel = new UserModel();
|
||||||
// $entity = $this->getUserModel()->getEntityByID($snsEntity->getID());
|
$userEntity = $userModel->getEntityByID($entity->getID());
|
||||||
// return $this->setSession_process($entity);;
|
if ($userEntity === null) {
|
||||||
// } catch (\Exception $e) {
|
throw new \Exception("{$this->_site}의{$authInfo['email']}:{$authInfo['name']}님은 아직 사용자 연결이 이루어지지 않았습니다. ");
|
||||||
// throw new \Exception("관리자에게 문의하시기 바랍니다.<BR>{$e->getMessage()}");
|
}
|
||||||
// }
|
return $userEntity;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \Exception("관리자에게 문의하시기 바랍니다.<BR>{$e->getMessage()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,31 +3,44 @@
|
|||||||
namespace App\Libraries\MyAuth;
|
namespace App\Libraries\MyAuth;
|
||||||
|
|
||||||
use App\Entities\UserEntity;
|
use App\Entities\UserEntity;
|
||||||
|
use App\Models\UserModel;
|
||||||
|
|
||||||
class LocalAuth extends MyAuth
|
class LocalAuth extends MyAuth
|
||||||
{
|
{
|
||||||
|
private $_model = null;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAuthButton()
|
public function getAuthButton(): string
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(): UserEntity
|
final protected function getModel(): UserModel
|
||||||
{
|
{
|
||||||
return new UserEntity();
|
if ($this->_model === null) {
|
||||||
// $formDatas = $this->getFormDatas();
|
$this->_model = new UserModel();
|
||||||
// if (!isset($formDatas['id']) || !$formDatas['id'] || !isset($formDatas['passwd']) || !$formDatas['passwd']) {
|
}
|
||||||
// throw new \Exception("ID 나 암호의 값이 없습니다.");
|
return $this->_model;
|
||||||
// }
|
}
|
||||||
// $entity = $this->getUserModel()->getEntity(['id' => $formDatas['id'], 'status' => DEFAULTS['STATUS']]);
|
|
||||||
// if (!password_verify($formDatas['passwd'], $entity->passwd)) {
|
public function checkUser(array $formDatas): UserEntity
|
||||||
// throw new \Exception("암호가 맞지않습니다.");
|
{
|
||||||
// }
|
if (!isset($formDatas['id']) || !$formDatas['id']) {
|
||||||
// //Session에 인증정보 설정
|
throw new \Exception("사용자ID를 입력해주세요!");
|
||||||
// return $this->setSession_process($entity);;
|
}
|
||||||
|
if (!isset($formDatas['passwd']) || !$formDatas['passwd']) {
|
||||||
|
throw new \Exception("암호를 입력해주세요!");
|
||||||
|
}
|
||||||
|
$entity = $this->getModel()->getEntityByID($formDatas['id']);
|
||||||
|
if (is_null($entity) || !isset($entity->passwd)) {
|
||||||
|
throw new \Exception("사용자ID: {$formDatas['id']}가 존재하지 않습니다.");
|
||||||
|
}
|
||||||
|
if (!password_verify($formDatas['passwd'], $entity->passwd)) {
|
||||||
|
throw new \Exception("암호가 맞지 않습니다.");
|
||||||
|
}
|
||||||
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,39 +3,19 @@
|
|||||||
namespace App\Libraries\MyAuth;
|
namespace App\Libraries\MyAuth;
|
||||||
|
|
||||||
use App\Entities\UserEntity;
|
use App\Entities\UserEntity;
|
||||||
use App\Models\UserModel;
|
use App\Libraries\CommonLibrary;
|
||||||
use App\Models\SNSUserModel;
|
|
||||||
|
|
||||||
// 참고:https://github.com/SyntaxPhoenix/iloclient
|
// 참고:https://github.com/SyntaxPhoenix/iloclient
|
||||||
abstract class MyAuth
|
abstract class MyAuth extends CommonLibrary
|
||||||
{
|
{
|
||||||
private $_userModel = null;
|
private $_session = null;
|
||||||
private $_snsUserModel = null;
|
|
||||||
protected $_session = null;
|
|
||||||
protected function __construct()
|
protected function __construct()
|
||||||
{
|
{
|
||||||
$this->_session = \Config\Services::session();
|
$this->_session = \Config\Services::session();
|
||||||
}
|
}
|
||||||
abstract public function getAuthButton();
|
abstract public function getAuthButton();
|
||||||
abstract public function execute(): UserEntity;
|
|
||||||
|
|
||||||
final protected function getUserModel(): UserModel
|
final public function setLogin(UserEntity $entity): void
|
||||||
{
|
|
||||||
if (is_null($this->_userModel)) {
|
|
||||||
$this->_userModel = new UserModel();
|
|
||||||
}
|
|
||||||
return $this->_userModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
final protected function getUserSNSModel(): SNSUSerModel
|
|
||||||
{
|
|
||||||
if (is_null($this->_snsUserModel)) {
|
|
||||||
$this->_snsUserModel = new SNSUserModel();
|
|
||||||
}
|
|
||||||
return $this->_snsUserModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setSession_process(UserEntity $entity): UserEntity
|
|
||||||
{
|
{
|
||||||
$this->_session->set(SESSION_NAMES['ISLOGIN'], true);
|
$this->_session->set(SESSION_NAMES['ISLOGIN'], true);
|
||||||
$this->_session->set(SESSION_NAMES['AUTH'], [
|
$this->_session->set(SESSION_NAMES['AUTH'], [
|
||||||
@ -43,6 +23,5 @@ abstract class MyAuth
|
|||||||
'name' => $entity->getTitle(),
|
'name' => $entity->getTitle(),
|
||||||
'role' => $entity->role
|
'role' => $entity->role
|
||||||
]);
|
]);
|
||||||
return $entity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,12 @@ class SNSUserModel extends CommonModel
|
|||||||
const TABLE = "sns_users";
|
const TABLE = "sns_users";
|
||||||
const PK = "uid";
|
const PK = "uid";
|
||||||
const TITLE = "name";
|
const TITLE = "name";
|
||||||
|
const SITE = "site";
|
||||||
protected $table = self::TABLE;
|
protected $table = self::TABLE;
|
||||||
protected $primaryKey = self::PK;
|
protected $primaryKey = self::PK;
|
||||||
protected $returnType = SNSUSerEntity::class;
|
protected $returnType = SNSUSerEntity::class;
|
||||||
protected $allowedFields = [
|
protected $allowedFields = [
|
||||||
|
"site",
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"name",
|
||||||
"email",
|
"email",
|
||||||
@ -37,6 +39,9 @@ class SNSUserModel extends CommonModel
|
|||||||
case $this->getTitleField():
|
case $this->getTitleField():
|
||||||
$rule = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
break;
|
break;
|
||||||
|
case "site":
|
||||||
|
$rule = "required|trim|string";
|
||||||
|
break;
|
||||||
case "email":
|
case "email":
|
||||||
$rule = "if_exist|trim|valid_email";
|
$rule = "if_exist|trim|valid_email";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Traits;
|
|
||||||
|
|
||||||
use CodeIgniter\Session\Session;
|
|
||||||
|
|
||||||
trait AuthTrait
|
|
||||||
{
|
|
||||||
final protected function session_AuthTrait(): Session
|
|
||||||
{
|
|
||||||
$session = \Config\Services::session();
|
|
||||||
$session->set('currentRoles', [DEFAULTS["ROLE"]]);
|
|
||||||
if ($session->get(SESSION_NAMES['ISLOGIN'])) {
|
|
||||||
$session->set(SESSION_NAMES['ISLOGIN'], true);
|
|
||||||
$session->set(
|
|
||||||
'currentRoles',
|
|
||||||
explode(
|
|
||||||
DEFAULTS['DELIMITER_ROLE'],
|
|
||||||
$session->get(SESSION_NAMES['AUTH'])['role']
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $session;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -13,12 +13,12 @@
|
|||||||
<input type="password" class="form-control" id="userPassword" name="passwd" required>
|
<input type="password" class="form-control" id="userPassword" name="passwd" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<button type="submit" class="btn btn-primary">로그인</button>
|
<button type="submit" class="btn btn-primary" name="site" value="local">로그인</button>
|
||||||
<button type="button" class="btn btn-outline-primary">회원가입</button>
|
<button type="submit" class="btn btn-danger" name="site" value="google">
|
||||||
<button type="button" class="btn btn-primary">
|
|
||||||
<img src="https://www.google.com/favicon.ico" alt="Google" width="20" height="20" class="me-2">
|
<img src="https://www.google.com/favicon.ico" alt="Google" width="20" height="20" class="me-2">
|
||||||
Google 로그인
|
Google 로그인
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn btn-outline-primary">회원가입</button>
|
||||||
</div>
|
</div>
|
||||||
<?= form_close(); ?>
|
<?= form_close(); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user