Skip to content

Commit

Permalink
♻️ Apply Analytics tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed Jul 13, 2023
1 parent d774c52 commit f837ee2
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/admin/src/Actions/AttemptToAuthenticate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopper\Actions;

use Closure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopper\Actions;

use Closure;
Expand All @@ -12,7 +14,7 @@

final class RedirectIfTwoFactorAuthenticatable
{
public function handle(array $data, Closure $next): Response | Redirector
public function handle(array $data, Closure $next): Response|Redirector
{
$user = $this->validateCredentials($data);

Expand All @@ -26,23 +28,23 @@ public function handle(array $data, Closure $next): Response | Redirector

protected function validateCredentials(array $request)
{
$model = Shopper::auth()->getProvider()->getModel();
$model = Shopper::auth()->getProvider()->getModel(); // @phpstan-ignore-line

return tap($model::where('email', $request['email'])->first(), function ($user) use ($request) {
if (! $user || ! Hash::check(value: $request['password'], hashedValue: $user->password)) {
return tap($model::where('email', $request['email'])->first(), function ($user) use ($request): void {
if (! $user || ! Hash::check(value: $request['password'], hashedValue: $user->password)) {
$this->throwFailedAuthenticationException();
}
});
}

protected function throwFailedAuthenticationException()
protected function throwFailedAuthenticationException(): void
{
throw ValidationException::withMessages([
'email' => __('shopper::messages.login.failed'),
]);
}

protected function twoFactorChallengeResponse($user, bool $remember): Redirector | Response
protected function twoFactorChallengeResponse($user, bool $remember): Redirector|Response
{
request()->session()->put([
'login.id' => $user->getKey(),
Expand Down
2 changes: 2 additions & 0 deletions packages/admin/src/Contracts/LoginResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopper\Contracts;

use Illuminate\Contracts\Support\Responsable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function create(TwoFactorLoginRequest $request): View
return view('shopper::auth.two-factor-login');
}

public function store(TwoFactorLoginRequest $request): FailedTwoFactorLoginResponse | JsonResponse| RedirectResponse
public function store(TwoFactorLoginRequest $request): FailedTwoFactorLoginResponse|JsonResponse|RedirectResponse
{
$user = $request->challengedUser();

Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Http/Livewire/Pages/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function authenticate()
RedirectIfTwoFactorAuthenticatable::class,
AttemptToAuthenticate::class,
]))
->then(fn ($request) => app(LoginResponse::class));
->then(fn ($request) => app(LoginResponse::class));
}

public function render(): View
Expand Down
6 changes: 2 additions & 4 deletions packages/admin/src/Http/Requests/TwoFactorLoginRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace Shopper\Http\Requests;

use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\ValidationException;
use Shopper\Contracts\TwoFactorAuthenticationProvider;
use Shopper\Facades\Shopper;
use Shopper\Http\Responses\FailedTwoFactorLoginResponse;
Expand Down Expand Up @@ -51,7 +49,7 @@ public function validRecoveryCode(): ?string

public function hasChallengedUser(): bool
{
$model = Shopper::auth()->getProvider()->getModel();
$model = Shopper::auth()->getProvider()->getModel(); // @phpstan-ignore-line

return $this->session()->has('login.id') &&
$model::find($this->session()->get('login.id'));
Expand All @@ -63,7 +61,7 @@ public function challengedUser()
return $this->challengedUser;
}

$model = Shopper::auth()->getProvider()->getModel();
$model = Shopper::auth()->getProvider()->getModel(); // @phpstan-ignore-line

if (! $this->session()->has('login.id') ||
! $user = $model::find($this->session()->pull('login.id'))) {
Expand Down
2 changes: 2 additions & 0 deletions packages/admin/src/Http/Responses/LoginResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopper\Http\Responses;

use Shopper\Contracts\LoginResponse as Responsable;
Expand Down
8 changes: 5 additions & 3 deletions packages/admin/src/ShopperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Livewire\Livewire;
use PragmaRX\Google2FA\Google2FA;
use Shopper\Contracts\FailedTwoFactorLoginResponse as FailedTwoFactorLoginResponseContract;
use Shopper\Contracts\LoginResponse as LoginResponseContract;
use Shopper\Contracts\LoginResponse;
use Shopper\Contracts\LoginResponse as LoginResponseContract;
use Shopper\Contracts\TwoFactorAuthenticationProvider as TwoFactorAuthenticationProviderContract;
use Shopper\Contracts\TwoFactorDisabledResponse as TwoFactorDisabledResponseContract;
use Shopper\Contracts\TwoFactorEnabledResponse as TwoFactorEnabledResponseContract;
Expand Down Expand Up @@ -115,8 +115,10 @@ protected function bootLivewireComponents(): void
{
Livewire::addPersistentMiddleware([Authenticate::class]);

foreach (array_merge(config('shopper.components', []),
$this->getLivewirePagesComponents()) as $alias => $component) {
foreach (array_merge(
config('shopper.components', []),
$this->getLivewirePagesComponents()
) as $alias => $component) {
Livewire::component("shopper-$alias", $component);
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/Traits/ReviewRateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Shopper\Core\Traits;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Collection;
use Shopper\Core\Models\Review;
Expand Down

0 comments on commit f837ee2

Please sign in to comment.