getProfileByVerificationCode($code); if ($profile === null) { $error = 'Invalid code'; } if ($code === 'success') { require $tplDir . '/activate-success.phtml'; exit(); } } if ($profile === null) { require $tplDir . '/activate-code.phtml'; exit(); } $input = [ 'gamerTag' => $_POST['gamerTag'] ?? null, 'founderFlag' => (bool) ($_POST['founderFlag'] ?? false), 'founderName' => $_POST['founderName'] ?? null, 'minAge' => $_POST['minAge'] ?? 3, 'avatar' => $_POST['avatar'] ?? 'rocket', 'submit' => $_POST['submit'] ?? false, ]; $avatars = [ $input['avatar'] => null,//have active one first, especially for mobile ]; $avatarFiles = glob(__DIR__ . '/../www/resources/avatars/*.small.{jpg,png}', GLOB_BRACE); foreach ($avatarFiles as $smallImage) { $key = basename($smallImage, '.small.jpg'); $key = basename($key, '.small.png'); $avatars[$key] = '/resources/avatars/' . basename($smallImage); } $avatars = array_filter($avatars); //input validation $errors = []; if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['gamerTag'])) { $errors['gamerTag'] = 'Invalid gamer tag'; } if ($input['founderFlag']) { if ($input['founderName'] === '') { $errors['founderName'] = 'Founder name missing'; } else if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['founderName'])) { $errors['founderName'] = 'Invalid founder name'; } } if (!in_array($input['minAge'], [3, 7, 12, 17])) { $errors['minAge'] = 'Invalid age'; } if (!in_array($input['avatar'], array_keys($avatars))) { $errors['avatar'] = 'Invalid avatar image'; } if (!$input['submit'] || count($errors)) { require $tplDir . '/activate-profile.phtml'; exit(); } //validation successful, store the profile //$input['verificationCode'] => null; unset($input['submit']); $profile = $profileDb->updateProfile($profile->hwId, $input); require $tplDir . '/activate-success.phtml';