1 Commits
v0.0.1 ... php

Author SHA1 Message Date
Marijn Doeve
3192fb6c83 Refactor Base64 encoding/decoding methods and enhance candidate not found flash message 2025-04-02 21:20:44 +02:00
2 changed files with 19 additions and 7 deletions

View File

@@ -72,8 +72,11 @@ class QuizController extends AbstractController
$candidate = $candidateRepository->getCandidateByHash($season, $nameHash); $candidate = $candidateRepository->getCandidateByHash($season, $nameHash);
if (!$candidate instanceof Candidate) { if (!$candidate instanceof Candidate) {
// Add option to add new candidate when preregister is disabled if ($season->isPreregisterCandidates() === false) {
$this->addFlash(FlashType::Danger->value, 'Candidate not found'); // create candidate
}
$this->addFlash(FlashType::Danger->value, "Candidate {${Base64::base64_url_decode($nameHash)}} not found");
return $this->redirectToRoute('enter_name', ['seasonCode' => $season->getSeasonCode()]); return $this->redirectToRoute('enter_name', ['seasonCode' => $season->getSeasonCode()]);
} }

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Helpers; namespace App\Helpers;
use Safe\Exceptions\UrlException; use Safe\Exceptions\UrlException;
use function rtrim;
class Base64 class Base64
{ {
@@ -12,14 +13,22 @@ class Base64
{ {
} }
public static function base64_url_encode(string $input): string /**
* @param string $name name to hash
* @return string hashed name
*/
public static function base64_url_encode(string $name): string
{ {
return strtr(base64_encode($input), '+/', '-_'); return rtrim(strtr(base64_encode($name), '+/', '-_'), '=');
} }
/** @throws UrlException */ /**
public static function base64_url_decode(string $input): string * @param string $hash hashed name
* @return string plaintext name
* @throws UrlException
*/
public static function base64_url_decode(string $hash): string
{ {
return \Safe\base64_decode(strtr($input, '-_', '+/'), true); return \Safe\base64_decode(strtr($hash, '-_', '+/'), true);
} }
} }