mirror of
https://github.com/coollabsio/coolify.git
synced 2026-10-07 06:26:10 -04:00
Add audit levels and record user, OAuth, DNS, notification, and settings changes while removing the obsolete scheduled job monitoring UI and services.
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Fortify;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\Rule;
|
|
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
|
|
|
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
|
{
|
|
/**
|
|
* Validate and update the given user's profile information.
|
|
*
|
|
* @param array<string, string> $input
|
|
*/
|
|
public function update(User $user, array $input): void
|
|
{
|
|
$changedFields = collect(['name', 'email'])
|
|
->filter(fn (string $field): bool => $user->{$field} !== $input[$field])
|
|
->values()
|
|
->all();
|
|
Validator::make($input, [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
|
|
'email' => [
|
|
'required',
|
|
'string',
|
|
'email',
|
|
'max:255',
|
|
Rule::unique('users')->ignore($user->id),
|
|
],
|
|
])->validateWithBag('updateProfileInformation');
|
|
|
|
if (
|
|
$input['email'] !== $user->email &&
|
|
$user instanceof MustVerifyEmail
|
|
) {
|
|
$this->updateVerifiedUser($user, $input);
|
|
} else {
|
|
$user->fill([
|
|
'name' => $input['name'],
|
|
'email' => $input['email'],
|
|
])->save();
|
|
}
|
|
|
|
if ($changedFields !== []) {
|
|
auditLog('ui.user.profile_updated', [
|
|
'team_id' => $user->currentTeam()?->id,
|
|
'resource' => 'user',
|
|
'user_name' => $user->name,
|
|
'changed_fields' => $changedFields,
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the given verified user's profile information.
|
|
*
|
|
* @param array<string, string> $input
|
|
*/
|
|
protected function updateVerifiedUser(User $user, array $input): void
|
|
{
|
|
$user->fill([
|
|
'name' => $input['name'],
|
|
'email' => $input['email'],
|
|
'email_verified_at' => null,
|
|
])->save();
|
|
|
|
$user->sendEmailVerificationNotification();
|
|
}
|
|
}
|