From c4438f7e8c1f4f7388a1038f6f17c9fb3ade6bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danyi=20D=C3=A1vid?= Date: Sun, 13 May 2018 22:34:15 +0200 Subject: [PATCH] * image upload handling * old static image migrator implementation as cli command * auth id fix, renew works now * templates refactored to work with uploaded images --- config/autoload/auth.global.php | 4 + config/routes.php | 21 +++-- public/styles/main.css | 2 + src/App/Command/MigrateImages.php | 66 +++++++++++++++ src/App/Command/MigrateImagesFactory.php | 21 +++++ src/App/ConfigProvider.php | 14 ++++ src/App/Entity/Awardee.php | 51 +++++++++++- src/App/Entity/Judge.php | 23 ++++++ src/App/Handler/Api/AwardeeImageHandler.php | 68 ++++++++++++++++ .../Api/AwardeeImageHandlerFactory.php | 18 +++++ src/App/Handler/Api/JudgeImageHandler.php | 65 +++++++++++++++ .../Handler/Api/JudgeImageHandlerFactory.php | 18 +++++ src/App/Service/AwardeeManager.php | 80 ++++++++++++++++++- src/App/Service/JudgeManager.php | 79 ++++++++++++++++-- src/UtilityModule/Handler/AuthHandler.php | 2 +- .../Middleware/JwtMiddlewareFactory.php | 5 ++ src/UtilityModule/Service/AuthService.php | 3 +- templates/app/awardees.phtml | 2 +- templates/app/judges.inc.phtml | 6 +- templates/app/profile.phtml | 4 +- 20 files changed, 532 insertions(+), 20 deletions(-) create mode 100644 src/App/Command/MigrateImages.php create mode 100644 src/App/Command/MigrateImagesFactory.php create mode 100644 src/App/Handler/Api/AwardeeImageHandler.php create mode 100644 src/App/Handler/Api/AwardeeImageHandlerFactory.php create mode 100644 src/App/Handler/Api/JudgeImageHandler.php create mode 100644 src/App/Handler/Api/JudgeImageHandlerFactory.php diff --git a/config/autoload/auth.global.php b/config/autoload/auth.global.php index 8eaa66b..aee107e 100644 --- a/config/autoload/auth.global.php +++ b/config/autoload/auth.global.php @@ -8,5 +8,9 @@ return [ 'api.auth.login', 'api.ping', ], + 'unguarded_paths' => [ + '/api/awardee-image', + '/api/judge-image', + ], ], ]; diff --git a/config/routes.php b/config/routes.php index c5a33f2..731e20b 100644 --- a/config/routes.php +++ b/config/routes.php @@ -44,10 +44,22 @@ return function (Application $app, MiddlewareFactory $factory, ContainerInterfac 'api.judges' ); $app->route( - '/api/awardee[/{id:\d+}]', - App\Handler\Api\AwardeeHandler::class, - ['GET','POST','PUT','DELETE'], - 'api.awardees' + '/api/awardee[/{id:\d+}]', + App\Handler\Api\AwardeeHandler::class, + ['GET','POST','PUT','DELETE'], + 'api.awardees' + ); + $app->route( + '/api/judge-image/{slug}', + App\Handler\Api\JudgeImageHandler::class, + ['GET','POST','DELETE'], + 'api.judge-image' + ); + $app->route( + '/api/awardee-image/{type:profile|award}/{slug}', + App\Handler\Api\AwardeeImageHandler::class, + ['GET','POST','DELETE'], + 'api.awardee-image' ); $app->get('/the-prize', App\Handler\PrizeRedirectHandler::class, 'the-prize'); @@ -57,7 +69,6 @@ return function (Application $app, MiddlewareFactory $factory, ContainerInterfac 'the-prize.article' ); -// $app->get('/judges', App\Handler\JudgesHandler::class, 'judges'); $app->get('/awards', App\Handler\AwardeeRedirectHandler::class, 'awardees'); $app->get('/awards/{year:\d+}', App\Handler\AwardeeHandler::class, 'awardees-by-year'); $app->get('/awardee/{slug}', App\Handler\ProfileHandler::class, 'awardee'); diff --git a/public/styles/main.css b/public/styles/main.css index a3f550c..d9e21a0 100644 --- a/public/styles/main.css +++ b/public/styles/main.css @@ -504,10 +504,12 @@ section.awardee { "content content"; } +section.awardee ol, section.awardee ul { padding-left: 1.5em; } +section.awardee ol > li, section.awardee ul > li { margin-bottom: 10px; } diff --git a/src/App/Command/MigrateImages.php b/src/App/Command/MigrateImages.php new file mode 100644 index 0000000..1d621e1 --- /dev/null +++ b/src/App/Command/MigrateImages.php @@ -0,0 +1,66 @@ +awardeeManager = $awardeeManager; + $this->judgeManager = $judgeManager; + parent::__construct(); + } + + protected function configure() + { + $this->setName('image:migrate') + ->setDescription('Migrate images from old format to new'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->write("Migrating awardee images ..."); + $awardees = $this->awardeeManager->getAwardees(); + $this->awardeeManager->ensureImageDirectoryExists(); + foreach ($awardees as $awardee) { + if ($awardee->hasLegacyProfileImage() && !$awardee->hasProfileImage()) { + link( + sprintf('public/img/awardees/%s.jpg', $awardee->getSlug()), + sprintf('%s/%s-profile.jpg',AwardeeManager::IMAGE_DIRECTORY, $awardee->getId()) + ); + } + if ($awardee->hasLegacyAwardImage() && !$awardee->hasAwardImage()) { + link( + sprintf('public/img/awardees/%s-atadas.jpg', $awardee->getSlug()), + sprintf('%s/%s-award.jpg',AwardeeManager::IMAGE_DIRECTORY, $awardee->getId()) + ); + } + } + $output->writeln("done."); + + $output->write("Migrating judge images ..."); + $judges = $this->judgeManager->getJudges(); + $this->judgeManager->ensureImageDirectoryExists(); + foreach ($judges as $judge) { + if ($judge->hasLegacyProfileImage() && !$judge->hasProfileImage()) { + link( + sprintf('public/img/judges/%s.jpg', $judge->getSlug()), + sprintf('%s/%s.jpg',JudgeManager::IMAGE_DIRECTORY, $judge->getId()) + ); + } + } + $output->writeln("done."); + } +} diff --git a/src/App/Command/MigrateImagesFactory.php b/src/App/Command/MigrateImagesFactory.php new file mode 100644 index 0000000..9a4a066 --- /dev/null +++ b/src/App/Command/MigrateImagesFactory.php @@ -0,0 +1,21 @@ +get(AwardeeManager::class); + $judgeManager = $container->get(JudgeManager::class); + return new MigrateImages($awardeeManager, $judgeManager); + } +} diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index c63c9c0..a6ce62a 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -23,6 +23,7 @@ class ConfigProvider return [ 'dependencies' => $this->getDependencies(), 'templates' => $this->getTemplates(), + 'console' => $this->getConsoleCommands(), ]; } @@ -36,6 +37,8 @@ class ConfigProvider Handler\PingHandler::class => Handler\PingHandler::class, ], 'factories' => [ + Command\MigrateImages::class => Command\MigrateImagesFactory::class, + Handler\HomePageHandler::class => Handler\HomePageHandlerFactory::class, Handler\ArticleHandler::class => Handler\ArticleHandlerFactory::class, Handler\AwardeeHandler::class => Handler\AwardeeHandlerFactory::class, @@ -45,7 +48,9 @@ class ConfigProvider Handler\PrizeRedirectHandler::class => Handler\PrizeRedirectHandlerFactory::class, Handler\Api\AwardeeHandler::class => Handler\Api\AwardeeHandlerFactory::class, + Handler\Api\AwardeeImageHandler::class => Handler\Api\AwardeeImageHandlerFactory::class, Handler\Api\JudgesHandler::class => Handler\Api\JudgesHandlerFactory::class, + Handler\Api\JudgeImageHandler::class => Handler\Api\JudgeImageHandlerFactory::class, Handler\Api\YearsHandler::class => Handler\Api\YearsHandlerFactory::class, Plates\StringExtension::class => Plates\StringExtensionFactory::class, @@ -71,4 +76,13 @@ class ConfigProvider ], ]; } + + public function getConsoleCommands(): array + { + return [ + 'commands' => [ + Command\MigrateImages::class, + ] + ]; + } } diff --git a/src/App/Entity/Awardee.php b/src/App/Entity/Awardee.php index 65677f9..0053ae6 100644 --- a/src/App/Entity/Awardee.php +++ b/src/App/Entity/Awardee.php @@ -3,6 +3,7 @@ namespace App\Entity; +use App\Service\AwardeeManager; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use JsonSerializable; @@ -15,6 +16,7 @@ use JsonSerializable; * @ORM\Index(name="a_name_idx", columns={"name"}) * } * ) + * @ORM\HasLifecycleCallbacks */ class Awardee implements JsonSerializable { @@ -45,7 +47,7 @@ class Awardee implements JsonSerializable private $text; /** - * @ORM\Column(name="image_label", type="string", length=255, unique=true) + * @ORM\Column(name="image_label", type="string", length=255) * @var string */ private $imageLabel; @@ -165,6 +167,51 @@ class Awardee implements JsonSerializable return $this; } + /** + * @return bool + */ + public function hasProfileImage(): bool + { + return file_exists(sprintf('%s/%s-profile.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId())); + } + + /** + * @return bool + */ + public function hasLegacyProfileImage(): bool + { + return file_exists(sprintf('public/img/awardees/%s.jpg', $this->getSlug())); + } + + /** + * @return bool + */ + public function hasAwardImage(): bool + { + return file_exists(sprintf('%s/%s-award.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId())); + } + + /** + * @return bool + */ + public function hasLegacyAwardImage(): bool + { + return file_exists(sprintf('public/img/awardees/%s-atadas.jpg', $this->getSlug())); + } + + /** + * @ORM\PreRemove + */ + public function cleanUpImagesBeforeDelete() + { + if ($this->hasProfileImage()) { + unlink(sprintf('%s/%s-profile.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId())); + } + if ($this->hasAwardImage()) { + unlink(sprintf('%s/%s-award.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId())); + } + } + /** * @return array */ @@ -177,6 +224,8 @@ class Awardee implements JsonSerializable 'text' => $this->getText(), 'imageLabel' => $this->getImageLabel(), 'slug' => $this->getSlug(), + 'hasProfileImage' => $this->hasProfileImage(), + 'hasAwardImage' => $this->hasAwardImage(), ]; } } diff --git a/src/App/Entity/Judge.php b/src/App/Entity/Judge.php index 468b327..dcd2dcf 100644 --- a/src/App/Entity/Judge.php +++ b/src/App/Entity/Judge.php @@ -3,6 +3,7 @@ namespace App\Entity; +use App\Service\JudgeManager; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -17,6 +18,7 @@ use JsonSerializable; * @ORM\Index(name="j_name_idx", columns={"name"}) * } * ) + * @ORM\HasLifecycleCallbacks */ class Judge implements JsonSerializable { @@ -198,6 +200,26 @@ class Judge implements JsonSerializable return $this; } + public function hasProfileImage(): bool + { + return file_exists(sprintf('%s/%s.jpg', JudgeManager::IMAGE_DIRECTORY, $this->getId())); + } + + public function hasLegacyProfileImage(): bool + { + return file_exists(sprintf('public/img/judges/%s.jpg', $this->getSlug())); + } + + /** + * @ORM\PreRemove + */ + public function cleanUpImagesBeforeDelete() + { + if ($this->hasProfileImage()) { + unlink(sprintf('%s/%s.jpg', JudgeManager::IMAGE_DIRECTORY, $this->getId())); + } + } + /** * @return array */ @@ -209,6 +231,7 @@ class Judge implements JsonSerializable 'prefix' => $this->getPrefix(), 'titles' => $this->getTitles()->getValues(), 'slug' => $this->getSlug(), + 'hasProfileImage' => $this->hasProfileImage(), ]; } } diff --git a/src/App/Handler/Api/AwardeeImageHandler.php b/src/App/Handler/Api/AwardeeImageHandler.php new file mode 100644 index 0000000..9d85b0c --- /dev/null +++ b/src/App/Handler/Api/AwardeeImageHandler.php @@ -0,0 +1,68 @@ +awardeeManager = $awardeeManager; + } + + /** + * @param ServerRequestInterface $request + * @return ResponseInterface + */ + public function get(ServerRequestInterface $request): ResponseInterface + { + $slug = $request->getAttribute(static::IDENTIFIER_NAME); + $type = $request->getAttribute('type'); + $imageResponse = new TextResponse($this->awardeeManager->getProfileImage($slug, $type)); + return $imageResponse + ->withHeader('Content-Type', 'image/jpeg') + ->withHeader('Cache-Control', 'must-revalidate') + ; + } + + /** + * @param ServerRequestInterface $request + * @return JsonResponse + */ + public function create(ServerRequestInterface $request): ResponseInterface + { + $slug = $request->getAttribute(static::IDENTIFIER_NAME); + $type = $request->getAttribute('type'); + /** @var UploadedFileInterface[] $files */ + $files = $request->getUploadedFiles(); + $imageData = $files['image']->getStream()->getContents(); + $entity = $this->awardeeManager->setProfileImage($slug, $imageData, $type); + return new JsonResponse($entity); + } + + /** + * @param ServerRequestInterface $request + * @return ResponseInterface + */ + public function delete(ServerRequestInterface $request): ResponseInterface + { + $slug = $request->getAttribute(static::IDENTIFIER_NAME); + $type = $request->getAttribute('type'); + return new JsonResponse($this->awardeeManager->deleteProfileImage($slug, $type)); + } +} diff --git a/src/App/Handler/Api/AwardeeImageHandlerFactory.php b/src/App/Handler/Api/AwardeeImageHandlerFactory.php new file mode 100644 index 0000000..0265102 --- /dev/null +++ b/src/App/Handler/Api/AwardeeImageHandlerFactory.php @@ -0,0 +1,18 @@ +get(AwardeeManager::class); + return new AwardeeImageHandler($awardeeManager); + } +} diff --git a/src/App/Handler/Api/JudgeImageHandler.php b/src/App/Handler/Api/JudgeImageHandler.php new file mode 100644 index 0000000..8eb1c9d --- /dev/null +++ b/src/App/Handler/Api/JudgeImageHandler.php @@ -0,0 +1,65 @@ +judgeManager = $judgeManager; + } + + /** + * @param ServerRequestInterface $request + * @return ResponseInterface + */ + public function get(ServerRequestInterface $request): ResponseInterface + { + $slug = $request->getAttribute(static::IDENTIFIER_NAME); + $imageResponse = new TextResponse($this->judgeManager->getProfileImage($slug)); + return $imageResponse + ->withHeader('Content-Type', 'image/jpeg') + ->withHeader('Cache-Control', 'must-revalidate') + ; + } + + /** + * @param ServerRequestInterface $request + * @return JsonResponse + */ + public function create(ServerRequestInterface $request): ResponseInterface + { + $slug = $request->getAttribute(static::IDENTIFIER_NAME); + /** @var UploadedFileInterface[] $files */ + $files = $request->getUploadedFiles(); + $imageData = $files['image']->getStream()->getContents(); + $entity = $this->judgeManager->setProfileImage($slug, $imageData); + return new JsonResponse($entity); + } + + /** + * @param ServerRequestInterface $request + * @return ResponseInterface + */ + public function delete(ServerRequestInterface $request): ResponseInterface + { + $slug = $request->getAttribute(static::IDENTIFIER_NAME); + return new JsonResponse($this->judgeManager->deleteProfileImage($slug)); + } +} diff --git a/src/App/Handler/Api/JudgeImageHandlerFactory.php b/src/App/Handler/Api/JudgeImageHandlerFactory.php new file mode 100644 index 0000000..1028908 --- /dev/null +++ b/src/App/Handler/Api/JudgeImageHandlerFactory.php @@ -0,0 +1,18 @@ +get(JudgeManager::class); + return new JudgeImageHandler($judgeManager); + } +} diff --git a/src/App/Service/AwardeeManager.php b/src/App/Service/AwardeeManager.php index b944e1f..21685f5 100644 --- a/src/App/Service/AwardeeManager.php +++ b/src/App/Service/AwardeeManager.php @@ -10,6 +10,8 @@ use UtilityModule\Hydrator\DoctrineObject; class AwardeeManager { + const IMAGE_DIRECTORY = 'data/user-data/images/awardee'; + /** @var EntityManager */ private $entityManager; @@ -24,6 +26,9 @@ class AwardeeManager $this->hydrator = $hydrator; } + /** + * @return Awardee[]|null + */ public function getAwardees(): ?array { return $this->entityManager->getRepository(Awardee::class)->findBy([], [ @@ -42,6 +47,10 @@ class AwardeeManager ]); } + /** + * @param int $id + * @return Awardee|null + */ public function getAwardee(int $id): ?Awardee { /** @var Awardee $awardee */ @@ -63,12 +72,14 @@ class AwardeeManager } /** + * @param $data * @return Awardee * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException */ public function create($data): Awardee { + unset($data['slug']); /** @var Awardee $awardee */ $awardee = $this->hydrator->hydrate($data, new Awardee()); $this->entityManager->persist($awardee); @@ -85,6 +96,7 @@ class AwardeeManager */ public function update(int $id, $data): Awardee { + unset($data['slug']); $awardee = $this->entityManager->getRepository(Awardee::class)->find($id); /** @var Awardee $awardee */ $awardee = $this->hydrator->hydrate($data, $awardee); @@ -99,7 +111,8 @@ class AwardeeManager * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException */ - public function delete(int $id): bool { + public function delete(int $id): bool + { if (null !== ($entity = $this->getAwardee($id))) { $this->entityManager->remove($entity); $this->entityManager->flush(); @@ -107,4 +120,69 @@ class AwardeeManager } return false; } + + /** + * @param string $slug + * @param string $type + * @return string + */ + public function getProfileImage(string $slug, string $type): string + { + /** @var Awardee $entity */ + $entity = $this->entityManager->getRepository(Awardee::class)->findOneBy([ + 'slug' => $slug, + ]); + $fileName = $this->getImageFileName($entity->getId(), $type); + if (file_exists($fileName)) { + return file_get_contents($fileName); + } + throw new \InvalidArgumentException("$fileName not found"); + } + + /** + * @param string $slug + * @param string $imageData + * @param string $type + * @return bool + */ + public function setProfileImage(string $slug, string $imageData, string $type): bool + { + /** @var Awardee $entity */ + $entity = $this->entityManager->getRepository(Awardee::class)->findOneBy([ + 'slug' => $slug, + ]); + $this->ensureImageDirectoryExists(); + $fileName = $this->getImageFileName($entity->getId(), $type); + return false !== file_put_contents($fileName, $imageData); + } + + /** + * @param string $slug + * @param string $type + * @return bool + */ + public function deleteProfileImage(string $slug, string $type): bool + { + /** @var Awardee $entity */ + $entity = $this->entityManager->getRepository(Awardee::class)->findOneBy([ + 'slug' => $slug, + ]); + $fileName = $this->getImageFileName($entity->getId(), $type); + if (file_exists($fileName)) { + return unlink($fileName); + } + throw new \InvalidArgumentException(); + } + + public function ensureImageDirectoryExists() + { + if (!is_dir(self::IMAGE_DIRECTORY)) { + mkdir(self::IMAGE_DIRECTORY, 0755, true); + } + } + + private function getImageFileName(int $id, string $type): string + { + return sprintf('%s/%s-%s.jpg', self::IMAGE_DIRECTORY, $id, $type); + } } diff --git a/src/App/Service/JudgeManager.php b/src/App/Service/JudgeManager.php index fc2fb7c..11d68d7 100644 --- a/src/App/Service/JudgeManager.php +++ b/src/App/Service/JudgeManager.php @@ -10,6 +10,8 @@ use UtilityModule\Hydrator\DoctrineObject; class JudgeManager { + const IMAGE_DIRECTORY = 'data/user-data/images/judge'; + /** @var EntityManager */ private $entityManager; @@ -24,7 +26,10 @@ class JudgeManager $this->hydrator = $hydrator; } - public function getJudges() + /** + * @return Judge[]|null + */ + public function getJudges(): ?array { $qb = $this->entityManager->createQueryBuilder(); return $qb->select('j, t') @@ -32,14 +37,14 @@ class JudgeManager ->leftJoin('j.titles', 't') ->orderBy('j.name', 'ASC') ->getQuery() - ->getArrayResult(); + ->getResult(); } /** * @param int $year - * @return array + * @return Judge[]|null */ - public function getJudgesByYear(int $year) + public function getJudgesByYear(int $year): ?array { $qb = $this->entityManager->createQueryBuilder(); return $qb->select('j,t') @@ -49,7 +54,7 @@ class JudgeManager ->orderBy('j.name', 'ASC') ->setParameter('year', $year) ->getQuery() - ->getArrayResult(); + ->getResult(); } /** @@ -71,6 +76,7 @@ class JudgeManager */ public function create($data): Judge { + unset($data['slug']); /** @var Judge $judge */ $judge = $this->hydrator->hydrate($data, new Judge()); $this->entityManager->persist($judge); @@ -87,6 +93,7 @@ class JudgeManager */ public function update(int $id, $data): Judge { + unset($data['slug']); $judge = $this->entityManager->getRepository(Judge::class)->find($id); /** @var Judge $judge */ $judge = $this->hydrator->hydrate($data, $judge); @@ -110,4 +117,66 @@ class JudgeManager } return false; } + + /** + * @param string $slug + * @return string + */ + public function getProfileImage(string $slug): string + { + /** @var Judge $entity */ + $entity = $this->entityManager->getRepository(Judge::class)->findOneBy([ + 'slug' => $slug, + ]); + $fileName = $this->getImageFileName($entity->getId()); + if (file_exists($fileName)) { + return file_get_contents($fileName); + } + throw new \InvalidArgumentException(); + } + + /** + * @param string $slug + * @param string $imageData + * @return bool + */ + public function setProfileImage(string $slug, string $imageData): bool + { + /** @var Judge $entity */ + $entity = $this->entityManager->getRepository(Judge::class)->findOneBy([ + 'slug' => $slug, + ]); + $this->ensureImageDirectoryExists(); + $fileName = $this->getImageFileName($entity->getId()); + return false !== file_put_contents($fileName, $imageData); + } + + /** + * @param string $slug + * @return bool + */ + public function deleteProfileImage(string $slug): bool + { + /** @var Judge $entity */ + $entity = $this->entityManager->getRepository(Judge::class)->findOneBy([ + 'slug' => $slug, + ]); + $fileName = $this->getImageFileName($entity->getId()); + if (file_exists($fileName)) { + return unlink($fileName); + } + throw new \InvalidArgumentException(); + } + + public function ensureImageDirectoryExists() + { + if (!is_dir(self::IMAGE_DIRECTORY)) { + mkdir(self::IMAGE_DIRECTORY, 0755, true); + } + } + + private function getImageFileName(int $id): string + { + return sprintf('%s/%s.jpg', self::IMAGE_DIRECTORY, $id); + } } diff --git a/src/UtilityModule/Handler/AuthHandler.php b/src/UtilityModule/Handler/AuthHandler.php index a66b648..5ee22f4 100644 --- a/src/UtilityModule/Handler/AuthHandler.php +++ b/src/UtilityModule/Handler/AuthHandler.php @@ -41,7 +41,7 @@ class AuthHandler extends AbstractCrudHandler * @param ServerRequestInterface $request * @return \Zend\Diactoros\Response\JsonResponse */ - public function get(ServerRequestInterface $request) + public function getList(ServerRequestInterface $request) { $token = $request->getAttribute('token'); return new JsonResponse($this->authService->renewToken($token)); diff --git a/src/UtilityModule/Middleware/JwtMiddlewareFactory.php b/src/UtilityModule/Middleware/JwtMiddlewareFactory.php index 441afad..226d695 100644 --- a/src/UtilityModule/Middleware/JwtMiddlewareFactory.php +++ b/src/UtilityModule/Middleware/JwtMiddlewareFactory.php @@ -64,6 +64,11 @@ class JwtMiddlewareFactory } } + $unguardedPaths = $this->aclConfig->get('unguarded_paths', new Config([]))->toArray(); + foreach ($unguardedPaths as $path) { + $passThroughRoutes[] = $path; + } + return $passThroughRoutes; } } diff --git a/src/UtilityModule/Service/AuthService.php b/src/UtilityModule/Service/AuthService.php index e1e634b..c459acd 100644 --- a/src/UtilityModule/Service/AuthService.php +++ b/src/UtilityModule/Service/AuthService.php @@ -62,6 +62,7 @@ class AuthService /** @var string $hmacKey */ $hmacKey = $this->config->get('hmac_key'); return JWT::encode([ + "jti" => uniqid(), "iat" => time(), "nbf" => time(), "exp" => time() + 3600, @@ -77,7 +78,7 @@ class AuthService /** @var string $hmacKey */ $hmacKey = $this->config->get('hmac_key'); return JWT::encode([ - "jti" => $token->jti, + "jti" => $token['jti'], "iat" => time(), "nbf" => time(), "exp" => time() + 3600, diff --git a/templates/app/awardees.phtml b/templates/app/awardees.phtml index 3bf0e28..a14cba5 100644 --- a/templates/app/awardees.phtml +++ b/templates/app/awardees.phtml @@ -2,7 +2,7 @@
- +
getName() ?>
batch($awardee->getText(), 'excerpt|mdtohtml') ?>
diff --git a/templates/app/judges.inc.phtml b/templates/app/judges.inc.phtml index f6ef129..329f9a5 100644 --- a/templates/app/judges.inc.phtml +++ b/templates/app/judges.inc.phtml @@ -2,9 +2,9 @@

judges

- -
- + + getPrefix().$judge->getName()?>
+ getTitles()[0]->getTitle()?>
diff --git a/templates/app/profile.phtml b/templates/app/profile.phtml index a1ee9d7..5e5f125 100644 --- a/templates/app/profile.phtml +++ b/templates/app/profile.phtml @@ -1,13 +1,13 @@ layout('layout::default', ['title' => $awardee->getName()]) ?>
- +
getYear() ?>
getName() ?>
mdtohtml($awardee->getText()) ?>