Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Allow redirect()->intended() responses to be resolved via the Container #551

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions src/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Laravel\Fortify;

use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Contracts\Auth\StatefulGuard;
crynobone marked this conversation as resolved.
Show resolved Hide resolved
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Route;
crynobone marked this conversation as resolved.
Show resolved Hide resolved
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse as EmailVerificationNotificationSentResponseContract;
Expand Down Expand Up @@ -73,6 +75,10 @@ public function register()
$this->app->bind(StatefulGuard::class, function () {
return Auth::guard(config('fortify.guard', null));
});

$this->app->bind(PasswordBroker::class, function () {
crynobone marked this conversation as resolved.
Show resolved Hide resolved
return Password::broker(config('fortify.passwords'));
});
crynobone marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Responses\RedirectAsIntended;

class EmailVerificationNotificationController extends Controller
{
Expand All @@ -21,7 +21,7 @@ public function store(Request $request)
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new JsonResponse('', 204)
: redirect()->intended(Fortify::redirects('email-verification'));
: app(RedirectAsIntended::class, ['name' => 'email-verification']);
}

$request->user()->sendEmailVerificationNotification();
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/EmailVerificationPromptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Responses\RedirectAsIntended;

class EmailVerificationPromptController extends Controller
{
Expand All @@ -18,7 +18,7 @@ class EmailVerificationPromptController extends Controller
public function __invoke(Request $request)
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(Fortify::redirects('email-verification'))
? app(RedirectAsIntended::class, ['name' => 'email-verification'])
: app(VerifyEmailViewResponse::class);
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/NewPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ function ($user) use ($request) {
*/
protected function broker(): PasswordBroker
{
return Password::broker(config('fortify.passwords'));
return app(PasswordBroker::class);
crynobone marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function store(Request $request): Responsable
*/
protected function broker(): PasswordBroker
{
return Password::broker(config('fortify.passwords'));
return app(PasswordBroker::class);
crynobone marked this conversation as resolved.
Show resolved Hide resolved
}
}
31 changes: 31 additions & 0 deletions src/Http/Responses/RedirectAsIntended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Contracts\Support\Responsable;
use Laravel\Fortify\Fortify;

class RedirectAsIntended implements Responsable
{
/**
* Create a new class instance.
*
* @param string $name
* @return void
*/
public function __construct(public string $name)
{
//
}

/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return redirect()->intended(Fortify::redirects($this->name));
}
}
Loading