diff --git a/app/Filament/Pages/Auth/Login.php b/app/Filament/Pages/Auth/Login.php index a4f157a37..d1bf4b007 100644 --- a/app/Filament/Pages/Auth/Login.php +++ b/app/Filament/Pages/Auth/Login.php @@ -3,7 +3,10 @@ namespace App\Filament\Pages\Auth; use Coderflex\FilamentTurnstile\Forms\Components\Turnstile; +use Filament\Forms\Components\Component; +use Filament\Forms\Components\TextInput; use Filament\Pages\Auth\Login as BaseLogin; +use Illuminate\Validation\ValidationException; class Login extends BaseLogin { @@ -13,7 +16,7 @@ class Login extends BaseLogin 'form' => $this->form( $this->makeForm() ->schema([ - $this->getEmailFormComponent(), + $this->getLoginFormComponent(), $this->getPasswordFormComponent(), $this->getRememberFormComponent(), Turnstile::make('captcha') @@ -31,6 +34,28 @@ class Login extends BaseLogin { $this->dispatch('reset-captcha'); - parent::throwFailureValidationException(); + throw ValidationException::withMessages([ + 'data.login' => __('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 getCredentialsFromFormData(array $data): array + { + $loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; + + return [ + $loginType => mb_strtolower($data['login']), + 'password' => $data['password'], + ]; } } diff --git a/app/Models/User.php b/app/Models/User.php index 733b51d84..adb2caeb6 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -252,6 +252,14 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac $this->attributes['username'] = mb_strtolower($value); } + /** + * Store the email as a lowercase string. + */ + public function setEmailAttribute(string $value): void + { + $this->attributes['email'] = mb_strtolower($value); + } + /** * Return a concatenated result for the accounts full name. */ diff --git a/tests/Integration/Api/Client/AccountControllerTest.php b/tests/Integration/Api/Client/AccountControllerTest.php index ccca6818d..d62fc5faf 100644 --- a/tests/Integration/Api/Client/AccountControllerTest.php +++ b/tests/Integration/Api/Client/AccountControllerTest.php @@ -47,7 +47,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase $user = User::factory()->create(); $response = $this->actingAs($user)->putJson('/api/client/account/email', [ - 'email' => $email = Str::random() . '@example.com', + 'email' => $email = mb_strtolower(Str::random() . '@example.com'), 'password' => 'password', ]);