Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class OAuthController extends BaseController implements ControllersInterface
{
private const ACCESS_DENIED = 'access_denied';

private ?User $userExist = null;

public function redirectOAuth(string $oauthName): RedirectResponse
{
// if user login
Expand Down Expand Up @@ -89,10 +91,7 @@ public function callBack(): RedirectResponse
$updateFields = $oauthClass->getColumnsName('syncingUserInfo', $userInfo);

$userid = $this->syncingUserInfo($find, $updateFields);
}

// Create new user if credentials not exist or let users register themselves
if ($this->checkExistenceUser($find) === false) {
} else {
// Check config setting first to see if it can register automatically or not
if (config('ShieldOAuthConfig')->oauthConfigs[$oauthName]['allow_register'] === false) {
return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.account_not_found', [$userInfo->email]));
Expand All @@ -112,6 +111,10 @@ public function callBack(): RedirectResponse
$users->addToDefaultGroup($user);
}

if ($this->userExist->isBanned()) {
return redirect()->to(config('Auth')->logoutRedirect())->with('error', $this->userExist->getBanMessage() ?? lang('Auth.bannedUser'));
}

auth()->loginById($userid);
$this->recordLoginAttempt($oauthName, $userInfo->email);

Expand Down Expand Up @@ -143,6 +146,8 @@ private function checkExistenceUser(array $find = []): bool
// $find = ['email' => $this->userInfo()->email];
$findUser = $users->findByCredentials($find);

$this->userExist = $findUser;

return $findUser !== null;
}

Expand Down