QrCodeController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Api\v1\Controllers;
  3. use App\Models\TwoFAccount;
  4. use App\Services\QrCodeService;
  5. use App\Api\v1\Requests\QrCodeDecodeRequest;
  6. use App\Http\Controllers\Controller;
  7. class QrCodeController extends Controller
  8. {
  9. /**
  10. * The QR code Service instance.
  11. */
  12. protected $qrcodeService;
  13. /**
  14. * Create a new controller instance.
  15. *
  16. * @param \App\Services\QrCodeService $qrcodeService
  17. * @return void
  18. */
  19. public function __construct(QrCodeService $qrcodeService)
  20. {
  21. $this->qrcodeService = $qrcodeService;
  22. }
  23. /**
  24. * Show a QR code image
  25. *
  26. * @param App\Models\TwoFAccount $twofaccount
  27. * @return \Illuminate\Http\JsonResponse
  28. */
  29. public function show(TwoFAccount $twofaccount)
  30. {
  31. $uri = $twofaccount->getURI();
  32. return response()->json(['qrcode' => $this->qrcodeService->encode($uri)], 200);
  33. }
  34. /**
  35. * Decode an uploaded QR Code image
  36. *
  37. * @param \App\Api\v1\Requests\QrCodeDecodeRequest $request
  38. * @return \Illuminate\Http\JsonResponse
  39. */
  40. public function decode(QrCodeDecodeRequest $request)
  41. {
  42. $file = $request->file('qrcode');
  43. return response()->json(['data' => $this->qrcodeService->decode($file)], 200);
  44. }
  45. }