diff --git a/change_password.php b/change_password.php new file mode 100644 index 0000000..d347edd --- /dev/null +++ b/change_password.php @@ -0,0 +1,114 @@ += 8 && strlen($pw) <= 64 + && preg_match('/[A-Za-z]/', $pw) && preg_match('/\d/', $pw) + && preg_match('/^[\x21-\x7e]+$/', $pw); // 可打印 ASCII,禁空格/中文 +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_password']) && !$locked) { + if (!csrf_ok()) { + $message = '请求校验失败,请刷新页面重试。'; + } else { + $current = $_POST['current_password'] ?? ''; + $new = $_POST['new_password'] ?? ''; + + if (!strong_password_ok($new)) { + $message = $password_rule . '。'; + } elseif ($new === $current) { + $message = '新密码不能与当前密码相同。'; + } else { + $stmt = $conn->prepare("SELECT password FROM photo_users WHERE user_id = ?"); + $stmt->bind_param("i", $user['user_id']); + $stmt->execute(); + $hash = $stmt->get_result()->fetch_assoc()['password'] ?? ''; + $stmt->close(); + + if (!password_verify($current, $hash)) { + $message = '当前密码错误。'; + } else { + $newHash = password_hash($new, PASSWORD_DEFAULT); + $upd = $conn->prepare("UPDATE photo_users SET password = ?, must_change_password = 0 WHERE user_id = ?"); + $upd->bind_param("si", $newHash, $user['user_id']); + $ok = $upd->execute(); + $upd->close(); + $message = $ok ? '密码已修改成功。' : '修改失败,请稍后再试。'; + if ($ok && $forced) { + $_SESSION['login_pending_pwd'] = false; + flash_set('success', '密码已更新,欢迎使用'); + header($user['is_admin'] ? 'Location: admin.php' : 'Location: gallery.php'); + exit; + } + } + } + } +} + +render_header('修改密码', $user, 'change_password.php', '账号安全'); +?> +
+
+
+
+ + 管理员已锁定此账号的密码,如需修改请联系管理员。 + + 这是管理员为你设置的初始密码,改成你自己的密码后才能继续使用。 + + 定期更换密码,保护你的相册安全 + +
+
+
+ +
+
+ +
+ +
+ + +
+ 密码已锁定,无法自行修改。需要新密码请让管理员重置。 +
+ 退出登录 + +
+ +
+ + +
+
+ +
+ + +
+
+
+
+ + + 返回 + +
+ +

不想现在改?退出登录

+ +
+ +
+
+connect_error) { + // 不要把连接细节抛给浏览器,只记服务端日志 + error_log('DB connect failed: ' . $conn->connect_error); + http_response_code(500); + die('数据库暂不可用,请联系管理员。'); +} + +$conn->set_charset('utf8mb4'); diff --git a/delete_image.php b/delete_image.php new file mode 100644 index 0000000..5d7521a --- /dev/null +++ b/delete_image.php @@ -0,0 +1,75 @@ + false, 'msg' => '登录已失效,请重新登录']); + exit; +} +if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !csrf_ok()) { + http_response_code(400); + echo json_encode(['ok' => false, 'msg' => '请求校验失败']); + exit; +} + +$raw = $_POST['ids'] ?? ($_POST['id'] ?? ''); +$ids = array_values(array_unique(array_filter( + array_map('intval', explode(',', (string)$raw)), + fn($v) => $v > 0 +))); +if (!$ids) { + echo json_encode(['ok' => false, 'msg' => '未选择图片']); + exit; +} + +$placeholders = implode(',', array_fill(0, count($ids), '?')); +$types = str_repeat('i', count($ids)) . 'i'; +$args = array_merge($ids, [$user['user_id']]); + +$stmt = $conn->prepare("SELECT image_id, image_path FROM images WHERE image_id IN ($placeholders) AND user_id = ?"); +$stmt->bind_param($types, ...$args); +$stmt->execute(); +$rows = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); +$stmt->close(); + +$deleted = 0; +foreach ($rows as $row) { + $d = $conn->prepare("DELETE FROM images WHERE image_id = ? AND user_id = ?"); + $d->bind_param("ii", $row['image_id'], $user['user_id']); + $d->execute(); + $hit = $d->affected_rows; + $deleted += $hit; + $d->close(); + + if ($hit > 0) { + // 图片若在广场,级联删除(FK ON DELETE CASCADE);显式删一次让意图一目了然 + $sq = $conn->prepare("DELETE FROM photos_square WHERE image_id = ?"); + $sq->bind_param("i", $row['image_id']); + $sq->execute(); + $sq->close(); + + $uploads_dir = realpath(__DIR__ . '/uploads'); + $full = realpath(__DIR__ . '/' . $row['image_path']); + if ($full && $uploads_dir && strpos($full, $uploads_dir) === 0 && is_file($full)) { + @unlink($full); + } + } +} + +$refunded = 0; +if ($deleted > 0) { + $refunded = $deleted; + $u = $conn->prepare("UPDATE photo_users SET points = points + ? WHERE user_id = ?"); + $u->bind_param("ii", $refunded, $user['user_id']); + $u->execute(); + $u->close(); +} + +echo json_encode([ + 'ok' => true, + 'deleted' => $deleted, + 'refunded' => $refunded, + 'points' => $user['points'] + $refunded, +], JSON_UNESCAPED_UNICODE); diff --git a/gallery.php b/gallery.php new file mode 100644 index 0000000..d7afa4a --- /dev/null +++ b/gallery.php @@ -0,0 +1,338 @@ +prepare("SELECT i.image_id, i.image_path, sq.status AS square_status, sq.zone_id AS square_zone, sq.title AS square_title + FROM images i LEFT JOIN photos_square sq ON sq.image_id = i.image_id + WHERE i.user_id = ? AND i.is_deleted = 0 ORDER BY i.image_id DESC"); +$stmt->bind_param("i", $user['user_id']); +$stmt->execute(); +$images = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); +$stmt->close(); +$count = count($images); +$points = (int)$user['points']; + +render_header('我的图库', $user, 'gallery.php', '共 ' . $count . ' 张图片'); +?> +
+
+
我的图库
+
剩余可上传 张 · 点击图片查看大图
+
+
+ 上传新图片 +
+
+ + +
+
+
还没有上传任何图片
+
上传第一张照片,开始建立你的私人相册。
+ 上传第一张 +
+ +
+ + '审核中', 'approved' => '广场已上架', 'rejected' => '广场被驳回'][$sq] ?? ''; + $sq_badge = ['pending' => 'warning', 'approved' => 'success', 'rejected' => 'danger'][$sq] ?? ''; ?> +
+ 图片 + + + + + + + +
+ +
+ + +
+ 已选 0 张 + + +
+ + + + + + +