-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from fleetbase/dev-v0.3.3
v0.3.3
- Loading branch information
Showing
12 changed files
with
216 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Fleetbase\Http\Controllers\Api\v1; | ||
|
||
use Fleetbase\Http\Controllers\Controller; | ||
use Fleetbase\Http\Resources\Organization; | ||
use Fleetbase\Models\ApiCredential; | ||
use Fleetbase\Models\Company; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Str; | ||
|
||
class OrganizationController extends Controller | ||
{ | ||
public function getCurrent(Request $request) | ||
{ | ||
$token = $request->bearerToken(); | ||
$isSecretKey = Str::startsWith($token, '$'); | ||
|
||
// Depending on API key format set the connection to find credential on | ||
$connection = Str::startsWith($token, 'flb_test_') ? 'sandbox' : 'mysql'; | ||
|
||
// Find the API Credential record | ||
$findApKey = ApiCredential::on($connection) | ||
->where(function ($query) use ($isSecretKey, $token) { | ||
if ($isSecretKey) { | ||
$query->where('secret', $token); | ||
} else { | ||
$query->where('key', $token); | ||
} | ||
}) | ||
->with(['company.owner']) | ||
->withoutGlobalScopes(); | ||
|
||
// Get the api credential model record | ||
$apiCredential = $findApKey->first(); | ||
|
||
// Handle no api credential found | ||
if (!$apiCredential) { | ||
return response()->error('No API key found to fetch company details with.'); | ||
} | ||
|
||
// Get the organization owning the API key | ||
$organization = Company::where('uuid', $apiCredential->company_uuid)->first(); | ||
|
||
return new Organization($organization); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.