2 $rootDir = dirname(__FILE__, 2);
3 $tplDir = $rootDir . '/templates';
5 require_once $rootDir . '/config.php';
6 require $rootDir . '/src/ProfileDb.php';
7 $profileDb = new ProfileDb();
12 if (isset($_REQUEST['code']) && trim($_REQUEST['code']) !== '') {
13 $code = $_REQUEST['code'];
15 $profile = $profileDb->getProfileByVerificationCode($code);
16 if ($profile === null) {
17 $error = 'Invalid code';
20 if ($code === 'success') {
21 require $tplDir . '/activate-success.phtml';
26 if ($profile === null) {
27 require $tplDir . '/activate-code.phtml';
32 'gamerTag' => $_POST['gamerTag'] ?? null,
33 'founderFlag' => (bool) ($_POST['founderFlag'] ?? false),
34 'founderName' => $_POST['founderName'] ?? null,
35 'minAge' => $_POST['minAge'] ?? 3,
36 'avatar' => $_POST['avatar'] ?? 'rocket',
37 'submit' => $_POST['submit'] ?? false,
41 $input['avatar'] => null,//have active one first, especially for mobile
43 $avatarFiles = glob(__DIR__ . '/../www/resources/avatars/*.small.{jpg,png}', GLOB_BRACE);
44 foreach ($avatarFiles as $smallImage) {
45 $key = basename($smallImage, '.small.jpg');
46 $key = basename($key, '.small.png');
47 $avatars[$key] = '/resources/avatars/' . basename($smallImage);
49 $avatars = array_filter($avatars);
53 if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['gamerTag'])) {
54 $errors['gamerTag'] = 'Invalid gamer tag';
56 if ($input['founderFlag']) {
57 if ($input['founderName'] === '') {
58 $errors['founderName'] = 'Founder name missing';
59 } else if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['founderName'])) {
60 $errors['founderName'] = 'Invalid founder name';
63 if (!in_array($input['minAge'], [3, 7, 12, 17])) {
64 $errors['minAge'] = 'Invalid age';
66 if (!in_array($input['avatar'], array_keys($avatars))) {
67 $errors['avatar'] = 'Invalid avatar image';
70 if (!$input['submit'] || count($errors)) {
71 require $tplDir . '/activate-profile.phtml';
75 //validation successful, store the profile
76 //$input['verificationCode'] => null;
77 unset($input['submit']);
78 $profile = $profileDb->updateProfile($profile->hwId, $input);
80 require $tplDir . '/activate-success.phtml';