Ejemplo n.º 1
0
 /**
  * Generates a QrCode
  *
  * @param string $text The text to be converted into a QrCode
  * @param null|string $filename The filename and path to save the QrCode file
  * @return string|void Returns a QrCode string depending on the format, or saves to a file.
  */
 public function generate($text, $filename = null)
 {
     if ($filename === null) {
         return $this->writer->writeString($text, $this->encoding, $this->errorCorrection);
     } else {
         $this->writer->writeFile($text, $filename, $this->encoding, $this->errorCorrection);
     }
 }
Ejemplo n.º 2
0
 public function renderQrCodeAction()
 {
     /** @var AccountInterface $account */
     $account = $this->zourceAccount();
     $oneTimePassword = new TOTP($account->getContact()->getFullName(), $this->tfaService->getSecret());
     $oneTimePassword->setIssuer('Zource');
     $oneTimePassword->setIssuerIncludedAsParameter(true);
     $oneTimePassword->setParameter('image', $this->url()->fromRoute('settings/security/tfa-image', [], ['force_canonical' => true]));
     $filePath = tempnam('data/tmp/', '2fa-qr-');
     $renderer = new Png();
     $renderer->setHeight(256);
     $renderer->setWidth(256);
     $writer = new Writer($renderer);
     $writer->writeFile($oneTimePassword->getProvisioningUri(true), $filePath);
     $response = new Stream();
     $response->setCleanup(true);
     $response->setStream(fopen($filePath, 'rb'));
     $response->setStreamName($filePath);
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Length', filesize($filePath));
     $headers->addHeaderLine('Content-Type', 'image/png');
     return $response;
 }