Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent authored and github-actions[bot] committed Oct 16, 2022
1 parent 4cb6f73 commit 0e0a231
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/Http/Controllers/Onboarding/OnboardingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class OnboardingController extends Controller
{
public function index(Request $request)
{

throw_unless(config('web.config.ONBOARDING'), 'Onboarding is disabled');

$user = User::query()
Expand All @@ -25,18 +24,17 @@ public function index(Request $request)
'mainCharacterId' => $user->main_character_id,
'enlistments' => Enlistment::query()
->with(['corporation' => ['alliance']])
->get()
->get(),
]);
}

public function complete()
{

// create onboarding record
Onboarding::query()->create([
'user_id' => auth()->user()->getAuthIdentifier(),
]);

return redirect()->route('home');
}
}
}
13 changes: 5 additions & 8 deletions src/Http/Middleware/OnboardingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,35 @@

namespace Seatplus\Web\Http\Middleware;

use Illuminate\Http\Request;
use Closure;
use Illuminate\Http\Request;
use Seatplus\Auth\Models\User;
use Seatplus\Web\Models\Onboarding;

class OnboardingMiddleware
{

private $user;

public function handle(Request $request, Closure $next)
{

// if onboarding is disabled, skip middleware
if(! config('web.config.ONBOARDING')) {
if (! config('web.config.ONBOARDING')) {
return $next($request);
}

$this->setUser($request);

// if user has been created longer then an hour ago don't bother with onboarding
if($this->getUser()->created_at->diffInMinutes(now()) >= 60) {
if ($this->getUser()->created_at->diffInMinutes(now()) >= 60) {
return $next($request);
}

// if user has completed onboarding don't bother with onboarding
if(Onboarding::firstWhere('user_id', $this->getUser()->getAuthIdentifier())) {
if (Onboarding::firstWhere('user_id', $this->getUser()->getAuthIdentifier())) {
return $next($request);
}

return redirect()->route('onboarding');

}

private function setUser(Request $request): void
Expand All @@ -45,4 +42,4 @@ private function getUser(): User
{
return $this->user;
}
}
}
2 changes: 0 additions & 2 deletions src/Models/Onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Seatplus\Auth\Models\User;
use Seatplus\Eveapi\Models\Universe\Location;
use Seatplus\Eveapi\Models\Universe\System;

class Onboarding extends Model
{
Expand Down
7 changes: 2 additions & 5 deletions tests/Integration/OnboardingLifeCycleTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

use Seatplus\Web\Models\Onboarding;
use function Pest\Laravel\actingAs;
use Seatplus\Web\Models\Onboarding;

it('throws error when turned off and navigated to onboarding if turned off', function () {
config()->set('web.config.ONBOARDING', false);

actingAs($this->test_user);

$response = $this->get(route('onboarding'))->assertStatus(500);

});

it('redirects to onboarding if turned on', function () {
Expand All @@ -21,7 +20,6 @@

$response = $this->get(route('home'))
->assertRedirect(route('onboarding'));

});

it('does not redirect to onboarding if user has been created longer then an hour ago', function () {
Expand Down Expand Up @@ -61,7 +59,6 @@

$response->assertOk()
->assertInertia(fn (\Inertia\Testing\AssertableInertia $page) => $page->component('Onboarding/Index'));

});

it('completes onboarding', function () {
Expand All @@ -77,4 +74,4 @@
->assertRedirect(route('home'));

expect(Onboarding::firstWhere('user_id', $this->test_user->getAuthIdentifier()))->toBeInstanceOf(Onboarding::class);
});
});

0 comments on commit 0e0a231

Please sign in to comment.