Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Actions\Fortify;

use Illuminate\Validation\Rules\Password;

trait PasswordValidationRules
{
/**
* Get the validation rules used to validate passwords.
*
* @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
*/
protected function passwordRules(): array
{
return ['required', 'string', Password::default(), 'confirmed'];
}
}
28 changes: 28 additions & 0 deletions app/Actions/Fortify/ResetUserPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\ResetsUserPasswords;

class ResetUserPassword implements ResetsUserPasswords
{
use PasswordValidationRules;

/**
* Validate and reset the user's forgotten password.
*
* @param array<string, string> $input
*/
public function reset(User $user, array $input): void
{
Validator::make($input, [
'password' => $this->passwordRules(),
])->validate();

$user->forceFill([
'password' => $input['password'],
])->save();
}
}
69 changes: 0 additions & 69 deletions app/Http/Controllers/Auth/NewPasswordController.php

This file was deleted.

41 changes: 0 additions & 41 deletions app/Http/Controllers/Auth/PasswordResetLinkController.php

This file was deleted.

19 changes: 19 additions & 0 deletions app/Providers/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Actions\Fortify\ResetUserPassword;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
Expand All @@ -26,10 +27,19 @@ public function register(): void
*/
public function boot(): void
{
$this->configureActions();
$this->configureViews();
$this->configureRateLimiting();
}

/**
* Configure Fortify actions.
*/
private function configureActions(): void
{
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
}

/**
* Configure Fortify views.
*/
Expand All @@ -44,6 +54,15 @@ private function configureViews(): void
'status' => $request->session()->get('status'),
]));

Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('auth/forgot-password', [
'status' => $request->session()->get('status'),
]));

Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/reset-password', [
'email' => $request->email,
'token' => $request->route('token'),
]));

Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/two-factor-challenge'));

Fortify::confirmPasswordView(fn () => Inertia::render('auth/confirm-password'));
Expand Down
4 changes: 1 addition & 3 deletions config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@

'features' => [
// Features::registration(),
// Features::resetPasswords(),
Features::resetPasswords(),
Features::emailVerification(),
// Features::updateProfileInformation(),
// Features::updatePasswords(),
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
Expand Down
2 changes: 1 addition & 1 deletion resources/js/layouts/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils';
import { edit as editAppearance } from '@/routes/appearance';
import { edit as editPassword } from '@/routes/password';
import { edit } from '@/routes/profile';
import { show } from '@/routes/two-factor';
import { edit as editPassword } from '@/routes/user-password';
import { type NavItem } from '@/types';
import { Link } from '@inertiajs/react';
import { type PropsWithChildren } from 'react';
Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/auth/forgot-password.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Components
import PasswordResetLinkController from '@/actions/App/Http/Controllers/Auth/PasswordResetLinkController';
import { login } from '@/routes';
import { email } from '@/routes/password';
import { Form, Head } from '@inertiajs/react';
import { LoaderCircle } from 'lucide-react';

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

<div className="space-y-6">
<Form {...PasswordResetLinkController.store.form()}>
<Form {...email.form()}>
{({ processing, errors }) => (
<>
<div className="grid gap-2">
Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/auth/reset-password.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NewPasswordController from '@/actions/App/Http/Controllers/Auth/NewPasswordController';
import { update } from '@/routes/password';
import { Form, Head } from '@inertiajs/react';

import InputError from '@/components/input-error';
Expand All @@ -22,7 +22,7 @@ export default function ResetPassword({ token, email }: ResetPasswordProps) {
<Head title="Reset password" />

<Form
{...NewPasswordController.store.form()}
{...update.form()}
transform={(data) => ({ ...data, token, email })}
resetOnSuccess={['password', 'password_confirmation']}
>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/pages/settings/password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HeadingSmall from '@/components/heading-small';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { edit } from '@/routes/password';
import { edit } from '@/routes/user-password';

const breadcrumbs: BreadcrumbItem[] = [
{
Expand Down
14 changes: 0 additions & 14 deletions routes/auth.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use App\Http\Controllers\Auth\NewPasswordController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use Illuminate\Support\Facades\Route;

Expand All @@ -11,16 +9,4 @@

Route::post('register', [RegisteredUserController::class, 'store'])
->name('register.store');

Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
->name('password.request');

Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])
->name('password.email');

Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
->name('password.reset');

Route::post('reset-password', [NewPasswordController::class, 'store'])
->name('password.store');
});
4 changes: 2 additions & 2 deletions routes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
Route::patch('settings/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('settings/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');

Route::get('settings/password', [PasswordController::class, 'edit'])->name('password.edit');
Route::get('settings/password', [PasswordController::class, 'edit'])->name('user-password.edit');

Route::put('settings/password', [PasswordController::class, 'update'])
->middleware('throttle:6,1')
->name('password.update');
->name('user-password.update');

Route::get('settings/appearance', function () {
return Inertia::render('settings/appearance');
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Auth/PasswordResetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function test_password_can_be_reset_with_valid_token()
$this->post(route('password.email'), ['email' => $user->email]);

Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
$response = $this->post(route('password.store'), [
$response = $this->post(route('password.update'), [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
Expand All @@ -75,7 +75,7 @@ public function test_password_cannot_be_reset_with_invalid_token(): void
{
$user = User::factory()->create();

$response = $this->post(route('password.store'), [
$response = $this->post(route('password.update'), [
'token' => 'invalid-token',
'email' => $user->email,
'password' => 'newpassword123',
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/Settings/PasswordUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_password_update_page_is_displayed()

$response = $this
->actingAs($user)
->get(route('password.edit'));
->get(route('user-password.edit'));

$response->assertStatus(200);
}
Expand All @@ -28,16 +28,16 @@ public function test_password_can_be_updated()

$response = $this
->actingAs($user)
->from(route('password.edit'))
->put(route('password.update'), [
->from(route('user-password.edit'))
->put(route('user-password.update'), [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);

$response
->assertSessionHasNoErrors()
->assertRedirect(route('password.edit'));
->assertRedirect(route('user-password.edit'));

$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
}
Expand All @@ -48,15 +48,15 @@ public function test_correct_password_must_be_provided_to_update_password()

$response = $this
->actingAs($user)
->from(route('password.edit'))
->put(route('password.update'), [
->from(route('user-password.edit'))
->put(route('user-password.update'), [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);

$response
->assertSessionHasErrors('current_password')
->assertRedirect(route('password.edit'));
->assertRedirect(route('user-password.edit'));
}
}
Loading