svrjs-mods-directory/includes/page_confirmregistration.php
2024-12-27 15:05:54 +01:00

86 lines
No EOL
3.1 KiB
PHP

<?php
if (!defined('SVRJS_MOD_DIRECTORY')) die;
$errorMessage = null;
if (!isset($_GET['id']) || !$_GET['id']) {
http_response_code(400);
$errorMessage = "Email address change request ID is not specified.";
} else {
$statement = $connection->prepare("SELECT users.id AS id, users.is_verified AS is_verified FROM requests_register JOIN users ON users.id = requests_register.user WHERE requests_register.id = ?");
if (!$statement) {
http_response_code(500);
$errorMessage = "An unexpected error occurred while verifiying the account.";
} else {
$statement->bind_param('s', $_GET['id']);
$statement->execute();
$result = $statement->get_result();
if (!$result) {
http_response_code(500);
$errorMessage = "An unexpected error occurred while verifiying the account.";
$statement->close();
} else {
$userData = $result->fetch_assoc();
$statement->close();
if (!$userData) {
http_response_code(400);
$errorMessage = "Invalid request ID.";
} else {
$verified = false;
if ($userData['is_verified']) {
$verified = true;
http_response_code(400);
$errorMessage = "The account is already verified.";
}
if (!$verified) {
$statement = $connection->prepare("UPDATE users SET is_verified = 1 WHERE id = ?");
if (!$statement) {
http_response_code(500);
$errorMessage = "An unexpected error occurred while verifiying the account.";
} else {
$statement->bind_param('i', $userData['id']);
if (!$statement->execute()) {
http_response_code(500);
$errorMessage = "An unexpected error occurred while verifiying the account.";
} else {
session_regenerate_id(true);
$_SESSION['user'] = $userData['id'];
}
$statement->close();
}
}
}
$statement = $connection->prepare("DELETE FROM requests_register WHERE id = ?");
if (!$statement) {
http_response_code(500);
$errorMessage = "An unexpected error occurred while verifiying the account.";
} else {
$statement->bind_param('s', $_GET['id']);
if (!$statement->execute()) {
http_response_code(500);
$errorMessage = "An unexpected error occurred while verifiying the account.";
}
$statement->close();
}
}
}
}
if ($errorMessage) {
$pageTitle = "Your account hasn't been verified";
$pageDescription = $errorMessage;
} else {
$pageTitle = "Your account has been verified";
$pageDescription = "Your account has been verified.";
}
include 'header.php';
?>
<main class="content">
<h1><?php echo htmlspecialchars($errorMessage ? "Your account hasn't been verified" : "Your account has been verified") ?></h1>
<p><?php echo htmlspecialchars($errorMessage ? $errorMessage : "Your account has been verified.") ?></p>
<p><a href="<?php echo htmlspecialchars(URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') ?>" class="btn">Return to home</a></p>
</main>
<?php
include 'footer.php';
?>