feature/MAPG-235-basic-challenge-mode #48
@ -107,6 +107,10 @@ class GameController
|
|||||||
{
|
{
|
||||||
// create Challenge
|
// create Challenge
|
||||||
$challengeToken = rand();
|
$challengeToken = rand();
|
||||||
|
while ($this->challengeRepository->getByToken($challengeToken)) {
|
||||||
|
// if a challenge with the same token already exists
|
||||||
|
$challengeToken = rand();
|
||||||
|
}
|
||||||
|
|
||||||
$challenge = new Challenge();
|
$challenge = new Challenge();
|
||||||
balazs marked this conversation as resolved
Outdated
|
|||||||
$challenge->setToken($challengeToken);
|
$challenge->setToken($challengeToken);
|
||||||
|
@ -31,6 +31,13 @@ class ChallengeRepository
|
|||||||
|
|
||||||
public function getByTokenStr(string $token_str): ?Challenge
|
public function getByTokenStr(string $token_str): ?Challenge
|
||||||
{
|
{
|
||||||
|
// validate token string
|
||||||
|
foreach (str_split($token_str) as $char) {
|
||||||
|
if (!(('0' <= $char && $char <= '9') || ('a' <= $char && $char <= 'f'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// convert token to int
|
||||||
$token = hexdec($token_str);
|
$token = hexdec($token_str);
|
||||||
|
|
||||||
return $this->getByToken($token);
|
return $this->getByToken($token);
|
||||||
|
@ -48,6 +48,13 @@ class UserInChallengeRepository
|
|||||||
$withRelations = array_unique(array_merge($withRelations, $necessaryRelations));
|
$withRelations = array_unique(array_merge($withRelations, $necessaryRelations));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate token string
|
||||||
|
foreach (str_split($token_str) as $char) {
|
||||||
|
if (!(('0' <= $char && $char <= '9') || ('a' <= $char && $char <= 'f'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// convert token to int
|
||||||
$token = hexdec($token_str);
|
$token = hexdec($token_str);
|
||||||
|
|
||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
balazs marked this conversation as resolved
Outdated
bence
commented
PHP's builtin ctype_xdigit could be used for that. PHP's builtin [ctype_xdigit](https://www.php.net/manual/en/function.ctype-xdigit.php) could be used for that.
|
|||||||
|
Loading…
Reference in New Issue
Block a user
Maybe a do..while would be better here because the token calculation should not be repeated.
My eye is twitching when variables are used outside of the scope of {}, but it's different in PHP, so it can be refactored.