newUser($username, $password, $email, $first_name, $last_name); } catch (\Exception $e) { $_SESSION['error'] = $e->getMessage(); header("Location: register.php"); exit; } // Log the user in using SessionManager SessionManager::setUser([ 'id' => $user_id, 'username' => $username, 'email' => $email ]); // Trigger email verification: generate a verification code valid for 15 minutes $verification_code = bin2hex(random_bytes(16)); $expires_at = date("Y-m-d H:i:s", strtotime("+15 minutes")); // Insert verification record (with purpose 'email_verification') $stmt = $db->prepare("REPLACE INTO email_verifications (user_id, email, verification_code, expires_at, purpose) VALUES (?, ?, ?, ?, 'email_verification')"); $stmt->bind_param("isss", $user_id, $email, $verification_code, $expires_at); $stmt->execute(); $stmt->close(); // Send verification email via AWS SES $sesClient = new SesClient([ 'version' => 'latest', 'region' => $config['aws']['ses']['region'], 'credentials' => [ 'key' => $config['aws']['ses']['access_key'], 'secret' => $config['aws']['ses']['secret_key'] ] ]); $sender_email = $config['aws']['ses']['sender_email']; $recipient_email = $email; $subject = "Verify Your Email Address"; $verification_link = $config['app']['url'] . "/verify_email.php?code={$verification_code}"; $body_text = "Thank you for registering at " . $config['app']['name'] . ".\n\n"; $body_text .= "Please verify your email address by clicking the link below or by entering the verification code in your profile:\n\n"; $body_text .= "{$verification_link}\n\nYour verification code is: {$verification_code}\nThis code will expire in 15 minutes."; try { $sesClient->sendEmail([ 'Destination' => ['ToAddresses' => [$recipient_email]], 'ReplyToAddresses' => [$sender_email], 'Source' => $sender_email, 'Message' => [ 'Body' => [ 'Text' => [ 'Charset' => 'UTF-8', 'Data' => $body_text, ], ], 'Subject' => [ 'Charset' => 'UTF-8', 'Data' => $subject, ], ], ]); $_SESSION['success'] = "Registration successful! A verification email has been sent to your email address."; } catch (AwsException $e) { $_SESSION['error'] = "Registration successful, but failed to send verification email: " . $e->getAwsErrorMessage(); } header("Location: profile.php"); exit; } require_once 'includes/header.php'; ?>
' . htmlspecialchars($_SESSION['error']) . '
'; unset($_SESSION['error']); } ?>

Register

Already have an account? Login