Files
scrum-poker-internal/app/Http/Controllers/Settings/SecurityController.php
T
2026-08-20 23:00:47 +02:00

67 lines
2.0 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 App\Http\Resources\PasskeyResource;
use App\Models\User;
use App\Services\Settings\SecuritySettingsService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\Rules\Password;
use Inertia\Inertia;
use Inertia\Response;
use Laravel\Fortify\Features;
class SecurityController extends Controller
{
public function __construct(
private readonly SecuritySettingsService $securitySettings,
) {}
/**
* Show the user's security settings page.
*/
public function edit(TwoFactorAuthenticationRequest $request): Response
{
$user = $request->user();
abort_unless($user instanceof User, 403);
$canManageTwoFactor = Features::canManageTwoFactorAuthentication();
$canManagePasskeys = Features::canManagePasskeys();
$props = [
'canManageTwoFactor' => $canManageTwoFactor,
'canManagePasskeys' => $canManagePasskeys,
'passkeys' => PasskeyResource::collection(
$this->securitySettings->passkeys($user, $canManagePasskeys),
)->resolve($request),
'passwordRules' => Password::defaults()->toPasswordRulesString(),
];
if ($canManageTwoFactor) {
$request->ensureStateIsValid();
$props['twoFactorEnabled'] = $user->hasEnabledTwoFactorAuthentication();
$props['requiresConfirmation'] = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm');
}
return Inertia::render('settings/Security', $props);
}
/**
* Update the user's password.
*/
public function update(PasswordUpdateRequest $request): RedirectResponse
{
$request->user()->update([
'password' => $request->password,
]);
Inertia::flash('toast', ['type' => 'success', 'message' => __('Password updated.')]);
return back();
}
}