feat(profile): align settings with dashboard layout
This commit is contained in:
@@ -2,26 +2,50 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\Profile\UpdateProfileRequest;
|
||||
use App\Models\User;
|
||||
use App\Services\Auth\TwoFactorEnrollmentState;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Auth\SecurityEventRecorder;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the authenticated user's profile and security settings.
|
||||
* Display the authenticated user's profile settings.
|
||||
*/
|
||||
public function __invoke(
|
||||
Request $request,
|
||||
TwoFactorEnrollmentState $enrollmentState
|
||||
): Response {
|
||||
public function show(): Response
|
||||
{
|
||||
return Inertia::render('Profile/Show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the authenticated user's profile settings.
|
||||
*/
|
||||
public function update(
|
||||
UpdateProfileRequest $request,
|
||||
SecurityEventRecorder $securityEvents
|
||||
): RedirectResponse {
|
||||
/** @var User $user */
|
||||
$user = $request->user();
|
||||
$emailChanged = $user->email !== $request->validated('email');
|
||||
|
||||
return Inertia::render('Profile/Show', [
|
||||
'twoFactor' => $enrollmentState->for($user),
|
||||
$user->fill($request->validated());
|
||||
|
||||
if ($emailChanged) {
|
||||
$user->email_verified_at = null;
|
||||
}
|
||||
|
||||
$user->save();
|
||||
$securityEvents->record('profile.updated', $user, $request, [
|
||||
'email_changed' => $emailChanged,
|
||||
]);
|
||||
|
||||
if ($emailChanged) {
|
||||
$user->sendEmailVerificationNotification();
|
||||
}
|
||||
|
||||
return redirect()->route('profile.show')
|
||||
->with('success', 'Your profile has been updated.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user