mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-23 16:53:26 +01:00
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Api\v1\Controllers;
|
|
|
|
use App\Models\TwoFAccount;
|
|
use App\Facades\QrCode;
|
|
use App\Api\v1\Requests\QrCodeDecodeRequest;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
class QrCodeController extends Controller
|
|
{
|
|
|
|
/**
|
|
* Show a QR code image
|
|
*
|
|
* @param \App\Models\TwoFAccount $twofaccount
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function show(TwoFAccount $twofaccount)
|
|
{
|
|
$uri = $twofaccount->getURI();
|
|
|
|
return response()->json(['qrcode' => QrCode::encode($uri)], 200);
|
|
}
|
|
|
|
|
|
/**
|
|
* Decode an uploaded QR Code image
|
|
*
|
|
* @param \App\Api\v1\Requests\QrCodeDecodeRequest $request
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function decode(QrCodeDecodeRequest $request)
|
|
{
|
|
$file = $request->file('qrcode');
|
|
|
|
return $file instanceof \Illuminate\Http\UploadedFile
|
|
? response()->json(['data' => QrCode::decode($file)], 200)
|
|
: response()->json(['message' => __('errors.file_upload_failed')], 500);
|
|
}
|
|
|
|
} |