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

Send JSON response if request is an AJAX request #75

Merged
merged 2 commits into from
Sep 21, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;

class EmailVerificationNotificationController extends Controller
Expand All @@ -18,14 +18,14 @@ public function store(Request $request)
{
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new Response('', 204)
? new JsonResponse('', 204)
: redirect(config('fortify.home'));
}

$request->user()->sendEmailVerificationNotification();

return $request->wantsJson()
? new Response('', 202)
? new JsonResponse('', 202)
: back()->with('status', 'verification-link-sent');
}
}
4 changes: 2 additions & 2 deletions src/Http/Controllers/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;

Expand All @@ -21,7 +21,7 @@ public function update(Request $request, UpdatesUserPasswords $updater)
$updater->update($request->user(), $request->all());

return $request->wantsJson()
? new Response('', 200)
? new JsonResponse('', 200)
: back()->with('status', 'password-updated');
}
}
4 changes: 2 additions & 2 deletions src/Http/Controllers/ProfileInformationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;

Expand All @@ -22,7 +22,7 @@ public function update(Request $request,
$updater->update($request->user(), $request->all());

return $request->wantsJson()
? new Response('', 200)
? new JsonResponse('', 200)
: back()->with('status', 'profile-information-updated');
}
}
3 changes: 2 additions & 1 deletion src/Http/Controllers/RecoveryCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Actions\GenerateNewRecoveryCodes;
Expand Down Expand Up @@ -38,7 +39,7 @@ public function store(Request $request, GenerateNewRecoveryCodes $generate)
$generate($request->user());

return $request->wantsJson()
? response('', 200)
? new JsonResponse('', 200)
: back()->with('status', 'recovery-codes-generated');
}
}
5 changes: 3 additions & 2 deletions src/Http/Controllers/TwoFactorAuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Actions\DisableTwoFactorAuthentication;
Expand All @@ -21,7 +22,7 @@ public function store(Request $request, EnableTwoFactorAuthentication $enable)
$enable($request->user());

return $request->wantsJson()
? response('', 200)
? new JsonResponse('', 200)
: back()->with('status', 'two-factor-authentication-enabled');
}

Expand All @@ -37,7 +38,7 @@ public function destroy(Request $request, DisableTwoFactorAuthentication $disabl
$disable($request->user());

return $request->wantsJson()
? response('', 200)
? new JsonResponse('', 200)
: back()->with('status', 'two-factor-authentication-disabled');
}
}
3 changes: 2 additions & 1 deletion src/Http/Responses/LogoutResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\LogoutResponse as LogoutResponseContract;

Expand All @@ -16,7 +17,7 @@ class LogoutResponse implements LogoutResponseContract
public function toResponse($request)
{
return $request->wantsJson()
? new Response('', 204)
? new JsonResponse('', 204)
: redirect('/');
}
}
3 changes: 2 additions & 1 deletion src/Http/Responses/PasswordConfirmedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract;

Expand All @@ -16,7 +17,7 @@ class PasswordConfirmedResponse implements PasswordConfirmedResponseContract
public function toResponse($request)
{
return $request->wantsJson()
? new Response('', 201)
? new JsonResponse('', 201)
: redirect()->intended(config('fortify.home'));
}
}
3 changes: 2 additions & 1 deletion src/Http/Responses/RegisterResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;

Expand All @@ -16,7 +17,7 @@ class RegisterResponse implements RegisterResponseContract
public function toResponse($request)
{
return $request->wantsJson()
? new Response('', 201)
? new JsonResponse('', 201)
: redirect(config('fortify.home'));
}
}
3 changes: 2 additions & 1 deletion src/Http/Responses/TwoFactorLoginResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;

class TwoFactorLoginResponse implements TwoFactorLoginResponseContract
Expand All @@ -15,7 +16,7 @@ class TwoFactorLoginResponse implements TwoFactorLoginResponseContract
public function toResponse($request)
{
return $request->wantsJson()
? response('', 204)
? new JsonResponse('', 204)
: redirect(config('fortify.home'));
}
}