2FAuth/app/Api/v1/Controllers/QrCodeController.php

40 lines
984 B
PHP
Raw Normal View History

2020-01-03 17:25:56 +01:00
<?php
namespace App\Api\v1\Controllers;
2020-01-03 17:25:56 +01:00
use App\Api\v1\Requests\QrCodeDecodeRequest;
2022-11-22 15:15:52 +01:00
use App\Facades\QrCode;
use App\Http\Controllers\Controller;
2022-11-22 15:15:52 +01:00
use App\Models\TwoFAccount;
2020-01-03 17:25:56 +01:00
class QrCodeController extends Controller
2020-01-03 17:25:56 +01:00
{
/**
* Show a QR code image
*
2021-11-26 11:18:58 +01:00
* @return \Illuminate\Http\JsonResponse
*/
public function show(TwoFAccount $twofaccount)
{
$this->authorize('view', $twofaccount);
$uri = $twofaccount->getURI();
2020-11-05 22:47:59 +01:00
return response()->json(['qrcode' => QrCode::encode($uri)], 200);
}
2020-01-03 17:25:56 +01:00
/**
* Decode an uploaded QR Code image
2020-01-03 17:25:56 +01:00
*
2021-11-26 11:18:58 +01:00
* @return \Illuminate\Http\JsonResponse
2020-01-03 17:25:56 +01:00
*/
public function decode(QrCodeDecodeRequest $request)
2020-01-03 17:25:56 +01:00
{
$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);
2020-01-03 17:25:56 +01:00
}
2022-11-22 15:15:52 +01:00
}