上传文件至 /

This commit is contained in:
2025-11-30 13:06:28 +00:00
parent c56dca6129
commit 9600be072a
5 changed files with 620 additions and 0 deletions

134
register.php Normal file
View File

@@ -0,0 +1,134 @@
<?php
require_once 'config.php';
if (isset($_SESSION['user_id'])) {
header('Location: dashboard.php');
exit;
}
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
if (empty($username) || empty($email) || empty($password)) {
$error = t('fill_all_fields');
} elseif ($password !== $confirm_password) {
$error = t('password_mismatch');
} elseif (strlen($password) < 6) {
$error = t('password_length_error');
} else {
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->execute([$username, $email]);
if ($stmt->rowCount() > 0) {
$error = t('user_exists');
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$verification_code = md5(uniqid(rand(), true));
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, verification_code) VALUES (?, ?, ?, ?)");
if ($stmt->execute([$username, $email, $hashed_password, $verification_code])) {
if (sendVerificationEmail($email, $username, $verification_code)) {
$success = t('registration_success_verify');
} else {
$pdo->prepare("UPDATE users SET is_verified = 1 WHERE email = ?")->execute([$email]);
$success = t('registration_success_direct');
}
} else {
$error = t('registration_failed');
}
}
}
}
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>" data-theme="<?php echo $currentUserSettings['dark_mode'] ? 'dark' : 'light'; ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo t('register'); ?> - <?php echo SITE_NAME; ?></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'components/navbar.php'; ?>
<div class="container">
<div class="auth-container">
<div class="auth-card card">
<h2><i class="fas fa-user-plus"></i> <?php echo t('register'); ?></h2>
<?php if($error): ?>
<div class="alert alert-error">
<i class="fas fa-exclamation-triangle"></i> <?php echo $error; ?>
</div>
<?php endif; ?>
<?php if($success): ?>
<div class="alert alert-success">
<i class="fas fa-check-circle"></i> <?php echo $success; ?>
</div>
<?php endif; ?>
<?php if(empty($success)): ?>
<form method="POST" action="">
<div class="form-group">
<label for="username">
<i class="fas fa-user"></i> <?php echo t('username'); ?>
</label>
<input type="text" id="username" name="username" required
value="<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['username']) : ''; ?>"
placeholder="<?php echo t('enter_username'); ?>">
</div>
<div class="form-group">
<label for="email">
<i class="fas fa-envelope"></i> <?php echo t('email'); ?>
</label>
<input type="email" id="email" name="email" required
value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>"
placeholder="<?php echo t('enter_email'); ?>">
</div>
<div class="form-group">
<label for="password">
<i class="fas fa-lock"></i> <?php echo t('password'); ?>
</label>
<input type="password" id="password" name="password" required
placeholder="<?php echo t('enter_password'); ?>">
<small><?php echo t('password_min_length'); ?></small>
</div>
<div class="form-group">
<label for="confirm_password">
<i class="fas fa-lock"></i> <?php echo t('confirm_password'); ?>
</label>
<input type="password" id="confirm_password" name="confirm_password" required
placeholder="<?php echo t('confirm_password_placeholder'); ?>">
</div>
<button type="submit" class="btn btn-primary btn-full">
<i class="fas fa-user-plus"></i> <?php echo t('register'); ?>
</button>
</form>
<?php endif; ?>
<div class="auth-links">
<p>
<?php echo t('have_account'); ?>
<a href="login.php">
<i class="fas fa-sign-in-alt"></i> <?php echo t('login_now'); ?>
</a>
</p>
</div>
</div>
</div>
</div>
</body>
</html>