Skip to content

Commit 3c3b702

Browse files
authored
check for blocked users and prevent them from logging in
1 parent 30fbd3d commit 3c3b702

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Controllers/OAuthController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class OAuthController extends BaseController implements ControllersInterface
2323
{
2424
private const ACCESS_DENIED = 'access_denied';
25+
private ?User $userExist;
2526

2627
public function redirectOAuth(string $oauthName): RedirectResponse
2728
{
@@ -89,10 +90,7 @@ public function callBack(): RedirectResponse
8990
$updateFields = $oauthClass->getColumnsName('syncingUserInfo', $userInfo);
9091

9192
$userid = $this->syncingUserInfo($find, $updateFields);
92-
}
93-
94-
// Create new user if credentials not exist or let users register themselves
95-
if ($this->checkExistenceUser($find) === false) {
93+
} else {
9694
// Check config setting first to see if it can register automatically or not
9795
if (config('ShieldOAuthConfig')->oauthConfigs[$oauthName]['allow_register'] === false) {
9896
return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.account_not_found', [$userInfo->email]));
@@ -112,6 +110,10 @@ public function callBack(): RedirectResponse
112110
$users->addToDefaultGroup($user);
113111
}
114112

113+
if ($this->userExist->isBanned()) {
114+
return redirect()->to(config('Auth')->logoutRedirect())->with('error', $this->userExist->getBanMessage() ?? lang('Auth.bannedUser'));
115+
}
116+
115117
auth()->loginById($userid);
116118
$this->recordLoginAttempt($oauthName, $userInfo->email);
117119

@@ -143,6 +145,8 @@ private function checkExistenceUser(array $find = []): bool
143145
// $find = ['email' => $this->userInfo()->email];
144146
$findUser = $users->findByCredentials($find);
145147

148+
$this->userExist = $findUser;
149+
146150
return $findUser !== null;
147151
}
148152

0 commit comments

Comments
 (0)