mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 02:54:45 +02:00

* Fix copy paste AllocationsRelationManager * We shouldn't let the user know if the user is correct but the password isn't * Add missing `trans()` `EditServer` * Add missing `trans()` User `ServersRelationManager` * Replace every `__()` with `trans()` helper * Fix `exceptions` `User` Model * Replace `Translator->get()` with `trans()` helper * Revert "We shouldn't let the user know if the user is correct but the password isn't" This reverts commit e156ee4b38e9e969662a532648c78fdc1e9b0166. that's stock laravel, therefore it needs to stay
87 lines
2.7 KiB
PHP
87 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Auth;
|
|
|
|
use App\Extensions\OAuth\Providers\OAuthProvider;
|
|
use Coderflex\FilamentTurnstile\Forms\Components\Turnstile;
|
|
use Filament\Forms\Components\Actions;
|
|
use Filament\Forms\Components\Actions\Action;
|
|
use Filament\Forms\Components\Component;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Pages\Auth\Login as BaseLogin;
|
|
use Filament\Support\Colors\Color;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class Login extends BaseLogin
|
|
{
|
|
protected function getForms(): array
|
|
{
|
|
return [
|
|
'form' => $this->form(
|
|
$this->makeForm()
|
|
->schema([
|
|
$this->getLoginFormComponent(),
|
|
$this->getPasswordFormComponent(),
|
|
$this->getRememberFormComponent(),
|
|
$this->getOAuthFormComponent(),
|
|
Turnstile::make('captcha')
|
|
->hidden(!config('turnstile.turnstile_enabled'))
|
|
->validationMessages([
|
|
'required' => config('turnstile.error_messages.turnstile_check_message'),
|
|
]),
|
|
])
|
|
->statePath('data'),
|
|
),
|
|
];
|
|
}
|
|
|
|
protected function throwFailureValidationException(): never
|
|
{
|
|
$this->dispatch('reset-captcha');
|
|
|
|
throw ValidationException::withMessages([
|
|
'data.login' => trans('filament-panels::pages/auth/login.messages.failed'),
|
|
]);
|
|
}
|
|
|
|
protected function getLoginFormComponent(): Component
|
|
{
|
|
return TextInput::make('login')
|
|
->label('Login')
|
|
->required()
|
|
->autocomplete()
|
|
->autofocus()
|
|
->extraInputAttributes(['tabindex' => 1]);
|
|
}
|
|
|
|
protected function getOAuthFormComponent(): Component
|
|
{
|
|
$actions = [];
|
|
|
|
$oauthProviders = collect(OAuthProvider::get())->filter(fn (OAuthProvider $provider) => $provider->isEnabled())->all();
|
|
|
|
foreach ($oauthProviders as $oauthProvider) {
|
|
|
|
$id = $oauthProvider->getId();
|
|
|
|
$actions[] = Action::make("oauth_$id")
|
|
->label($oauthProvider->getName())
|
|
->icon($oauthProvider->getIcon())
|
|
->color(Color::hex($oauthProvider->getHexColor()))
|
|
->url(route('auth.oauth.redirect', ['driver' => $id], false));
|
|
}
|
|
|
|
return Actions::make($actions);
|
|
}
|
|
|
|
protected function getCredentialsFromFormData(array $data): array
|
|
{
|
|
$loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
|
|
|
|
return [
|
|
$loginType => mb_strtolower($data['login']),
|
|
'password' => $data['password'],
|
|
];
|
|
}
|
|
}
|