2020-01-03 17:25:56 +01:00
|
|
|
<?php
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
namespace App\Api\v1\Controllers;
|
2020-01-03 17:25:56 +01:00
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
use App\Models\TwoFAccount;
|
2022-07-30 10:46:02 +02:00
|
|
|
use App\Facades\QrCode;
|
2021-11-07 21:57:22 +01:00
|
|
|
use App\Api\v1\Requests\QrCodeDecodeRequest;
|
|
|
|
use App\Http\Controllers\Controller;
|
2021-09-07 23:01:53 +02:00
|
|
|
|
2020-01-03 17:25:56 +01:00
|
|
|
|
2020-10-11 19:14:56 +02:00
|
|
|
class QrCodeController extends Controller
|
2020-01-03 17:25:56 +01:00
|
|
|
{
|
2021-09-07 23:01:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a QR code image
|
2020-11-02 13:39:43 +01:00
|
|
|
*
|
2022-08-26 15:57:18 +02:00
|
|
|
* @param \App\Models\TwoFAccount $twofaccount
|
2021-11-26 11:18:58 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-11-02 13:39:43 +01:00
|
|
|
*/
|
|
|
|
public function show(TwoFAccount $twofaccount)
|
|
|
|
{
|
2022-07-05 10:10:24 +02:00
|
|
|
$uri = $twofaccount->getURI();
|
2020-11-05 22:47:59 +01:00
|
|
|
|
2022-07-30 10:46:02 +02:00
|
|
|
return response()->json(['qrcode' => QrCode::encode($uri)], 200);
|
2020-11-02 13:39:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-03 17:25:56 +01:00
|
|
|
/**
|
2020-11-13 14:52:24 +01:00
|
|
|
* Decode an uploaded QR Code image
|
2020-01-03 17:25:56 +01:00
|
|
|
*
|
2021-11-26 11:18:58 +01:00
|
|
|
* @param \App\Api\v1\Requests\QrCodeDecodeRequest $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-01-03 17:25:56 +01:00
|
|
|
*/
|
2021-09-07 23:01:53 +02:00
|
|
|
public function decode(QrCodeDecodeRequest $request)
|
2020-01-03 17:25:56 +01:00
|
|
|
{
|
2021-09-07 23:01:53 +02:00
|
|
|
$file = $request->file('qrcode');
|
2020-11-18 23:48:51 +01:00
|
|
|
|
2022-09-02 14:28:57 +02:00
|
|
|
return $file instanceof \Illuminate\Http\UploadedFile
|
|
|
|
? response()->json(['data' => QrCode::decode($file)], 200)
|
|
|
|
: response()->json(['message' => __('errors.file_upload_failed')], 500);
|
2020-01-03 17:25:56 +01:00
|
|
|
}
|
2020-01-09 16:33:32 +01:00
|
|
|
|
2021-09-07 23:01:53 +02:00
|
|
|
}
|