From 4bd0ae6c6dd0a5b2d86c6921d849c3370050b7dc Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Tue, 19 Mar 2019 11:58:39 +0200 Subject: [PATCH] generate qr code here --- .gitignore | 4 + composer.json | 4 +- composer.lock | 355 +++++++++++++++++- config/bundles.php | 1 + src/Controller/Api/BuildsController.php | 7 +- src/Controller/Web/BuildsController.php | 42 ++- src/Controller/Web/ProjectsController.php | 4 +- symfony.lock | 27 ++ templates/{Builds => builds}/index.html.twig | 0 .../{Builds => builds}/install.html.twig | 0 .../{Projects => projects}/index.html.twig | 0 .../{Projects => projects}/login.html.twig | 0 12 files changed, 420 insertions(+), 24 deletions(-) rename templates/{Builds => builds}/index.html.twig (100%) rename templates/{Builds => builds}/install.html.twig (100%) rename templates/{Projects => projects}/index.html.twig (100%) rename templates/{Projects => projects}/login.html.twig (100%) diff --git a/.gitignore b/.gitignore index 3fc274a..59a7168 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,7 @@ yarn-error.log /phpunit.xml /.phpunit.result.cache ###< phpunit/phpunit ### + +###> symfony/web-server-bundle ### +/.web-server-pid +###< symfony/web-server-bundle ### diff --git a/composer.json b/composer.json index 54ff049..08c01f8 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "ext-zip": "*", "aws/aws-sdk-php": "^3.87", "ekreative/redmine_login": "^3.8", + "endroid/qr-code": "^3.5", "guzzlehttp/guzzle": "^6.3", "rodneyrehm/plist": "^2.0", "sensio/framework-extra-bundle": "^5.2", @@ -82,6 +83,7 @@ "phpunit/phpunit": "^8.0", "symfony/dotenv": "4.2.*", "symfony/maker-bundle": "^1.11", - "symfony/profiler-pack": "^1.0" + "symfony/profiler-pack": "^1.0", + "symfony/web-server-bundle": "4.2.*" } } diff --git a/composer.lock b/composer.lock index fab6a8a..134c559 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2b3ab7059a62cd3a8552d232463bfaae", + "content-hash": "9fcbf68f68b8b868906d718de7296387", "packages": [ { "name": "aws/aws-sdk-php", @@ -88,6 +88,97 @@ ], "time": "2019-03-18T18:09:25+00:00" }, + { + "name": "bacon/bacon-qr-code", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/Bacon/BaconQrCode.git", + "reference": "eaac909da3ccc32b748a65b127acd8918f58d9b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/eaac909da3ccc32b748a65b127acd8918f58d9b0", + "reference": "eaac909da3ccc32b748a65b127acd8918f58d9b0", + "shasum": "" + }, + "require": { + "dasprid/enum": "^1.0", + "ext-iconv": "*", + "php": "^7.1" + }, + "require-dev": { + "phly/keep-a-changelog": "^1.4", + "phpunit/phpunit": "^6.4", + "squizlabs/php_codesniffer": "^3.1" + }, + "suggest": { + "ext-imagick": "to generate QR code images" + }, + "type": "library", + "autoload": { + "psr-4": { + "BaconQrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "http://www.dasprids.de", + "role": "Developer" + } + ], + "description": "BaconQrCode is a QR code generator for PHP.", + "homepage": "https://github.com/Bacon/BaconQrCode", + "time": "2018-04-25T17:53:56+00:00" + }, + { + "name": "dasprid/enum", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/DASPRiD/Enum.git", + "reference": "631ef6e638e9494b0310837fa531bedd908fc22b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/631ef6e638e9494b0310837fa531bedd908fc22b", + "reference": "631ef6e638e9494b0310837fa531bedd908fc22b", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^6.4", + "squizlabs/php_codesniffer": "^3.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DASPRiD\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/" + } + ], + "description": "PHP 7.1 enum implementation", + "keywords": [ + "enum", + "map" + ], + "time": "2017-10-25T22:45:27+00:00" + }, { "name": "doctrine/annotations", "version": "v1.6.0", @@ -771,6 +862,114 @@ "description": "Login to symfony using redmine as user provider", "time": "2019-02-04T14:25:47+00:00" }, + { + "name": "endroid/installer", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/endroid/installer.git", + "reference": "b41b44ae2e410609be3b7f080b626dfc9ff4822a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/endroid/installer/zipball/b41b44ae2e410609be3b7f080b626dfc9ff4822a", + "reference": "b41b44ae2e410609be3b7f080b626dfc9ff4822a", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1", + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.7|^6.0" + }, + "type": "composer-plugin", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "class": "Endroid\\Installer\\Installer" + }, + "autoload": { + "psr-4": { + "Endroid\\Installer\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeroen van den Enden", + "email": "info@endroid.nl" + } + ], + "time": "2018-11-30T13:00:41+00:00" + }, + { + "name": "endroid/qr-code", + "version": "3.5.6", + "source": { + "type": "git", + "url": "https://github.com/endroid/qr-code.git", + "reference": "9cc1eaecb9bc670bba82f27b8dfccd4cbed2df2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/endroid/qr-code/zipball/9cc1eaecb9bc670bba82f27b8dfccd4cbed2df2f", + "reference": "9cc1eaecb9bc670bba82f27b8dfccd4cbed2df2f", + "shasum": "" + }, + "require": { + "bacon/bacon-qr-code": "^2.0", + "endroid/installer": "^1.0.3", + "ext-gd": "*", + "khanamiryan/qrcode-detector-decoder": "^1.0.2", + "myclabs/php-enum": "^1.5", + "php": ">=7.1", + "symfony/options-resolver": "^2.7|^3.0|^4.0", + "symfony/property-access": "^2.7|^3.0|^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7|^6.0" + }, + "suggest": { + "symfony/http-foundation": "Install if you want to use QrCodeResponse" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Endroid\\QrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeroen van den Enden", + "email": "info@endroid.nl" + } + ], + "description": "Endroid QR Code", + "homepage": "https://github.com/endroid/qr-code", + "keywords": [ + "bundle", + "code", + "endroid", + "php", + "qr", + "qrcode" + ], + "time": "2019-03-03T08:34:10+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.3.3", @@ -954,6 +1153,56 @@ ], "time": "2018-12-04T20:46:45+00:00" }, + { + "name": "khanamiryan/qrcode-detector-decoder", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/khanamiryan/php-qrcode-detector-decoder.git", + "reference": "a75482d3bc804e3f6702332bfda6cccbb0dfaa76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/khanamiryan/php-qrcode-detector-decoder/zipball/a75482d3bc804e3f6702332bfda6cccbb0dfaa76", + "reference": "a75482d3bc804e3f6702332bfda6cccbb0dfaa76", + "shasum": "" + }, + "require": { + "php": "^5.6|^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "Zxing\\": "lib/" + }, + "files": [ + "lib/Common/customFunctions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ashot Khanamiryan", + "email": "a.khanamiryan@gmail.com", + "homepage": "https://github.com/khanamiryan", + "role": "Developer" + } + ], + "description": "QR code decoder / reader", + "homepage": "https://github.com/khanamiryan/php-qrcode-detector-decoder/", + "keywords": [ + "barcode", + "qr", + "zxing" + ], + "time": "2018-04-26T11:41:33+00:00" + }, { "name": "mcfedr/json-form", "version": "4.4.0", @@ -1138,6 +1387,51 @@ ], "time": "2016-12-03T22:08:25+00:00" }, + { + "name": "myclabs/php-enum", + "version": "1.6.6", + "source": { + "type": "git", + "url": "https://github.com/myclabs/php-enum.git", + "reference": "32c4202886c51fbe5cc3a7c34ec5c9a4a790345e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/php-enum/zipball/32c4202886c51fbe5cc3a7c34ec5c9a4a790345e", + "reference": "32c4202886c51fbe5cc3a7c34ec5c9a4a790345e", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35|^5.7|^6.0", + "squizlabs/php_codesniffer": "1.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MyCLabs\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP Enum contributors", + "homepage": "https://github.com/myclabs/php-enum/graphs/contributors" + } + ], + "description": "PHP Enum implementation", + "homepage": "http://github.com/myclabs/php-enum", + "keywords": [ + "enum" + ], + "time": "2019-02-04T21:18:49+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -6909,6 +7203,65 @@ "homepage": "https://symfony.com", "time": "2019-02-28T14:59:23+00:00" }, + { + "name": "symfony/web-server-bundle", + "version": "v4.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/web-server-bundle.git", + "reference": "d189cb4349d807df4c4fab932e2764d1fbe65c4f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/web-server-bundle/zipball/d189cb4349d807df4c4fab932e2764d1fbe65c4f", + "reference": "d189cb4349d807df4c4fab932e2764d1fbe65c4f", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/config": "~3.4|~4.0", + "symfony/console": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/http-kernel": "~3.4|~4.0", + "symfony/polyfill-ctype": "~1.8", + "symfony/process": "^3.4.2|^4.0.2" + }, + "suggest": { + "symfony/expression-language": "For using the filter option of the log server.", + "symfony/monolog-bridge": "For using the log server." + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\WebServerBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony WebServerBundle", + "homepage": "https://symfony.com", + "time": "2019-02-23T15:17:42+00:00" + }, { "name": "theseer/tokenizer", "version": "1.1.0", diff --git a/config/bundles.php b/config/bundles.php index 89442d6..41e2f29 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -14,4 +14,5 @@ Mcfedr\JsonFormBundle\McfedrJsonFormBundle::class => ['all' => true], Ekreative\RedmineLoginBundle\EkreativeRedmineLoginBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true], ]; diff --git a/src/Controller/Api/BuildsController.php b/src/Controller/Api/BuildsController.php index 357656b..9a4dec2 100644 --- a/src/Controller/Api/BuildsController.php +++ b/src/Controller/Api/BuildsController.php @@ -10,9 +10,6 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -/** - * @Route("/api/builds") - */ class BuildsController extends AbstractController { /** @@ -38,7 +35,7 @@ public function __construct(BuildsUploader $buildUploader, AppDataManager $appDa } /** - * @Route("/{project}/{type}", methods={"GET"}, name="jenkins_projects") + * @Route("/api/builds/{project}/{type}", methods={"GET"}, name="jenkins_projects") */ public function builds(Request $request, $project, $type = null) { @@ -48,7 +45,7 @@ public function builds(Request $request, $project, $type = null) } /** - * @Route("/upload/{project}/{type}", name="jenkins_url", methods={"POST"}) + * @Route("/api/builds/upload/{project}/{type}", name="jenkins_url", methods={"POST"}) */ public function upload(Request $request, $project, $type) { diff --git a/src/Controller/Web/BuildsController.php b/src/Controller/Web/BuildsController.php index ae891c2..4cfbdc0 100644 --- a/src/Controller/Web/BuildsController.php +++ b/src/Controller/Web/BuildsController.php @@ -10,6 +10,7 @@ use App\Services\AppDataManager; use App\Services\BuildsUploader; use Ekreative\RedmineLoginBundle\Client\ClientProvider; +use Endroid\QrCode\Response\QrCodeResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -17,10 +18,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Endroid\QrCode\QrCode; -/** - * @Route("/web/builds") - */ class BuildsController extends AbstractController { /** @@ -60,7 +59,7 @@ public function __construct(ClientProvider $loginProvider, S3 $s3Service, Builds } /** - * @Route("/show/{projectSlug}/{type}", name="project_builds", defaults={"type": null}) + * @Route("/web/builds/show/{projectSlug}/{type}", name="project_builds", defaults={"type": null}) * * @param Request $request * @param $projectSlug @@ -103,7 +102,7 @@ public function index(Request $request, $projectSlug, $type) return $this->redirectToRoute('project_builds', ['projectSlug' => $projectSlug, 'type' => $search->getType()]); } - return $this->render('Builds/index.html.twig', [ + return $this->render('builds/index.html.twig', [ 'slug' => $projectSlug, 'form' => $form->createView(), 'searchForm' => $searchForm->createView(), @@ -148,7 +147,7 @@ private function getProjectIdAndPermissions($projectSlug) } /** - * @Route("/install/{token}", name="build_install") + * @Route("/web/builds/install/{token}", name="build_install") */ public function install($token) { @@ -166,7 +165,7 @@ public function install($token) } /** - * @Route("/install/{platform}/{token}", name="build_install_platform") + * @Route("/web/builds/install/{platform}/{token}", name="build_install_platform") */ public function installPlatform($token) { @@ -184,7 +183,7 @@ public function installPlatform($token) } /** - * @Route("/installByCommit/{commit}/{jobName}", name="build_commit", requirements={"commit"="^[0-9a-f]{40}$", "jobName"="^[0-9a-z-_]+$"}, defaults={"jobName"=null}) + * @Route("/web/builds/installByCommit/{commit}/{jobName}", name="build_commit", requirements={"commit"="^[0-9a-f]{40}$", "jobName"="^[0-9a-z-_]+$"}, defaults={"jobName"=null}) */ public function commit($commit, $jobName = null) { @@ -203,7 +202,7 @@ public function commit($commit, $jobName = null) } /** - * @Route("/latest/{projectSlug}/{type}/{ref}/{jobName}", name="build_latest", requirements={"type"="^ios|android|exe$", "ref"="^[0-9a-z-]+$", "jobName"="^[0-9a-z-_]+$"}, defaults={"jobName"=null}) + * @Route("/web/builds/latest/{projectSlug}/{type}/{ref}/{jobName}", name="build_latest", requirements={"type"="^ios|android|exe$", "ref"="^[0-9a-z-]+$", "jobName"="^[0-9a-z-_]+$"}, defaults={"jobName"=null}) */ public function latest($projectSlug, $type, $ref, $jobName = null) { @@ -240,19 +239,32 @@ private function renderApp(App $app) 'token' => $app->getToken(), 'platform' => $app->getType(), ], UrlGeneratorInterface::ABSOLUTE_URL); - $qrcode = 'https://chart.apis.google.com/chart?chl=' . urlencode($install) . '&chs=200x200&choe=UTF-8&cht=qr&chld=L%7C2'; - return $this->render('Builds/install.html.twig', [ + return $this->render('builds/install.html.twig', [ 'app' => $app, 'url' => $url, 'buildUrl' => $app->getBuildUrl(), - 'qrcode' => $qrcode, + 'qrcode' => $this->generateUrl('build_install_qr', ['token' => $app->getToken()]), 'install' => $install, ]); } /** - * @Route("/release/{token}", name="build_inverse_release", methods={"GET"}) + * @Route("/web/builds/qr/{token}", name="build_install_qr") + */ + public function appQr($token) + { + $install = $this->generateUrl('build_install', [ + 'token' => $token, + ], UrlGeneratorInterface::ABSOLUTE_URL); + + $qr = new QrCode($install); + $qr->setSize(150); + return new QrCodeResponse($qr); + } + + /** + * @Route("/web/builds/release/{token}", name="build_inverse_release", methods={"GET"}) */ public function release($token) { @@ -275,7 +287,7 @@ public function release($token) } /** - * @Route("/delete/{project}/{type}/{token}", name="build_delete", methods={"POST"}) + * @Route("/web/builds/delete/{project}/{type}/{token}", name="build_delete", methods={"POST"}) */ public function delete($project, $type, $token) { @@ -298,7 +310,7 @@ public function delete($project, $type, $token) } /** - * @Route("/upload/{project}/{type}", name="upload", methods={"POST"}) + * @Route("/web/builds/upload/{project}/{type}", name="upload", methods={"POST"}) * * @throws \Exception */ diff --git a/src/Controller/Web/ProjectsController.php b/src/Controller/Web/ProjectsController.php index cacf561..f90716d 100644 --- a/src/Controller/Web/ProjectsController.php +++ b/src/Controller/Web/ProjectsController.php @@ -54,7 +54,7 @@ public function index(Request $request, $page) $pages = ceil($projectsData['total_count'] / $projectsData['limit']); - return $this->render('Projects/index.html.twig', [ + return $this->render('projects/index.html.twig', [ 'searchForm' => $form->createView(), 'pages' => $pages, 'page' => $page, @@ -89,7 +89,7 @@ public function login(Request $request) $session->remove(Security::AUTHENTICATION_ERROR); } - return $this->render('Projects/login.html.twig', [ + return $this->render('projects/login.html.twig', [ 'last_username' => $session->get(Security::LAST_USERNAME), 'error' => $error, 'form' => $form->createView() diff --git a/symfony.lock b/symfony.lock index 45c953d..b895e48 100644 --- a/symfony.lock +++ b/symfony.lock @@ -2,12 +2,18 @@ "aws/aws-sdk-php": { "version": "3.87.2" }, + "bacon/bacon-qr-code": { + "version": "2.0.0" + }, "composer/semver": { "version": "1.4.2" }, "composer/xdebug-handler": { "version": "1.3.2" }, + "dasprid/enum": { + "version": "1.0.0" + }, "doctrine/annotations": { "version": "1.0", "recipe": { @@ -74,6 +80,12 @@ "ekreative/redmine_login": { "version": "3.8.2" }, + "endroid/installer": { + "version": "1.0.8" + }, + "endroid/qr-code": { + "version": "3.5.6" + }, "friendsofphp/php-cs-fixer": { "version": "2.2", "recipe": { @@ -98,6 +110,9 @@ "jdorn/sql-formatter": { "version": "v1.2.17" }, + "khanamiryan/qrcode-detector-decoder": { + "version": "1.0.2" + }, "mcfedr/json-form": { "version": "4.4.0" }, @@ -110,6 +125,9 @@ "myclabs/deep-copy": { "version": "1.8.1" }, + "myclabs/php-enum": { + "version": "1.6.6" + }, "nikic/php-parser": { "version": "v4.2.0" }, @@ -431,6 +449,15 @@ "ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6" } }, + "symfony/web-server-bundle": { + "version": "3.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "3.3", + "ref": "dae9b39fd6717970be7601101ce5aa960bf53d9a" + } + }, "symfony/webpack-encore-bundle": { "version": "1.0", "recipe": { diff --git a/templates/Builds/index.html.twig b/templates/builds/index.html.twig similarity index 100% rename from templates/Builds/index.html.twig rename to templates/builds/index.html.twig diff --git a/templates/Builds/install.html.twig b/templates/builds/install.html.twig similarity index 100% rename from templates/Builds/install.html.twig rename to templates/builds/install.html.twig diff --git a/templates/Projects/index.html.twig b/templates/projects/index.html.twig similarity index 100% rename from templates/Projects/index.html.twig rename to templates/projects/index.html.twig diff --git a/templates/Projects/login.html.twig b/templates/projects/login.html.twig similarity index 100% rename from templates/Projects/login.html.twig rename to templates/projects/login.html.twig