From 8f25ed34cb0433bc825c728fec38b403f5c6c89f Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 10 Sep 2024 10:27:48 +0700 Subject: [PATCH 1/6] feat: apply config setting --- src/Controllers/OAuthController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index 1c81fbf..2543f54 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -32,7 +32,7 @@ public function redirectOAuth(string $oauthName): RedirectResponse return redirect()->to(config('Auth')->loginRedirect()); } - if (config('ShieldOAuthConfig')->oauthConfigs[$oauthName]['allow_login'] === false) { + if (setting('ShieldOAuthConfig.oauthConfigs')[$oauthName]['allow_login'] === false) { $errorText = 'ShieldOAuthLang.' . ucfirst($oauthName) . '.not_allow'; return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang($errorText)); @@ -93,7 +93,7 @@ public function callBack(): RedirectResponse $userid = $this->syncingUserInfo($find, $updateFields); } else { // Check config setting first to see if it can register automatically or not - if (config('ShieldOAuthConfig')->oauthConfigs[$oauthName]['allow_register'] === false) { + if (setting('ShieldOAuthConfig.oauthConfigs')[$oauthName]['allow_register'] === false) { return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.account_not_found', [$userInfo->email])); } @@ -164,10 +164,10 @@ private function syncingUserInfo(array $find = [], array $updateFields = []): in $users = model('ShieldOAuthModel'); $user = $users->findByCredentials($find); - $syncingUserInfo = config('ShieldOAuthConfig')->syncingUserInfo; - if ($syncingUserInfo === true) { + if (setting('ShieldOAuthConfig.syncingUserInfo') === true) { $user->fill($updateFields); } + $users->save($user); return $user->id; From 0fc00571d4c8d9b98c5af2f42f789013cec9f7be Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 10 Sep 2024 10:32:45 +0700 Subject: [PATCH 2/6] require codeigniter4/settings --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 41af56b..f51197f 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "require": { "php": "^7.4.3 || ^8.0 || ^8.1 || ^8.2", "ext-curl": "*", - "codeigniter4/shield": "^1.0" + "codeigniter4/shield": "^1.0", + "codeigniter4/settings": "^2.2" }, "require-dev": { "codeigniter4/devkit": "^1.0", From f058fd77f10ea2f1b231e1613919ada4fb8f246c Mon Sep 17 00:00:00 2001 From: warcooft Date: Tue, 10 Sep 2024 12:12:24 +0700 Subject: [PATCH 3/6] remove unnecessary code --- src/Controllers/OAuthController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index 2543f54..da3aa49 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -143,7 +143,7 @@ private function checkAntiForgery(string $state): bool private function checkExistenceUser(array $find = []): bool { $users = model('ShieldOAuthModel'); - // $find = ['email' => $this->userInfo()->email]; + $findUser = $users->findByCredentials($find); $this->userExist = $findUser; From ff6571dca102306dc2589e7d134d4fe186439bb4 Mon Sep 17 00:00:00 2001 From: warcooft Date: Tue, 10 Sep 2024 12:20:10 +0700 Subject: [PATCH 4/6] fix: add phpstan-ignore for setting func --- src/Controllers/OAuthController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index da3aa49..6fa4c55 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -32,6 +32,7 @@ public function redirectOAuth(string $oauthName): RedirectResponse return redirect()->to(config('Auth')->loginRedirect()); } + /** @phpstan-ignore-next-line */ if (setting('ShieldOAuthConfig.oauthConfigs')[$oauthName]['allow_login'] === false) { $errorText = 'ShieldOAuthLang.' . ucfirst($oauthName) . '.not_allow'; @@ -93,6 +94,7 @@ public function callBack(): RedirectResponse $userid = $this->syncingUserInfo($find, $updateFields); } else { // Check config setting first to see if it can register automatically or not + /** @phpstan-ignore-next-line */ if (setting('ShieldOAuthConfig.oauthConfigs')[$oauthName]['allow_register'] === false) { return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.account_not_found', [$userInfo->email])); } @@ -164,6 +166,7 @@ private function syncingUserInfo(array $find = [], array $updateFields = []): in $users = model('ShieldOAuthModel'); $user = $users->findByCredentials($find); + /** @phpstan-ignore-next-line */ if (setting('ShieldOAuthConfig.syncingUserInfo') === true) { $user->fill($updateFields); } From a29f15fc0e648ba3a69434e3d5a4c8dc817f2990 Mon Sep 17 00:00:00 2001 From: warcooft Date: Wed, 11 Sep 2024 12:49:09 +0700 Subject: [PATCH 5/6] fix: func not found, rm require package --- composer.json | 137 ++++++++++++++-------------- phpstan.neon.dist | 1 + src/Controllers/OAuthController.php | 3 - 3 files changed, 69 insertions(+), 72 deletions(-) diff --git a/composer.json b/composer.json index f51197f..969ed92 100644 --- a/composer.json +++ b/composer.json @@ -1,74 +1,73 @@ { - "name": "datamweb/shield-oauth", - "description": "OAuth for CodeIgniter Shield", - "license": "MIT", - "type": "library", - "keywords": [ - "codeigniter4", - "shield", - "oauth", - "googleOauth", - "githubOauth", - "authentication", - "authorization" + "name": "datamweb/shield-oauth", + "description": "OAuth for CodeIgniter Shield", + "license": "MIT", + "type": "library", + "keywords": [ + "codeigniter4", + "shield", + "oauth", + "googleOauth", + "githubOauth", + "authentication", + "authorization" + ], + "authors": [ + { + "name": "Pooya Parsa Dadashi", + "email": "pooya_parsa_dadashi@yahoo.com", + "role": "Developer" + } + ], + "homepage": "https://github.com/datamweb/shield-oauth", + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": "^7.4.3 || ^8.0 || ^8.1 || ^8.2", + "ext-curl": "*", + "codeigniter4/shield": "^1.0" + }, + "require-dev": { + "codeigniter4/devkit": "^1.0", + "codeigniter4/framework": "^4.3.5", + "codeigniter4/shield": "^1.0", + "rector/rector": "1.2.5" + }, + "autoload": { + "psr-4": { + "Datamweb\\ShieldOAuth\\": "src" + }, + "exclude-from-classmap": [ + "**/Database/Migrations/**" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests", + "Tests\\Support\\": "tests/_support" + } + }, + "scripts": { + "post-update-cmd": [ + "bash admin/setup.sh" ], - "authors": [ - { - "name": "Pooya Parsa Dadashi", - "email": "pooya_parsa_dadashi@yahoo.com", - "role": "Developer" - } + "ci": [ + "Composer\\Config::disableProcessTimeout", + "@cs" ], - "homepage": "https://github.com/datamweb/shield-oauth", - "minimum-stability": "dev", - "prefer-stable": true, - "require": { - "php": "^7.4.3 || ^8.0 || ^8.1 || ^8.2", - "ext-curl": "*", - "codeigniter4/shield": "^1.0", - "codeigniter4/settings": "^2.2" - }, - "require-dev": { - "codeigniter4/devkit": "^1.0", - "codeigniter4/framework": "^4.3.5", - "codeigniter4/shield": "^1.0", - "rector/rector": "1.2.5" - }, - "autoload": { - "psr-4": { - "Datamweb\\ShieldOAuth\\": "src" - }, - "exclude-from-classmap": [ - "**/Database/Migrations/**" - ] - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests", - "Tests\\Support\\": "tests/_support" - } - }, - "scripts": { - "post-update-cmd": [ - "bash admin/setup.sh" - ], - "ci": [ - "Composer\\Config::disableProcessTimeout", - "@cs" - ], - "cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff", - "cs-fix": "php-cs-fixer fix --ansi --verbose --diff", - "style": "@cs-fix" - }, - "config": { - "allow-plugins": { - "phpstan/extension-installer": true - } - }, - "support": { - "forum": "https://github.com/datamweb/shield-oauth/discussions", - "source": "https://github.com/datamweb/shield-oauth", - "issues": "https://github.com/datamweb/shield-oauth/issues", - "docs": "https://www.shield-oauth.codeigniter4.ir" + "cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff", + "cs-fix": "php-cs-fixer fix --ansi --verbose --diff", + "style": "@cs-fix" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true } + }, + "support": { + "forum": "https://github.com/datamweb/shield-oauth/discussions", + "source": "https://github.com/datamweb/shield-oauth", + "issues": "https://github.com/datamweb/shield-oauth/issues", + "docs": "https://www.shield-oauth.codeigniter4.ir" + } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 020914f..62a60a6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -16,6 +16,7 @@ parameters: - Faker\Generator scanDirectories: - vendor/codeigniter4/framework/system/Helpers + - vendor/codeigniter4/settings/src/Helpers dynamicConstantNames: - APP_NAMESPACE - CI_DEBUG diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index 6fa4c55..da3aa49 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -32,7 +32,6 @@ public function redirectOAuth(string $oauthName): RedirectResponse return redirect()->to(config('Auth')->loginRedirect()); } - /** @phpstan-ignore-next-line */ if (setting('ShieldOAuthConfig.oauthConfigs')[$oauthName]['allow_login'] === false) { $errorText = 'ShieldOAuthLang.' . ucfirst($oauthName) . '.not_allow'; @@ -94,7 +93,6 @@ public function callBack(): RedirectResponse $userid = $this->syncingUserInfo($find, $updateFields); } else { // Check config setting first to see if it can register automatically or not - /** @phpstan-ignore-next-line */ if (setting('ShieldOAuthConfig.oauthConfigs')[$oauthName]['allow_register'] === false) { return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.account_not_found', [$userInfo->email])); } @@ -166,7 +164,6 @@ private function syncingUserInfo(array $find = [], array $updateFields = []): in $users = model('ShieldOAuthModel'); $user = $users->findByCredentials($find); - /** @phpstan-ignore-next-line */ if (setting('ShieldOAuthConfig.syncingUserInfo') === true) { $user->fill($updateFields); } From 2af01d0e74e4a96594e047dc477c1e8cb5641542 Mon Sep 17 00:00:00 2001 From: warcooft Date: Wed, 11 Sep 2024 12:56:08 +0700 Subject: [PATCH 6/6] fix: invalid combination --- phpstan.neon.dist | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 62a60a6..23c625e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,23 +1,23 @@ includes: - - phpstan-baseline.php + - phpstan-baseline.php parameters: - tmpDir: build/phpstan - level: 6 - paths: - - src/ - bootstrapFiles: - - vendor/codeigniter4/framework/system/Test/bootstrap.php - excludePaths: - - app/Views/* - ignoreErrors: - universalObjectCratesClasses: - - CodeIgniter\Entity - - CodeIgniter\Entity\Entity - - Faker\Generator - scanDirectories: - - vendor/codeigniter4/framework/system/Helpers - - vendor/codeigniter4/settings/src/Helpers - dynamicConstantNames: - - APP_NAMESPACE - - CI_DEBUG - - ENVIRONMENT + tmpDir: build/phpstan + level: 6 + paths: + - src/ + bootstrapFiles: + - vendor/codeigniter4/framework/system/Test/bootstrap.php + excludePaths: + - app/Views/* + ignoreErrors: + universalObjectCratesClasses: + - CodeIgniter\Entity + - CodeIgniter\Entity\Entity + - Faker\Generator + scanDirectories: + - vendor/codeigniter4/framework/system/Helpers + - vendor/codeigniter4/settings/src/Helpers + dynamicConstantNames: + - APP_NAMESPACE + - CI_DEBUG + - ENVIRONMENT