Skip to content

Commit 04781f1

Browse files
Consolidate password and two-factor settings into a unified security page (#316)
Co-authored-by: WendellAdriel <11641518+WendellAdriel@users.noreply.github.com> Co-authored-by: WendellAdriel <me@wendelladriel.com>
1 parent 307d39e commit 04781f1

File tree

12 files changed

+455
-526
lines changed

12 files changed

+455
-526
lines changed

app/Http/Controllers/Settings/PasswordController.php

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Settings;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Requests\Settings\PasswordUpdateRequest;
7+
use App\Http\Requests\Settings\TwoFactorAuthenticationRequest;
8+
use Illuminate\Http\RedirectResponse;
9+
use Illuminate\Routing\Controllers\HasMiddleware;
10+
use Illuminate\Routing\Controllers\Middleware;
11+
use Inertia\Inertia;
12+
use Inertia\Response;
13+
use Laravel\Fortify\Features;
14+
15+
class SecurityController extends Controller implements HasMiddleware
16+
{
17+
/**
18+
* Get the middleware that should be assigned to the controller.
19+
*/
20+
public static function middleware(): array
21+
{
22+
return Features::canManageTwoFactorAuthentication()
23+
&& Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
24+
? [new Middleware('password.confirm', only: ['edit'])]
25+
: [];
26+
}
27+
28+
/**
29+
* Show the user's security settings page.
30+
*/
31+
public function edit(TwoFactorAuthenticationRequest $request): Response
32+
{
33+
$props = [
34+
'canManageTwoFactor' => Features::canManageTwoFactorAuthentication(),
35+
];
36+
37+
if (Features::canManageTwoFactorAuthentication()) {
38+
$request->ensureStateIsValid();
39+
40+
$props['twoFactorEnabled'] = $request->user()->hasEnabledTwoFactorAuthentication();
41+
$props['requiresConfirmation'] = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm');
42+
}
43+
44+
return Inertia::render('settings/security', $props);
45+
}
46+
47+
/**
48+
* Update the user's password.
49+
*/
50+
public function update(PasswordUpdateRequest $request): RedirectResponse
51+
{
52+
$request->user()->update([
53+
'password' => $request->password,
54+
]);
55+
56+
return back();
57+
}
58+
}

app/Http/Controllers/Settings/TwoFactorAuthenticationController.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

app/Http/Requests/Settings/TwoFactorAuthenticationRequest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@
44

55
use Illuminate\Contracts\Validation\ValidationRule;
66
use Illuminate\Foundation\Http\FormRequest;
7-
use Laravel\Fortify\Features;
87
use Laravel\Fortify\InteractsWithTwoFactorState;
98

109
class TwoFactorAuthenticationRequest extends FormRequest
1110
{
1211
use InteractsWithTwoFactorState;
1312

14-
/**
15-
* Determine if the user is authorized to make this request.
16-
*/
17-
public function authorize(): bool
18-
{
19-
return Features::enabled(Features::twoFactorAuthentication());
20-
}
21-
2213
/**
2314
* Get the validation rules that apply to the request.
2415
*

resources/js/layouts/settings/layout.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { useCurrentUrl } from '@/hooks/use-current-url';
77
import { cn, toUrl } from '@/lib/utils';
88
import { edit as editAppearance } from '@/routes/appearance';
99
import { edit } from '@/routes/profile';
10-
import { show } from '@/routes/two-factor';
11-
import { edit as editPassword } from '@/routes/user-password';
10+
import { edit as editSecurity } from '@/routes/security';
1211
import type { NavItem } from '@/types';
1312

1413
const sidebarNavItems: NavItem[] = [
@@ -18,13 +17,8 @@ const sidebarNavItems: NavItem[] = [
1817
icon: null,
1918
},
2019
{
21-
title: 'Password',
22-
href: editPassword(),
23-
icon: null,
24-
},
25-
{
26-
title: 'Two-factor auth',
27-
href: show(),
20+
title: 'Security',
21+
href: editSecurity(),
2822
icon: null,
2923
},
3024
{

resources/js/pages/settings/password.tsx

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)