Added column to user table for email auth

This commit is contained in:
Anna-Sara Sélea 2025-11-26 20:42:27 +01:00
parent b74def256c
commit 19c995ad66
3 changed files with 53 additions and 3 deletions

View file

@ -7,9 +7,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Filament\Auth\MultiFactor\Email\Contracts\HasEmailAuthentication;
use Filament\Panel;
class User extends Authenticatable implements FilamentUser
class User extends Authenticatable implements FilamentUser, HasEmailAuthentication, MustVerifyEmail
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
@ -23,6 +25,7 @@ class User extends Authenticatable implements FilamentUser
'name',
'email',
'password',
'has_email_authentication'
];
/**
@ -45,6 +48,7 @@ class User extends Authenticatable implements FilamentUser
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'has_email_authentication' => 'boolean',
];
}
@ -52,4 +56,19 @@ class User extends Authenticatable implements FilamentUser
{
return true;
}
public function hasEmailAuthentication(): bool
{
// This method should return true if the user has enabled email authentication.
return $this->has_email_authentication;
}
public function toggleEmailAuthentication(bool $condition): void
{
// This method should save whether or not the user has enabled email authentication.
$this->has_email_authentication = $condition;
$this->save();
}
}

View file

@ -18,6 +18,7 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Filament\Auth\MultiFactor\Email\EmailAuthentication;
class AdminPanelProvider extends PanelProvider
{
@ -28,11 +29,13 @@ class AdminPanelProvider extends PanelProvider
->id('admin')
->path('')
->login()
->registration()
->profile()
->multiFactorAuthentication([
EmailAuthentication::make(),
])
->passwordReset()
->emailVerification()
->emailChangeVerification()
->profile()
->databaseNotifications()
->colors([
'primary' => Color::Amber,

View file

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('has_email_authentication')->default(false);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('has_email_authentication');
});
}
};