mirror of
https://github.com/pelican-dev/panel.git
synced 2026-05-04 18:00:48 +03:00
Add user to shouldLink and shouldCreate oauth functions (#2083)
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Extensions\OAuth;
|
||||
|
||||
use App\Models\User;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Wizard\Step;
|
||||
use Laravel\Socialite\Contracts\User as OAuthUser;
|
||||
|
||||
interface OAuthSchemaInterface
|
||||
{
|
||||
@@ -33,7 +35,7 @@ interface OAuthSchemaInterface
|
||||
|
||||
public function isEnabled(): bool;
|
||||
|
||||
public function shouldCreateMissingUsers(): bool;
|
||||
public function shouldCreateMissingUser(OAuthUser $user): bool;
|
||||
|
||||
public function shouldLinkMissingUsers(): bool;
|
||||
public function shouldLinkMissingUser(User $user, OAuthUser $oauthUser): bool;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace App\Extensions\OAuth\Schemas;
|
||||
|
||||
use App\Extensions\OAuth\OAuthSchemaInterface;
|
||||
use App\Models\User;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Schemas\Components\Wizard\Step;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Socialite\Contracts\User as OAuthUser;
|
||||
|
||||
abstract class OAuthSchema implements OAuthSchemaInterface
|
||||
{
|
||||
@@ -121,14 +123,14 @@ abstract class OAuthSchema implements OAuthSchemaInterface
|
||||
return env("OAUTH_{$id}_ENABLED", false);
|
||||
}
|
||||
|
||||
public function shouldCreateMissingUsers(): bool
|
||||
public function shouldCreateMissingUser(OAuthUser $user): bool
|
||||
{
|
||||
$id = Str::upper($this->getId());
|
||||
|
||||
return env("OAUTH_{$id}_SHOULD_CREATE_MISSING_USERS", false);
|
||||
}
|
||||
|
||||
public function shouldLinkMissingUsers(): bool
|
||||
public function shouldLinkMissingUser(User $user, OAuthUser $oauthUser): bool
|
||||
{
|
||||
$id = Str::upper($this->getId());
|
||||
|
||||
|
||||
@@ -79,13 +79,13 @@ class OAuthController extends Controller
|
||||
|
||||
$user = User::whereEmail($email)->first();
|
||||
if ($user) {
|
||||
if (!$driver->shouldLinkMissingUsers()) {
|
||||
if (!$driver->shouldLinkMissingUser($user, $oauthUser)) {
|
||||
return $this->errorRedirect();
|
||||
}
|
||||
|
||||
$user = $this->oauthService->linkUser($user, $driver, $oauthUser);
|
||||
} else {
|
||||
if (!$driver->shouldCreateMissingUsers()) {
|
||||
if (!$driver->shouldCreateMissingUser($oauthUser)) {
|
||||
return $this->errorRedirect();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user