Skip to content

Commit

Permalink
ability to reset 2fa for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Jul 22, 2024
1 parent 71b404c commit a7dc029
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions app/Filament/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@
namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Pages\Actions\DeleteAction;
use App\Models\User;
use Filament\Actions\Action;
use Filament\Resources\Pages\EditRecord;

/**
* @property User $record
*/
class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;

protected function getHeaderActions(): array
{

return [
DeleteAction::make(),
// Reset 2FA
Action::make('Reset 2FA')
->label('Reset 2FA')
->requiresConfirmation()
->color('danger')
->visible(fn(User $record) => $record->twoFactors()->exists())
->action(function () {
$this->record->resetTwoFactorAuth();
}),
];
}
}
8 changes: 7 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -132,11 +133,16 @@ public function groups()
);
}

public function twoFactors(): \Illuminate\Database\Eloquent\Relations\HasOne
public function twoFactors(): HasOne
{
return $this->hasOne(TwoFactor::class);
}

public function resetTwoFactorAuth()
{
$this->twoFactors()->delete();
}

public function appCan(string $scope)
{
$auth = Auth::guard('api');
Expand Down

0 comments on commit a7dc029

Please sign in to comment.