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';
21 if ($profile === null) {
22 require $tplDir . '/activate-code.phtml';
27 'gamerTag' => $_POST['gamerTag'] ?? null,
28 'founderFlag' => (bool) ($_POST['founderFlag'] ?? false),
29 'founderName' => $_POST['founderName'] ?? null,
30 'minAge' => $_POST['minAge'] ?? 3,
31 'avatar' => $_POST['avatar'] ?? 'avatar_1',
32 'submit' => $_POST['submit'] ?? false,
36 foreach (glob(__DIR__ . '/../www/resources/avatars/*.small.jpg') as $smallImage) {
37 $key = basename($smallImage, '.small.jpg');
38 $avatars[$key] = '/resources/avatars/' . basename($smallImage);
43 if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['gamerTag'])) {
44 $errors['gamerTag'] = 'Invalid gamer tag';
46 if ($input['founderFlag']) {
47 if ($input['founderName'] === '') {
48 $errors['founderName'] = 'Founder name missing';
49 } else if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['founderName'])) {
50 $errors['founderName'] = 'Invalid founder name';
53 if (!in_array($input['minAge'], [3, 7, 12, 17])) {
54 $errors['minAge'] = 'Invalid age';
56 if (!in_array($input['avatar'], array_keys($avatars))) {
57 $errors['avatar'] = 'Invalid avatar image';
60 if (!$input['submit'] || count($errors)) {
61 require $tplDir . '/activate-profile.phtml';
65 //validation successful, store the profile
66 //$input['verificationCode'] => null;
67 unset($input['submit']);
68 $profile = $profileDb->updateProfile($profile->hwId, $input);
70 require $tplDir . '/activate-success.phtml';