Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/CompanionAppsController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API\V4; | namespace App\Http\Controllers\API\V4; | ||||
use App\Http\Controllers\Controller; | use App\Http\Controllers\Controller; | ||||
use App\Utils; | |||||
use App\Tenant; | |||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Validator; | use Illuminate\Support\Facades\Validator; | ||||
use BaconQrCode; | |||||
class CompanionAppsController extends Controller | class CompanionAppsController extends Controller | ||||
{ | { | ||||
/** | /** | ||||
* Register a companion app. | * Register a companion app. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* | * | ||||
Show All 34 Lines | public function register(Request $request) | ||||
} | } | ||||
} | } | ||||
$app->notification_token = $notificationToken; | $app->notification_token = $notificationToken; | ||||
$app->save(); | $app->save(); | ||||
return response()->json(['status' => 'success']); | return response()->json(['status' => 'success']); | ||||
} | } | ||||
/** | |||||
* Generate a QR-code image for a contact | |||||
* | |||||
* @param array $contact Contact record | |||||
* | |||||
* @return string|null Image content, Null on error or missing PHP extensions | |||||
*/ | |||||
public static function generateQRCode($data) | |||||
{ | |||||
$renderer_style = new BaconQrCode\Renderer\RendererStyle\RendererStyle(300, 1); | |||||
$renderer_image = new BaconQrCode\Renderer\Image\SvgImageBackEnd(); | |||||
$renderer = new BaconQrCode\Renderer\ImageRenderer($renderer_style, $renderer_image); | |||||
$writer = new BaconQrCode\Writer($renderer); | |||||
return 'data:image/svg+xml;base64,' . base64_encode($writer->writeString($data)); | |||||
} | |||||
/** | |||||
* Get the information about the specified companion app. | |||||
* | |||||
* @param int $id The Companion App identifier | |||||
* | |||||
* @return \Illuminate\Http\JsonResponse|void | |||||
*/ | |||||
public function show($id) | |||||
{ | |||||
$user = $this->guard()->user(); | |||||
$response['qrcode'] = self::generateQRCode( | |||||
json_encode([ | |||||
"apiEndpoint" => Utils::serviceUrl('', $user->tenant_id), | |||||
"authorizationEndpoint" => Utils::serviceUrl('/oauth/authorize', $user->tenant_id), | |||||
"tokenEndpoint" => Utils::serviceUrl('/oauth/token', $user->tenant_id), | |||||
"clientIdentifier" => \App\Tenant::getConfig($user->tenant_id, 'app.companion_app_identifier'), | |||||
"clientSecret" => \App\Tenant::getConfig($user->tenant_id, 'app.companion_app_secret'), | |||||
"username" => $user->email | |||||
]) | |||||
); | |||||
machniak: We usually do something like this:
```
return response()->json([
'status' =>… | |||||
return response()->json($response); | |||||
} | |||||
} | } | ||||
Done Inline ActionsThis line should be removed. machniak: This line should be removed. | |||||
Done Inline ActionsIt does not return void. The description also is wrong. machniak: It does not return void. The description also is wrong. |
We usually do something like this: