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'] ?? 'avatar_1',
37 'submit' => $_POST['submit'] ?? false,
41 foreach (glob(__DIR__ . '/../www/resources/avatars/*.small.jpg') as $smallImage) {
42 $key = basename($smallImage, '.small.jpg');
43 $avatars[$key] = '/resources/avatars/' . basename($smallImage);
48 if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['gamerTag'])) {
49 $errors['gamerTag'] = 'Invalid gamer tag';
51 if ($input['founderFlag']) {
52 if ($input['founderName'] === '') {
53 $errors['founderName'] = 'Founder name missing';
54 } else if (!preg_match('#^[A-Za-z0-9 ]+$#', $input['founderName'])) {
55 $errors['founderName'] = 'Invalid founder name';
58 if (!in_array($input['minAge'], [3, 7, 12, 17])) {
59 $errors['minAge'] = 'Invalid age';
61 if (!in_array($input['avatar'], array_keys($avatars))) {
62 $errors['avatar'] = 'Invalid avatar image';
65 if (!$input['submit'] || count($errors)) {
66 require $tplDir . '/activate-profile.phtml';
70 //validation successful, store the profile
71 //$input['verificationCode'] => null;
72 unset($input['submit']);
73 $profile = $profileDb->updateProfile($profile->hwId, $input);
75 require $tplDir . '/activate-success.phtml';