2020-01-03 17:25:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-11-02 13:39:43 +01:00
|
|
|
use App\TwoFAccount;
|
2021-09-07 23:01:53 +02:00
|
|
|
use App\Services\QrCodeService;
|
2021-09-18 00:00:39 +02:00
|
|
|
use App\Services\TwoFAccountService;
|
2021-09-07 23:01:53 +02:00
|
|
|
use App\Http\Requests\QrCodeDecodeRequest;
|
|
|
|
|
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
|
|
|
{
|
2020-11-02 13:39:43 +01:00
|
|
|
/**
|
2021-09-18 00:00:39 +02:00
|
|
|
* The QR code Service instance.
|
2021-09-07 23:01:53 +02:00
|
|
|
*/
|
|
|
|
protected $qrcodeService;
|
|
|
|
|
2021-09-18 00:00:39 +02:00
|
|
|
/**
|
|
|
|
* The TwoFAccount Service instance.
|
|
|
|
*/
|
|
|
|
protected $twofaccountService;
|
|
|
|
|
2021-09-07 23:01:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
2021-09-22 22:59:56 +02:00
|
|
|
* @param \App\Services\QrCodeService $qrcodeService
|
|
|
|
* @param \App\Services\TwoFAccountService $twofaccountService
|
2021-09-07 23:01:53 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-09-18 00:00:39 +02:00
|
|
|
public function __construct(QrCodeService $qrcodeService, TwoFAccountService $twofaccountService)
|
2021-09-07 23:01:53 +02:00
|
|
|
{
|
|
|
|
$this->qrcodeService = $qrcodeService;
|
2021-09-18 00:00:39 +02:00
|
|
|
$this->twofaccountService = $twofaccountService;
|
2021-09-07 23:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a QR code image
|
2020-11-02 13:39:43 +01:00
|
|
|
*
|
2020-11-05 22:47:59 +01:00
|
|
|
* @param App\TwoFAccount $twofaccount
|
2020-11-02 13:39:43 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show(TwoFAccount $twofaccount)
|
|
|
|
{
|
2021-09-18 00:00:39 +02:00
|
|
|
$uri = $this->twofaccountService->getURI($twofaccount);
|
2020-11-05 22:47:59 +01:00
|
|
|
|
2021-09-18 00:00:39 +02:00
|
|
|
return response()->json(['qrcode' => $this->qrcodeService->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-09-07 23:01:53 +02:00
|
|
|
* @param \App\Http\Requests\QrCodeDecodeRequest $request
|
2020-01-03 17:25:56 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
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
|
|
|
|
2021-09-07 23:01:53 +02:00
|
|
|
return response()->json(['data' => $this->qrcodeService->decode($file)], 200);
|
2020-01-03 17:25:56 +01:00
|
|
|
}
|
2020-01-09 16:33:32 +01:00
|
|
|
|
2021-09-07 23:01:53 +02:00
|
|
|
}
|