38451-vm/auth/register.php
2026-02-16 02:49:59 +00:00

131 lines
6.1 KiB
PHP

<?php
require_once __DIR__ . '/../includes/lang.php';
require_once __DIR__ . '/../db/config.php';
$error = '';
$email_verify_enabled = getSetting('email_verification_enabled', '0') === '1';
function getSetting($key, $default = null) {
$stmt = db()->prepare("SELECT setting_value FROM system_settings WHERE setting_key = ?");
$stmt->execute([$key]);
$row = $stmt->fetch();
return $row ? $row['setting_value'] : $default;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$account = $_POST['account'] ?? '';
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
$verify_code = $_POST['verify_code'] ?? '';
$agree = isset($_POST['agree']);
if (empty($account) || empty($password)) {
$error = 'Please fill in all fields';
} elseif ($password !== $confirm_password) {
$error = 'Passwords do not match';
} elseif ($email_verify_enabled && empty($verify_code)) {
$error = 'Email verification code is required';
} elseif (!$agree) {
$error = 'You must agree to the Terms and Privacy Policy';
} else {
if ($email_verify_enabled && $verify_code !== '123456') {
$error = 'Invalid verification code (use 123456 for demo)';
} else {
try {
$hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare("INSERT INTO users (username, email, password_hash) VALUES (?, ?, ?)");
$username = strpos($account, '@') === false ? $account : explode('@', $account)[0];
$email = strpos($account, '@') !== false ? $account : $account . '@byro.io';
$stmt->execute([$username, $email, $hash]);
$userId = db()->lastInsertId();
// Initialize balance
$stmt = db()->prepare("INSERT INTO user_balances (user_id, symbol, available) VALUES (?, 'USDT', 0)");
$stmt->execute([$userId]);
$_SESSION['user_id'] = $userId;
header('Location: /');
exit;
} catch (PDOException $e) {
$error = 'Account already exists or database error';
}
}
}
}
include __DIR__ . '/../includes/header.php';
?>
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-5">
<div class="card bg-dark border-secondary p-4 p-md-5 shadow-lg">
<div class="text-center mb-4">
<div class="logo-container d-inline-flex mb-3">
<div class="logo-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2L2 7L12 12L22 7L12 2Z" fill="white"/>
<path d="M2 17L12 22L22 17" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 12L12 17L22 12" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<span class="logo-text fs-2">Byro</span>
</div>
<h2 class="fw-bold"><?= __('register') ?></h2>
<p class="text-muted small">Create your account to start trading</p>
</div>
<?php if ($error): ?>
<div class="alert alert-danger py-2 small border-0 bg-danger bg-opacity-10 text-danger">
<i class="bi bi-exclamation-triangle me-2"></i><?= $error ?>
</div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label text-muted small"><?= __('register') ?> (Account/Email)</label>
<input type="text" name="account" class="form-control bg-black border-secondary text-white py-2" required>
</div>
<?php if ($email_verify_enabled): ?>
<div class="mb-3">
<label class="form-label text-muted small"><?= __('email_verify') ?></label>
<div class="input-group">
<input type="text" name="verify_code" class="form-control bg-black border-secondary text-white">
<button class="btn btn-outline-secondary btn-sm" type="button"><?= __('send_code') ?? 'Send Code' ?></button>
</div>
</div>
<?php endif; ?>
<div class="mb-3">
<label class="form-label text-muted small"><?= __('password') ?></label>
<input type="password" name="password" class="form-control bg-black border-secondary text-white py-2" required>
</div>
<div class="mb-3">
<label class="form-label text-muted small"><?= __('confirm_password') ?></label>
<input type="password" name="confirm_password" class="form-control bg-black border-secondary text-white py-2" required>
</div>
<div class="mb-4 form-check small">
<input type="checkbox" name="agree" class="form-check-input bg-black border-secondary" id="agreeCheck" required>
<label class="form-check-label text-muted" for="agreeCheck">
<?= __('agree_terms') ?>
</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 fw-bold mb-3"><?= __('register') ?></button>
<div class="text-center small text-muted">
Already have an account? <a href="/auth/login.php" class="text-primary text-decoration-none"><?= __('login') ?></a>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>