Deny user API access if they're not ACTIVE #119
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Models\Enums\UserState;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Log;
|
use Log;
|
||||||
use Closure;
|
use Closure;
|
||||||
@@ -36,6 +37,10 @@ class ApiAuth
|
|||||||
return $this->unauthorized('User not found with key "'.$api_key.'"');
|
return $this->unauthorized('User not found with key "'.$api_key.'"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($user->state !== UserState::ACTIVE) {
|
||||||
|
return $this->unauthorized('User is not ACTIVE, please contact an administrator');
|
||||||
|
}
|
||||||
|
|
||||||
// Set the user to the request
|
// Set the user to the request
|
||||||
Auth::setUser($user);
|
Auth::setUser($user);
|
||||||
$request->merge(['user' => $user]);
|
$request->merge(['user' => $user]);
|
||||||
|
|||||||
@@ -35,9 +35,8 @@ class ApiTest extends TestCase
|
|||||||
->assertStatus(401);
|
->assertStatus(401);
|
||||||
|
|
||||||
// Test upper/lower case of Authorization header, etc
|
// Test upper/lower case of Authorization header, etc
|
||||||
$this->withHeaders($this->apiHeaders())->get($uri)
|
$response = $this->withHeaders($this->apiHeaders())->get($uri);
|
||||||
->assertStatus(200)
|
$response->assertStatus(200)->assertJson(['id' => $pirep->id], true);
|
||||||
->assertJson(['id' => $pirep->id], true);
|
|
||||||
|
|
||||||
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
@@ -52,6 +51,20 @@ class ApiTest extends TestCase
|
|||||||
->assertJson(['id' => $pirep->id], true);
|
->assertJson(['id' => $pirep->id], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testApiDeniedOnInactiveUser()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create([
|
||||||
|
'state' => UserState::PENDING
|
||||||
|
]);
|
||||||
|
|
||||||
|
$uri = '/api/user';
|
||||||
|
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
||||||
|
->assertStatus(401);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the airport data is returned
|
* Make sure the airport data is returned
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user