Skip to content

Commit 034974c

Browse files
committed
Replace forget password with fortify
1 parent c7c597f commit 034974c

File tree

14 files changed

+79
-150
lines changed

14 files changed

+79
-150
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Laravel\Fortify\Contracts\ResetsUserPasswords;
9+
10+
class ResetUserPassword implements ResetsUserPasswords
11+
{
12+
use PasswordValidationRules;
13+
14+
/**
15+
* Validate and reset the user's forgotten password.
16+
*
17+
* @param array<string, string> $input
18+
*/
19+
public function reset(User $user, array $input): void
20+
{
21+
Validator::make($input, [
22+
'password' => $this->passwordRules(),
23+
])->validate();
24+
25+
$user->forceFill([
26+
'password' => Hash::make($input['password']),
27+
])->save();
28+
}
29+
}

app/Http/Controllers/Auth/NewPasswordController.php

Lines changed: 0 additions & 69 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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
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;
8-
use Illuminate\Support\Facades\Route;
99
use Illuminate\Support\ServiceProvider;
1010
use Illuminate\Support\Str;
1111
use Inertia\Inertia;
12+
use Laravel\Fortify\Features;
1213
use Laravel\Fortify\Fortify;
1314

1415
class FortifyServiceProvider extends ServiceProvider
@@ -26,8 +27,10 @@ public function register(): void
2627
*/
2728
public function boot(): void
2829
{
30+
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
31+
2932
Fortify::loginView(fn (Request $request) => Inertia::render('auth/Login', [
30-
'canResetPassword' => Route::has('password.request'),
33+
'canResetPassword' => Features::enabled(Features::resetPasswords()),
3134
'status' => $request->session()->get('status'),
3235
]));
3336

@@ -39,6 +42,15 @@ public function boot(): void
3942

4043
Fortify::confirmPasswordView(fn () => Inertia::render('auth/ConfirmPassword'));
4144

45+
Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('auth/ForgotPassword', [
46+
'status' => $request->session()->get('status'),
47+
]));
48+
49+
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/ResetPassword', [
50+
'email' => $request->email,
51+
'token' => $request->route('token'),
52+
]));
53+
4254
RateLimiter::for('two-factor', function (Request $request) {
4355
return Limit::perMinute(5)->by($request->session()->get('login.id'));
4456
});

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.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Button } from '@/components/ui/button';
44
import { Separator } from '@/components/ui/separator';
55
import { toUrl, urlIsActive } from '@/lib/utils';
66
import { edit as editAppearance } from '@/routes/appearance';
7-
import { edit as editPassword } from '@/routes/password';
87
import { edit as editProfile } from '@/routes/profile';
98
import { show } from '@/routes/two-factor';
9+
import { edit as editPassword } from '@/routes/user-password';
1010
import { type NavItem } from '@/types';
1111
import { Link } from '@inertiajs/vue3';
1212

resources/js/pages/auth/ForgotPassword.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup lang="ts">
2-
import PasswordResetLinkController from '@/actions/App/Http/Controllers/Auth/PasswordResetLinkController';
32
import InputError from '@/components/InputError.vue';
43
import TextLink from '@/components/TextLink.vue';
54
import { Button } from '@/components/ui/button';
65
import { Input } from '@/components/ui/input';
76
import { Label } from '@/components/ui/label';
87
import AuthLayout from '@/layouts/AuthLayout.vue';
98
import { login } from '@/routes';
9+
import { email } from '@/routes/password';
1010
import { Form, Head } from '@inertiajs/vue3';
1111
import { LoaderCircle } from 'lucide-vue-next';
1212
@@ -30,10 +30,7 @@ defineProps<{
3030
</div>
3131

3232
<div class="space-y-6">
33-
<Form
34-
v-bind="PasswordResetLinkController.store.form()"
35-
v-slot="{ errors, processing }"
36-
>
33+
<Form v-bind="email.form()" v-slot="{ errors, processing }">
3734
<div class="grid gap-2">
3835
<Label for="email">Email address</Label>
3936
<Input

resources/js/pages/auth/ResetPassword.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script setup lang="ts">
2-
import NewPasswordController from '@/actions/App/Http/Controllers/Auth/NewPasswordController';
32
import InputError from '@/components/InputError.vue';
43
import { Button } from '@/components/ui/button';
54
import { Input } from '@/components/ui/input';
65
import { Label } from '@/components/ui/label';
76
import AuthLayout from '@/layouts/AuthLayout.vue';
7+
import { update } from '@/routes/password';
88
import { Form, Head } from '@inertiajs/vue3';
99
import { LoaderCircle } from 'lucide-vue-next';
1010
import { ref } from 'vue';
@@ -25,7 +25,7 @@ const inputEmail = ref(props.email);
2525
<Head title="Reset password" />
2626

2727
<Form
28-
v-bind="NewPasswordController.store.form()"
28+
v-bind="update.form()"
2929
:transform="(data) => ({ ...data, token, email })"
3030
:reset-on-success="['password', 'password_confirmation']"
3131
v-slot="{ errors, processing }"

resources/js/pages/settings/Password.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PasswordController from '@/actions/App/Http/Controllers/Settings/Password
33
import InputError from '@/components/InputError.vue';
44
import AppLayout from '@/layouts/AppLayout.vue';
55
import SettingsLayout from '@/layouts/settings/Layout.vue';
6-
import { edit } from '@/routes/password';
6+
import { edit } from '@/routes/user-password';
77
import { Form, Head } from '@inertiajs/vue3';
88
import { ref } from 'vue';
99

0 commit comments

Comments
 (0)