You've already forked Atomcms-edit
57 lines
1.5 KiB
PHP
Executable File
57 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
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
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $input
|
|
*/
|
|
public function update(User $user, array $input): void
|
|
{
|
|
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->mail &&
|
|
$user instanceof MustVerifyEmail) {
|
|
$this->updateVerifiedUser($user, $input);
|
|
} else {
|
|
$user->forceFill([
|
|
'name' => $input['name'],
|
|
'mail' => $input['email'],
|
|
])->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $input
|
|
*/
|
|
protected function updateVerifiedUser(User $user, array $input): void
|
|
{
|
|
$user->forceFill([
|
|
'name' => $input['name'],
|
|
'mail' => $input['email'],
|
|
'email_verified_at' => null,
|
|
])->save();
|
|
|
|
$user->sendEmailVerificationNotification();
|
|
}
|
|
}
|