Skip to content

Commit 3acdc7a

Browse files
committed
Replace reset password with fortify
1 parent 598adc8 commit 3acdc7a

File tree

14 files changed

+83
-145
lines changed

14 files changed

+83
-145
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Illuminate\Validation\Rules\Password;
6+
7+
trait PasswordValidationRules
8+
{
9+
/**
10+
* Get the validation rules used to validate passwords.
11+
*
12+
* @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
13+
*/
14+
protected function passwordRules(): array
15+
{
16+
return ['required', 'string', Password::default(), 'confirmed'];
17+
}
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Validator;
7+
use Laravel\Fortify\Contracts\ResetsUserPasswords;
8+
9+
class ResetUserPassword implements ResetsUserPasswords
10+
{
11+
use PasswordValidationRules;
12+
13+
/**
14+
* Validate and reset the user's forgotten password.
15+
*
16+
* @param array<string, string> $input
17+
*/
18+
public function reset(User $user, array $input): void
19+
{
20+
Validator::make($input, [
21+
'password' => $this->passwordRules(),
22+
])->validate();
23+
24+
$user->forceFill([
25+
'password' => $input['password'],
26+
])->save();
27+
}
28+
}

app/Http/Controllers/Auth/NewPasswordController.php

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

app/Http/Controllers/Auth/PasswordResetLinkController.php

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

app/Providers/FortifyServiceProvider.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use App\Actions\Fortify\ResetUserPassword;
56
use Illuminate\Cache\RateLimiting\Limit;
67
use Illuminate\Http\Request;
78
use Illuminate\Support\Facades\RateLimiter;
@@ -26,10 +27,19 @@ public function register(): void
2627
*/
2728
public function boot(): void
2829
{
30+
$this->configureActions();
2931
$this->configureViews();
3032
$this->configureRateLimiting();
3133
}
3234

35+
/**
36+
* Configure Fortify actions.
37+
*/
38+
private function configureActions(): void
39+
{
40+
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
41+
}
42+
3343
/**
3444
* Configure Fortify views.
3545
*/
@@ -44,6 +54,15 @@ private function configureViews(): void
4454
'status' => $request->session()->get('status'),
4555
]));
4656

57+
Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('auth/forgot-password', [
58+
'status' => $request->session()->get('status'),
59+
]));
60+
61+
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/reset-password', [
62+
'email' => $request->email,
63+
'token' => $request->route('token'),
64+
]));
65+
4766
Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/two-factor-challenge'));
4867

4968
Fortify::confirmPasswordView(fn () => Inertia::render('auth/confirm-password'));

config/fortify.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@
145145

146146
'features' => [
147147
// Features::registration(),
148-
// Features::resetPasswords(),
148+
Features::resetPasswords(),
149149
Features::emailVerification(),
150-
// Features::updateProfileInformation(),
151-
// Features::updatePasswords(),
152150
Features::twoFactorAuthentication([
153151
'confirm' => true,
154152
'confirmPassword' => true,

resources/js/layouts/settings/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Button } from '@/components/ui/button';
33
import { Separator } from '@/components/ui/separator';
44
import { cn } from '@/lib/utils';
55
import { edit as editAppearance } from '@/routes/appearance';
6-
import { edit as editPassword } from '@/routes/password';
76
import { edit } from '@/routes/profile';
87
import { show } from '@/routes/two-factor';
8+
import { edit as editPassword } from '@/routes/user-password';
99
import { type NavItem } from '@/types';
1010
import { Link } from '@inertiajs/react';
1111
import { type PropsWithChildren } from 'react';

resources/js/pages/auth/forgot-password.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Components
2-
import PasswordResetLinkController from '@/actions/App/Http/Controllers/Auth/PasswordResetLinkController';
32
import { login } from '@/routes';
3+
import { email } from '@/routes/password';
44
import { Form, Head } from '@inertiajs/react';
55
import { LoaderCircle } from 'lucide-react';
66

@@ -26,7 +26,7 @@ export default function ForgotPassword({ status }: { status?: string }) {
2626
)}
2727

2828
<div className="space-y-6">
29-
<Form {...PasswordResetLinkController.store.form()}>
29+
<Form {...email.form()}>
3030
{({ processing, errors }) => (
3131
<>
3232
<div className="grid gap-2">

resources/js/pages/auth/reset-password.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NewPasswordController from '@/actions/App/Http/Controllers/Auth/NewPasswordController';
1+
import { update } from '@/routes/password';
22
import { Form, Head } from '@inertiajs/react';
33
import { LoaderCircle } from 'lucide-react';
44

@@ -22,7 +22,7 @@ export default function ResetPassword({ token, email }: ResetPasswordProps) {
2222
<Head title="Reset password" />
2323

2424
<Form
25-
{...NewPasswordController.store.form()}
25+
{...update.form()}
2626
transform={(data) => ({ ...data, token, email })}
2727
resetOnSuccess={['password', 'password_confirmation']}
2828
>

resources/js/pages/settings/password.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import HeadingSmall from '@/components/heading-small';
1111
import { Button } from '@/components/ui/button';
1212
import { Input } from '@/components/ui/input';
1313
import { Label } from '@/components/ui/label';
14-
import { edit } from '@/routes/password';
14+
import { edit } from '@/routes/user-password';
1515

1616
const breadcrumbs: BreadcrumbItem[] = [
1717
{

0 commit comments

Comments
 (0)