2020-01-03 17:25:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-11-02 13:39:43 +01:00
|
|
|
use Zxing\QrReader;
|
|
|
|
use App\TwoFAccount;
|
2020-01-09 17:32:27 +01:00
|
|
|
use Illuminate\Http\Request;
|
2020-01-03 17:25:56 +01:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2020-11-05 22:47:59 +01:00
|
|
|
use chillerlan\QRCode\{QRCode, QROptions};
|
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
|
|
|
/**
|
|
|
|
* Return a QR code image
|
|
|
|
*
|
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)
|
|
|
|
{
|
2020-11-05 22:47:59 +01:00
|
|
|
|
2020-11-02 13:39:43 +01:00
|
|
|
$options = new QROptions([
|
|
|
|
'quietzoneSize' => 2,
|
|
|
|
'scale' => 8,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$qrcode = new QRCode($options);
|
|
|
|
|
|
|
|
return response()->json(['qrcode' => $qrcode->render($twofaccount->uri)], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function decode(Request $request)
|
|
|
|
{
|
2020-11-20 14:11:32 +01:00
|
|
|
|
|
|
|
// input validation
|
|
|
|
$this->validate($request, [
|
|
|
|
'qrcode' => 'required|image',
|
|
|
|
]);
|
2020-01-03 17:25:56 +01:00
|
|
|
|
2020-11-20 14:11:32 +01:00
|
|
|
// qrcode analysis
|
|
|
|
$path = $request->file('qrcode')->store('qrcodes');
|
|
|
|
$qrcode = new QrReader(storage_path('app/' . $path));
|
2020-11-18 23:48:51 +01:00
|
|
|
|
2020-11-20 14:11:32 +01:00
|
|
|
$uri = urldecode($qrcode->text());
|
2020-11-18 23:48:51 +01:00
|
|
|
|
2020-11-20 14:11:32 +01:00
|
|
|
// delete uploaded file
|
|
|
|
Storage::delete($path);
|
2020-11-18 23:48:51 +01:00
|
|
|
|
2020-11-20 14:11:32 +01:00
|
|
|
return response()->json(['uri' => $uri], 200);
|
2020-01-03 17:25:56 +01:00
|
|
|
}
|
2020-01-09 16:33:32 +01:00
|
|
|
|
2020-01-03 17:25:56 +01:00
|
|
|
}
|