38350-vm/register.php
2026-02-14 05:11:30 +00:00

101 lines
6.0 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/i18n.php';
session_start();
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
if (empty($username) || empty($password)) {
$error = __('fill_all_fields');
} elseif ($password !== $confirm_password) {
$error = __('passwords_not_match');
} else {
$pdo = db();
// Check if user exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetch()) {
$error = __('username_taken');
} else {
// Generate UID starting from 618120
$stmt = $pdo->query("SELECT COUNT(*) FROM users");
$count = $stmt->fetchColumn();
$uid = 618120 + $count + mt_rand(1, 9);
// Capture IP correctly
$user_ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$user_ip = trim($ips[0]);
}
// Register and auto-login
$stmt = $pdo->prepare("INSERT INTO users (uid, username, password, trading_password, balance, last_ip) VALUES (?, ?, ?, '123456', 0, ?)");
if ($stmt->execute([$uid, $username, password_hash($password, PASSWORD_DEFAULT), $user_ip])) {
$user_id = $pdo->lastInsertId();
$_SESSION['user_id'] = $user_id;
$_SESSION['username'] = $username;
$_SESSION['uid'] = $uid;
header("Location: index.php");
exit;
} else {
$error = __('registration_failed');
}
}
}
}
?>
<?php include 'header.php'; ?>
<main style="background: #0b0e11; min-height: calc(100vh - 64px); display: flex; align-items: center; justify-content: center; padding: 40px 20px;">
<div style="width: 100%; max-width: 480px; background: var(--card-bg); padding: 50px; border-radius: 32px; border: 1px solid var(--border-color); box-shadow: 0 20px 40px rgba(0,0,0,0.4);">
<h2 style="font-size: 2.2rem; font-weight: 800; margin-bottom: 10px; text-align: center; color: white;"><?php echo __('create_account'); ?></h2>
<p style="text-align: center; color: var(--text-muted); margin-bottom: 40px;"><?php echo __('join_novaex_tip'); ?></p>
<?php if($error): ?>
<div style="background: rgba(246,70,93,0.1); color: var(--danger-color); padding: 15px; border-radius: 12px; margin-bottom: 25px; border: 1px solid var(--danger-color); text-align: center; font-size: 14px;">
<i class="fas fa-exclamation-circle"></i> <?php echo $error; ?>
</div>
<?php endif; ?>
<form method="POST">
<div style="margin-bottom: 25px;">
<label style="display: block; margin-bottom: 10px; color: var(--text-muted); font-size: 14px;"><?php echo __('email_or_phone'); ?></label>
<div style="position: relative;">
<i class="fas fa-envelope" style="position: absolute; left: 15px; top: 15px; color: #555;"></i>
<input type="text" name="username" required placeholder="<?php echo __('enter_email_phone'); ?>" style="width: 100%; padding: 15px 15px 15px 45px; background: #161a1e; border: 1px solid var(--border-color); color: white; border-radius: 12px; font-size: 1rem; outline: none; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 25px;">
<label style="display: block; margin-bottom: 10px; color: var(--text-muted); font-size: 14px;"><?php echo __('login_password'); ?></label>
<div style="position: relative;">
<i class="fas fa-lock" style="position: absolute; left: 15px; top: 15px; color: #555;"></i>
<input type="password" name="password" required placeholder="<?php echo __('set_password'); ?>" style="width: 100%; padding: 15px 15px 15px 45px; background: #161a1e; border: 1px solid var(--border-color); color: white; border-radius: 12px; font-size: 1rem; outline: none; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 30px;">
<label style="display: block; margin-bottom: 10px; color: var(--text-muted); font-size: 14px;"><?php echo __('confirm_password_label'); ?></label>
<div style="position: relative;">
<i class="fas fa-check-double" style="position: absolute; left: 15px; top: 15px; color: #555;"></i>
<input type="password" name="confirm_password" required placeholder="<?php echo __('confirm_your_password'); ?>" style="width: 100%; padding: 15px 15px 15px 45px; background: #161a1e; border: 1px solid var(--border-color); color: white; border-radius: 12px; font-size: 1rem; outline: none; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 30px; display: flex; align-items: flex-start; gap: 12px;">
<input type="checkbox" required style="margin-top: 4px; accent-color: var(--primary-color);">
<span style="font-size: 0.85rem; color: var(--text-muted); line-height: 1.5;"><?php echo __('agree_terms'); ?></span>
</div>
<button type="submit" class="btn-primary" style="width: 100%; padding: 18px; font-weight: 800; font-size: 1.1rem; border-radius: 16px; box-shadow: 0 10px 20px rgba(0,82,255,0.2);"><?php echo __('nav_register'); ?></button>
</form>
<div style="text-align: center; margin-top: 30px; border-top: 1px solid var(--border-color); padding-top: 30px;">
<span style="color: var(--text-muted);"><?php echo __('already_have_account'); ?></span> <a href="login.php" style="color: var(--primary-color); text-decoration: none; font-weight: bold;"><?php echo __('nav_login'); ?></a>
</div>
</div>
</main>
<?php include 'footer.php'; ?>