Skip to content

Commit

Permalink
Remove EventServiceProvider (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna authored May 13, 2024
1 parent 44772b1 commit 47803b6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 90 deletions.
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

0 comments on commit 47803b6

Please sign in to comment.