Skip to content

Commit

Permalink
GH-150 Validate galaxy no
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Mar 19, 2022
1 parent adbfe80 commit e97cf73
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
27 changes: 27 additions & 0 deletions modules/registration/validators/validateInputs.validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ function _validateEmail($normalizedInput) {
return _createFuncWithResultHelpers($validator)($normalizedInput);
}

function _validateGalaxyNo($normalizedInput) {
$validator = function ($input, $resultHelpers) {
$value = $input['galaxyNo'];

$minGalaxyNo = 1;
$maxGalaxyNo = MAX_GALAXY_IN_WORLD;

if ($value < $minGalaxyNo) {
return $resultHelpers['createFailure']([
'code' => 'GALAXY_NO_TOO_LOW',
'minLength' => $minGalaxyNo,
]);
}
if ($value > $maxGalaxyNo) {
return $resultHelpers['createFailure']([
'code' => 'GALAXY_NO_TOO_HIGH',
'maxLength' => $maxGalaxyNo,
]);
}

return $resultHelpers['createSuccess']([]);
};

return _createFuncWithResultHelpers($validator)($normalizedInput);
}

// Arguments
// - $normalizedInput (Object)
//
Expand All @@ -117,6 +143,7 @@ function validateInputs($normalizedInput) {
'username' => _validateUsername($normalizedInput),
'password' => _validatePassword($normalizedInput),
'email' => _validateEmail($normalizedInput),
'galaxyNo' => _validateGalaxyNo($normalizedInput),
];
}

Expand Down
22 changes: 8 additions & 14 deletions reg_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,17 @@
$JSONResponse['Errors'][] = 8;
$JSONResponse['BadFields'][] = 'email';
break;
case 'GALAXY_NO_TOO_LOW':
$JSONResponse['Errors'][] = 13;
$JSONResponse['BadFields'][] = 'galaxy';
break;
case 'GALAXY_NO_TOO_HIGH':
$JSONResponse['Errors'][] = 14;
$JSONResponse['BadFields'][] = 'galaxy';
break;
}
}

// PreCheck Galaxy
if($GalaxyNo < 1)
{
// Galaxy not given
$JSONResponse['Errors'][] = 13;
$JSONResponse['BadFields'][] = 'galaxy';
}
else if($GalaxyNo > MAX_GALAXY_IN_WORLD)
{
// GalaxyNo is too high
$JSONResponse['Errors'][] = 14;
$JSONResponse['BadFields'][] = 'galaxy';
}

// Check if valid language has been selected
if(empty($LangCode))
{
Expand Down

0 comments on commit e97cf73

Please sign in to comment.