66
77// use Illuminate\Contracts\Auth\MustVerifyEmail;
88use App \Enums \UserRole ;
9+ use Filament \Auth \MultiFactor \App \Contracts \HasAppAuthentication ;
10+ use Filament \Auth \MultiFactor \App \Contracts \HasAppAuthenticationRecovery ;
911use Filament \Models \Contracts \FilamentUser ;
1012use Filament \Panel ;
1113use Illuminate \Database \Eloquent \Factories \HasFactory ;
1214use Illuminate \Foundation \Auth \User as Authenticatable ;
1315use Illuminate \Notifications \Notifiable ;
1416
15- class User extends Authenticatable implements FilamentUser
17+ class User extends Authenticatable implements FilamentUser, HasAppAuthentication, HasAppAuthenticationRecovery
1618{
1719 /** @use HasFactory<\Database\Factories\UserFactory> */
1820 use HasFactory;
@@ -39,6 +41,8 @@ class User extends Authenticatable implements FilamentUser
3941 protected $ hidden = [
4042 'password ' ,
4143 'remember_token ' ,
44+ 'app_authentication_secret ' ,
45+ 'app_authentication_recovery_codes ' ,
4246 ];
4347
4448 /**
@@ -50,11 +54,47 @@ protected function casts(): array
5054 {
5155 return [
5256 'email_verified_at ' => 'datetime ' ,
57+ 'last_logged_in_at ' => 'datetime ' ,
5358 'password ' => 'hashed ' ,
5459 'role ' => UserRole::class,
60+ 'app_authentication_secret ' => 'encrypted ' ,
61+ 'app_authentication_recovery_codes ' => 'encrypted:array ' ,
5562 ];
5663 }
5764
65+ public function getAppAuthenticationSecret (): ?string
66+ {
67+ return $ this ->app_authentication_secret ;
68+ }
69+
70+ public function saveAppAuthenticationSecret (?string $ secret ): void
71+ {
72+ $ this ->app_authentication_secret = $ secret ;
73+ $ this ->save ();
74+ }
75+
76+ public function getAppAuthenticationHolderName (): string
77+ {
78+ return $ this ->email ;
79+ }
80+
81+ /**
82+ * @return ?array<string>
83+ */
84+ public function getAppAuthenticationRecoveryCodes (): ?array
85+ {
86+ return $ this ->app_authentication_recovery_codes ;
87+ }
88+
89+ /**
90+ * @param array<string> | null $codes
91+ */
92+ public function saveAppAuthenticationRecoveryCodes (?array $ codes ): void
93+ {
94+ $ this ->app_authentication_recovery_codes = $ codes ;
95+ $ this ->save ();
96+ }
97+
5898 public function isMaintainer (): bool
5999 {
60100 return in_array ($ this ->role , [UserRole::Maintainer, UserRole::Admin], true );
0 commit comments