Files
KanbanGit/app/Http/Controllers/Settings/SecurityController.php
T
Twyco adaf3d2b32
linter / quality (push) Successful in 1m25s
tests / ci (8.4) (push) Failing after 1m19s
fixes
2026-05-23 01:05:01 +02:00

84 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
use App\Http\Requests\Settings\PasswordUpdateRequest;
use App\Http\Requests\Settings\TwoFactorAuthenticationRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;
use Inertia\Inertia;
use Inertia\Response;
use Laravel\Fortify\Features;
class SecurityController extends Controller implements HasMiddleware
{
/**
* Get the middleware that should be assigned to the controller.
*/
public static function middleware(): array
{
return Features::canManageTwoFactorAuthentication()
&& Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
? [new Middleware('password.confirm', only: ['edit'])]
: [];
}
/**
* Show the user's security settings page.
*/
public function edit(TwoFactorAuthenticationRequest $request): Response
{
$user = $request->user();
$props = [
'canManageTwoFactor' => Features::canManageTwoFactorAuthentication(),
];
if (Features::canManageTwoFactorAuthentication()) {
$request->ensureStateIsValid();
$props['twoFactorEnabled'] = $user->hasEnabledTwoFactorAuthentication();
$props['requiresConfirmation'] = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm');
}
return Inertia::render('settings/Security', $props);
}
/**
* Show the dedicated forced password change page.
*/
public function editForcedPassword(Request $request): Response|RedirectResponse
{
if (! $request->user()->must_change_password_on_next_login) {
return to_route('dashboard');
}
return Inertia::render('auth/ForcePasswordChange', [
'status' => session('status'),
]);
}
/**
* Update the user's password.
*/
public function update(PasswordUpdateRequest $request): RedirectResponse
{
$user = $request->user();
$mustChangePassword = (bool) $user->must_change_password_on_next_login;
$user->update([
'must_change_password_on_next_login' => false,
'password' => $request->password,
]);
if ($mustChangePassword) {
return redirect()->intended(route('dashboard'));
}
return back();
}
}