Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 5m39s
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'includes/globals.php';
|
|
require_once 'vendor/autoload.php';
|
|
|
|
use DJMixHosting\Database;
|
|
use DJMixHosting\User;
|
|
|
|
if (!isset($_SESSION['user'])) {
|
|
$_SESSION['error'] = $locale['loginToVerifyEmail'];
|
|
header("Location: /login");
|
|
exit;
|
|
}
|
|
|
|
$db = new Database($config);
|
|
$userId = $_SESSION['user']['id'];
|
|
|
|
// Create a User instance
|
|
$user = new User($db, $userId);
|
|
|
|
// Retrieve the verification code from GET or POST
|
|
$verification_code = "";
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['verification_code'])) {
|
|
$verification_code = trim($_POST['verification_code']);
|
|
} elseif (isset($_GET['code'])) {
|
|
$verification_code = trim($_GET['code']);
|
|
} else {
|
|
$_SESSION['error'] = $locale['verificationCodeRequired'];
|
|
header("Location: /profile");
|
|
exit;
|
|
}
|
|
|
|
// Attempt to verify the email
|
|
try {
|
|
$message = $user->verifyEmail($verification_code);
|
|
$_SESSION['success'] = $message;
|
|
} catch (\Exception $e) {
|
|
$_SESSION['error'] = $e->getMessage();
|
|
}
|
|
|
|
header("Location: /profile");
|
|
exit;
|