Skip to content
39 changes: 39 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\CreatesNewUsers;

class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;

/**
* Validate and create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
])->validate();

return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => $input['password'],
]);
}
}
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.

52 changes: 0 additions & 52 deletions app/Http/Controllers/Auth/RegisteredUserController.php

This file was deleted.

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

namespace App\Providers;

use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
Expand All @@ -26,24 +28,46 @@ 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);
Fortify::createUsersUsing(CreateNewUser::class);
}

/**
* Configure Fortify views.
*/
private function configureViews(): void
{
Fortify::loginView(fn (Request $request) => Inertia::render('auth/login', [
'canResetPassword' => Features::enabled(Features::resetPasswords()),
'canRegister' => Features::enabled(Features::registration()),
'status' => $request->session()->get('status'),
]));

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

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

Fortify::verifyEmailView(fn (Request $request) => Inertia::render('auth/verify-email', [
'status' => $request->session()->get('status'),
]));

Fortify::registerView(fn () => Inertia::render('auth/register'));

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

Fortify::confirmPasswordView(fn () => Inertia::render('auth/confirm-password'));
Expand Down
6 changes: 2 additions & 4 deletions config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@
*/

'features' => [
// Features::registration(),
// Features::resetPasswords(),
Features::registration(),
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
21 changes: 14 additions & 7 deletions resources/js/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import { Form, Head } from '@inertiajs/react';
interface LoginProps {
status?: string;
canResetPassword: boolean;
canRegister: boolean;
}

export default function Login({ status, canResetPassword }: LoginProps) {
export default function Login({
status,
canResetPassword,
canRegister,
}: LoginProps) {
return (
<AuthLayout
title="Log in to your account"
Expand Down Expand Up @@ -93,12 +98,14 @@ export default function Login({ status, canResetPassword }: LoginProps) {
</Button>
</div>

<div className="text-center text-sm text-muted-foreground">
Don't have an account?{' '}
<TextLink href={register()} tabIndex={5}>
Sign up
</TextLink>
</div>
{canRegister && (
<div className="text-center text-sm text-muted-foreground">
Don't have an account?{' '}
<TextLink href={register()} tabIndex={5}>
Sign up
</TextLink>
</div>
)}
</>
)}
</Form>
Expand Down
Loading
Loading