98 lines
4.1 KiB
PHP
98 lines
4.1 KiB
PHP
<?php
|
|
// 引入配置文件
|
|
require_once '../config.php';
|
|
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username']);
|
|
$email = trim($_POST['email']);
|
|
$password = $_POST['password'];
|
|
|
|
if (empty($username) || empty($email) || empty($password)) {
|
|
$error = '用户名、邮箱和密码不能为空';
|
|
} elseif (empty($_POST['agree'])) {
|
|
$error = '必须同意 APP 审核标准才能注册';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$error = '请输入有效的邮箱地址';
|
|
} else {
|
|
// 检查数据库连接是否为 PDO 对象
|
|
if (!($conn instanceof mysqli)) {
|
|
log_error('数据库连接错误: 连接不是MySQLi实例', __FILE__, __LINE__);
|
|
$error = '数据库连接错误,请检查配置';
|
|
} else {
|
|
try {
|
|
$stmt = $conn->prepare('SELECT id FROM developers WHERE username = ? OR email = ?');
|
|
$stmt->bind_param('ss', $username, $email);
|
|
$stmt->execute();
|
|
$stmt->store_result();
|
|
|
|
if ($stmt->num_rows > 0) {
|
|
$error = '用户名或邮箱已被注册';
|
|
} else {
|
|
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
|
$insertStmt = $conn->prepare('INSERT INTO developers (username, email, password) VALUES (?, ?, ?)');
|
|
if (!$insertStmt) {
|
|
log_error('插入准备失败: ' . $conn->error, __FILE__, __LINE__);
|
|
$error = '系统错误,请稍后再试';
|
|
} else {
|
|
$insertStmt->bind_param('sss', $username, $email, $hashedPassword);
|
|
if (!$insertStmt->execute()) {
|
|
log_error('插入执行失败: ' . $insertStmt->error, __FILE__, __LINE__);
|
|
$error = '系统错误,请稍后再试';
|
|
}
|
|
}
|
|
|
|
header('Location: login.php?register_success=1');
|
|
exit;
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = '注册时发生错误,请稍后再试';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>开发者注册</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
background-color: #f4f4f4;
|
|
padding: 20px 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container mt-5 col-md-4">
|
|
<h2>开发者注册</h2>
|
|
<?php if (!empty($error)): ?>
|
|
<div class="alert alert-danger" role="alert"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
<form method="post">
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label">用户名</label>
|
|
<input type="text" id="username" name="username" class="form-control" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email" class="form-label">邮箱</label>
|
|
<input type="email" id="email" name="email" class="form-control" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">密码</label>
|
|
<input type="password" id="password" name="password" class="form-control" required>
|
|
</div>
|
|
<div class="mb-3 form-check">
|
|
<input type="checkbox" class="form-check-input" id="agree" name="agree" required>
|
|
<label class="form-check-label" for="agree">我已阅读并同意 <a href="/docs/app_review_standards.php" target="_blank">APP 审核标准</a></label>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">注册</button>
|
|
</form>
|
|
</div>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|