first
This commit is contained in:
30
app/Actions/ChangeUserEmailAction.php
Normal file
30
app/Actions/ChangeUserEmailAction.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\AuditLogService;
|
||||
|
||||
class ChangeUserEmailAction
|
||||
{
|
||||
public function __construct(private readonly AuditLogService $audit) {}
|
||||
|
||||
public function execute(User $user, string $newEmail, ?string $justification = null): void
|
||||
{
|
||||
$oldEmail = $user->email;
|
||||
|
||||
$user->update([
|
||||
'email' => $newEmail,
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$this->audit->log('user_email_changed', [
|
||||
'subject_type' => User::class,
|
||||
'subject_id' => $user->id,
|
||||
'target_user_id' => $user->id,
|
||||
'old_values' => ['email' => $oldEmail],
|
||||
'new_values' => ['email' => $newEmail],
|
||||
'justification' => $justification,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user