31 lines
815 B
PHP
31 lines
815 B
PHP
<?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,
|
|
]);
|
|
}
|
|
}
|