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

65 lines
1.5 KiB
PHP
Raw Normal View History

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