QrCodeController.php 1.5 KB

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