['required', ['length' => ['min' => 2, 'max' => 31]], 'avatar_name'], 'lastName' => ['required', ['length' => ['min' => 2, 'max' => 31]], 'avatar_name'], 'email' => ['required', 'email'], 'password' => ['required', ['length' => ['min' => 8, 'max' => 50]]], 'password_confirm' => ['required'] ]; $form_data = [ 'firstName' => $_POST['firstName'] ?? '', 'lastName' => $_POST['lastName'] ?? '', 'email' => $_POST['email'] ?? '', 'password' => $_POST['password'] ?? '', 'password_confirm' => $_POST['password_confirm'] ?? '' ]; $validation_errors = validate_form($form_data, $validation_rules); // Additional validations if (empty($validation_errors)) { if ($form_data['password'] !== $form_data['password_confirm']) { $validation_errors['password_confirm'] = 'Passwords do not match'; } $password_check = OSWebSecurity::validatePassword($form_data['password']); if ($password_check !== true) { $validation_errors['password'] = implode(', ', $password_check); } if (is_disposable_email($form_data['email'], $disposable_domains, $blocked_tlds)) { $validation_errors['email'] = 'Disposable email addresses are not allowed'; } } if (empty($validation_errors)) { // Store data in session $_SESSION['avatar_data'] = [ 'firstName' => sanitize_input($form_data['firstName']), 'lastName' => sanitize_input($form_data['lastName']), 'email' => sanitize_input($form_data['email'], 'email'), 'password' => $form_data['password'] // Will be hashed later ]; $_SESSION['avatar_creation_step'] = 2; $current_step = 2; // Generate and send verification code $activation_code = bin2hex(random_bytes(16)); $_SESSION['activation_code'] = $activation_code; $_SESSION['code_expires'] = time() + 1800; // 30 minutes if (sendVerificationEmail($form_data['email'], $form_data['firstName'], $form_data['lastName'], $activation_code)) { $success_message = 'Verification code sent to your email address.'; } else { $errors[] = 'Failed to send verification email. Please check your email address.'; } } else { $errors = array_values($validation_errors); } } elseif (isset($_POST['submit_step2'])) { // Step 2: Email Verification $provided_code = sanitize_input($_POST['activation_code'] ?? ''); $stored_code = $_SESSION['activation_code'] ?? ''; $code_expires = $_SESSION['code_expires'] ?? 0; if (empty($provided_code)) { $errors[] = 'Please enter the activation code.'; } elseif (time() > $code_expires) { $errors[] = 'Activation code has expired. Please start registration again.'; session_destroy(); } elseif (!hash_equals($stored_code, $provided_code)) { $errors[] = 'Invalid activation code. Please check your email.'; } else { $_SESSION['avatar_creation_step'] = 3; $current_step = 3; $success_message = 'Email verified successfully!'; } } elseif (isset($_POST['submit_step3'])) { // Step 3: Final Registration if (!isset($_SESSION['avatar_data'])) { $errors[] = 'Session expired. Please start registration again.'; session_destroy(); } else { try { $db = new OSWebDatabase(); $avatar_data = $_SESSION['avatar_data']; // Check if user already exists $check_stmt = $db->prepare("SELECT COUNT(*) FROM UserAccounts WHERE FirstName = ? AND LastName = ?"); $check_stmt->bind_param("ss", $avatar_data['firstName'], $avatar_data['lastName']); $check_stmt->execute(); $check_stmt->bind_result($count); $check_stmt->fetch(); $check_stmt->close(); if ($count > 0) { $errors[] = 'An avatar with this name already exists.'; } else { // Create avatar $user_uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); // Hash password $salt = md5(str_replace("-", "", $user_uuid)); $password_hash = md5(md5($avatar_data['password']) . ":" . $salt); // Insert user account $stmt = $db->prepare("INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created, passwordHash, passwordSalt) VALUES (?, '00000000-0000-0000-0000-000000000000', ?, ?, ?, '', ?, ?, ?)"); $created = time(); $stmt->bind_param("ssssiiss", $user_uuid, $avatar_data['firstName'], $avatar_data['lastName'], $avatar_data['email'], $created, $password_hash, $salt); if ($stmt->execute()) { $success_message = 'Avatar created successfully! You can now log in to the grid.'; $current_step = 4; // Clear session data unset($_SESSION['avatar_data']); unset($_SESSION['activation_code']); unset($_SESSION['code_expires']); unset($_SESSION['avatar_creation_step']); } else { $errors[] = 'Failed to create avatar. Please try again.'; OSWebErrorHandler::logError('Avatar creation failed', ['error' => $stmt->error]); } $stmt->close(); } } catch (Exception $e) { $errors[] = 'A system error occurred. Please try again later.'; OSWebErrorHandler::logError('Avatar creation exception', ['error' => $e->getMessage()]); } } } } } } ?>
Join and start your virtual journey
We've sent a verification code to
Code expires in 30 minutes. Didn't receive it? Check your spam folder.
Name:
Email:
Welcome to ! Your avatar has been created and is ready to explore the virtual world.