Allow username on filament login page + make case insensitive (#714)
* allow login with username * make login case insensitive * fix tests
This commit is contained in:
parent
24eb52f7d6
commit
408897cfcf
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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',
|
||||
]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user