Fix formatting and interfaces in nearly every file
This commit is contained in:
@@ -16,14 +16,14 @@ class ApiAuth
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Check if Authorization header is in place
|
||||
$api_key = $request->header('x-api-key', null);
|
||||
if($api_key === null) {
|
||||
if ($api_key === null) {
|
||||
$api_key = $request->header('Authorization', null);
|
||||
if ($api_key === null) {
|
||||
return $this->unauthorized('X-API-KEY header missing');
|
||||
@@ -32,11 +32,11 @@ class ApiAuth
|
||||
|
||||
// Try to find the user via API key. Cache this lookup
|
||||
$user = User::where('api_key', $api_key)->first();
|
||||
if($user === null) {
|
||||
if ($user === null) {
|
||||
return $this->unauthorized('User not found with key "'.$api_key.'"');
|
||||
}
|
||||
|
||||
if($user->state !== UserState::ACTIVE) {
|
||||
if ($user->state !== UserState::ACTIVE) {
|
||||
return $this->unauthorized('User is not ACTIVE, please contact an administrator');
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ class ApiAuth
|
||||
* Return an unauthorized message
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
private function unauthorized($details='')
|
||||
private function unauthorized($details = '')
|
||||
{
|
||||
return response([
|
||||
'error' => [
|
||||
'code' => '401',
|
||||
'code' => '401',
|
||||
'http_code' => 'Unauthorized',
|
||||
'message' => 'Invalid or missing API key ('. $details .')',
|
||||
'message' => 'Invalid or missing API key ('.$details.')',
|
||||
],
|
||||
], 401);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class JsonResponse
|
||||
{
|
||||
$response = $next($request);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class MeasureExecutionTime
|
||||
{
|
||||
// Get the response
|
||||
$response = $next($request);
|
||||
if(!defined('LUMEN_START')) {
|
||||
if (!defined('LUMEN_START')) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ class MeasureExecutionTime
|
||||
// I assume you're using valid json in your responses
|
||||
// Then I manipulate them below
|
||||
$content = json_decode($response->getContent(), true) + [
|
||||
'execution_time' => $executionTime,
|
||||
];
|
||||
'execution_time' => $executionTime,
|
||||
];
|
||||
|
||||
// Change the content of your response
|
||||
$response->setData($content);
|
||||
|
||||
@@ -10,9 +10,9 @@ class RedirectIfAuthenticated
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
|
||||
Reference in New Issue
Block a user