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

Remove EventServiceProvider #2834

Merged
merged 4 commits into from
May 13, 2024
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
33 changes: 24 additions & 9 deletions src/Platform/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(Auth $auth)
*
* @return JsonResponse|RedirectResponse
*/
public function login(Request $request)
public function login(Request $request, CookieJar $cookieJar)
{
$request->validate([
'email' => 'required|string',
Expand All @@ -66,16 +66,21 @@ public function login(Request $request)

$auth = $this->guard->attempt(
$request->only(['email', 'password']),
$request->filled('remember')
$request->boolean('remember')
);

if ($auth) {
return $this->sendLoginResponse($request);
if (! $auth) {
throw ValidationException::withMessages([
'email' => __('The details you entered did not match our records. Please double-check and try again.'),
]);
}

throw ValidationException::withMessages([
'email' => __('The details you entered did not match our records. Please double-check and try again.'),
]);
if ($request->boolean('remember')) {
$user = $cookieJar->forever($this->nameForLock(), $this->guard->id());
$cookieJar->queue($user);
}

return $this->sendLoginResponse($request);
}

/**
Expand All @@ -100,7 +105,7 @@ protected function sendLoginResponse(Request $request)
*/
public function showLoginForm(Request $request)
{
$user = $request->cookie('lockUser');
$user = $request->cookie($this->nameForLock());

/** @var EloquentUserProvider $provider */
$provider = $this->guard->getProvider();
Expand All @@ -118,7 +123,7 @@ public function showLoginForm(Request $request)
*/
public function resetCookieLockMe(CookieJar $cookieJar)
{
$lockUser = $cookieJar->forget('lockUser');
$lockUser = $cookieJar->forget($this->nameForLock());

return redirect()->route('platform.login')->withCookie($lockUser);
}
Expand Down Expand Up @@ -151,4 +156,14 @@ public function logout(Request $request)
? new JsonResponse([], 204)
: redirect('/');
}

/**
* Get a unique identifier for the auth session value.
*
* @return string
*/
private function nameForLock(): string
{
return sprintf('%s_%s', $this->guard->getName(), '_orchid_lock');
}
}
41 changes: 0 additions & 41 deletions src/Platform/Listeners/LockUserForLogin.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Platform/Providers/EventServiceProvider.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Platform/Providers/FoundationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public function provides(): array
IconServiceProvider::class,
BreadcrumbsServiceProvider::class,
RouteServiceProvider::class,
EventServiceProvider::class,
PlatformServiceProvider::class,
];
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/Platform/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Orchid\Tests\Feature\Platform;

use Illuminate\Support\Facades\Auth;
use Orchid\Tests\TestFeatureCase;

class AuthTest extends TestFeatureCase
Expand Down Expand Up @@ -38,7 +39,7 @@ public function testRouteDashboardLoginAuthSuccess(): void
])
->assertStatus(302)
->assertRedirect(route(config('platform.index')))
->assertCookieNotExpired('lockUser');
->assertCookieNotExpired(sprintf('%s_%s', Auth::guard()->getName(), '_orchid_lock'));
}

public function testRouteDashboardLoginAuthFail(): void
Expand All @@ -57,7 +58,7 @@ public function testRouteDashboardGuestLockAuth(): void
'lockUser' => 1,
])
->assertRedirect(route('platform.login'))
->assertCookieExpired('lockUser');
->assertCookieExpired(sprintf('%s_%s', Auth::guard()->getName(), '_orchid_lock'));
}

public function testRouteDashboardSwitchLogout(): void
Expand Down