上传文件至 /
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 沈石磊(上海科技管理学校)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
64
index.php
Normal file
64
index.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_layout.php';
|
||||||
|
|
||||||
|
// 已登录直接跳走,避免重复登录
|
||||||
|
$user = current_user($conn);
|
||||||
|
if ($user) {
|
||||||
|
header($user['is_admin'] ? 'Location: admin.php' : 'Location: gallery.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$error = '';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$username = trim($_POST['username'] ?? '');
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("SELECT user_id, username, password, active, is_admin FROM photo_users WHERE username = ?");
|
||||||
|
$stmt->bind_param("s", $username);
|
||||||
|
$stmt->execute();
|
||||||
|
$row = $stmt->get_result()->fetch_assoc();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
$error = '用户名或密码错误。';
|
||||||
|
} elseif ((int)$row['active'] === 0) {
|
||||||
|
$error = '账号已被禁用,请联系管理员。';
|
||||||
|
} elseif (!password_verify($password, $row['password'])) {
|
||||||
|
$error = '用户名或密码错误。';
|
||||||
|
} else {
|
||||||
|
session_regenerate_id(true);
|
||||||
|
$_SESSION['loggedin'] = true;
|
||||||
|
$_SESSION['user_id'] = (int)$row['user_id'];
|
||||||
|
$_SESSION['user_name'] = $row['username'];
|
||||||
|
$_SESSION['is_admin'] = (bool)$row['is_admin'];
|
||||||
|
start_login($conn, (int)$row['user_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render_auth_header('登录', '', 'square.php');
|
||||||
|
?>
|
||||||
|
<h2 class="auth__title">欢迎回来</h2>
|
||||||
|
<p class="auth__sub">登录后即可管理你的私人相册</p>
|
||||||
|
<?php if ($f = flash_take()): ?>
|
||||||
|
<div class="alert alert--success"><?php echo icon('check'); ?><span><?php echo h($f['msg']); ?></span></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert--danger"><?php echo icon('warn'); ?><span><?php echo h($error); ?></span></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form method="post" autocomplete="on">
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="username">用户名</label>
|
||||||
|
<input class="input" type="text" id="username" name="username" autocomplete="username" placeholder="输入用户名" required autofocus>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="password">密码</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input class="input" type="password" id="password" name="password" autocomplete="current-password" placeholder="输入密码" required>
|
||||||
|
<button type="button" class="btn btn--ghost btn--icon" data-toggle-password="password" aria-label="显示密码"><?php echo icon('eye'); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn--primary btn--lg btn--block">登录</button>
|
||||||
|
</form>
|
||||||
|
<p class="auth__foot">还没有账号?<a href="register.php">使用邀请码注册</a></p>
|
||||||
|
<p class="auth__foot" style="margin-top:.5rem"><a href="square.php"><?php echo icon('globe', 14); ?> 先逛逛照片广场(公开)</a></p>
|
||||||
|
<?php render_auth_footer();
|
||||||
11
logout.php
Normal file
11
logout.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth.php';
|
||||||
|
|
||||||
|
$_SESSION = [];
|
||||||
|
if (ini_get('session.use_cookies')) {
|
||||||
|
$p = session_get_cookie_params();
|
||||||
|
setcookie(session_name(), '', time() - 42000, $p['path'], $p['domain'], $p['secure'], $p['httponly']);
|
||||||
|
}
|
||||||
|
session_destroy();
|
||||||
|
header('Location: index.php');
|
||||||
|
exit;
|
||||||
37
migrate-v3.sql
Normal file
37
migrate-v3.sql
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
-- person-photo v3.0 迁移:头像、站点显示名、照片广场
|
||||||
|
-- 幂等:可重复执行;MySQL 8.0 / MariaDB 10.6 均可跑。
|
||||||
|
-- 用法:mysql -u root -p person_photo < migrate-v3.sql
|
||||||
|
-- 回滚:备份在部署前生成,见 README「升级到 v3.0」
|
||||||
|
|
||||||
|
-- 1. photo_users 增加 display_name / avatar
|
||||||
|
SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'photo_users' AND COLUMN_NAME = 'display_name');
|
||||||
|
SET @s := IF(@c = 0,
|
||||||
|
'ALTER TABLE photo_users ADD COLUMN display_name VARCHAR(50) NOT NULL DEFAULT '''' COMMENT ''站点展示名,空则回退 nick_name'' AFTER nick_name',
|
||||||
|
'DO 0');
|
||||||
|
PREPARE st FROM @s; EXECUTE st; DEALLOCATE PREPARE st;
|
||||||
|
|
||||||
|
SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'photo_users' AND COLUMN_NAME = 'avatar');
|
||||||
|
SET @s := IF(@c = 0,
|
||||||
|
'ALTER TABLE photo_users ADD COLUMN avatar VARCHAR(512) DEFAULT NULL COMMENT ''头像相对路径'' AFTER display_name',
|
||||||
|
'DO 0');
|
||||||
|
PREPARE st FROM @s; EXECUTE st; DEALLOCATE PREPARE st;
|
||||||
|
|
||||||
|
-- 2. 照片广场表
|
||||||
|
CREATE TABLE IF NOT EXISTS photos_square (
|
||||||
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
image_id INT UNSIGNED NOT NULL COMMENT '来源图片 images.image_id',
|
||||||
|
user_id INT UNSIGNED NOT NULL COMMENT '推送人',
|
||||||
|
title VARCHAR(120) NOT NULL DEFAULT '' COMMENT '广场标题,可空',
|
||||||
|
status ENUM('pending','approved','rejected') NOT NULL DEFAULT 'pending',
|
||||||
|
reject_reason VARCHAR(200) NOT NULL DEFAULT '',
|
||||||
|
submitted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
reviewed_at DATETIME DEFAULT NULL,
|
||||||
|
reviewed_by INT UNSIGNED DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
KEY idx_status (status, submitted_at),
|
||||||
|
KEY idx_user (user_id),
|
||||||
|
CONSTRAINT fk_square_image FOREIGN KEY (image_id) REFERENCES images(image_id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_square_user FOREIGN KEY (user_id) REFERENCES photo_users(user_id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='照片广场(审核制)';
|
||||||
74
migrate-v4.sql
Normal file
74
migrate-v4.sql
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
-- person-photo v3.3 迁移:账号策略 + 用户分组 + 广场分区
|
||||||
|
-- 幂等:可重复执行;MySQL 8.0 / MariaDB 10.6 均可跑。
|
||||||
|
-- 用法:mysql -u root -p person_photo < migrate-v4.sql
|
||||||
|
-- 回滚:见 README「升级到 v3.3」(删表 + 删列即可,旧数据不受影响)
|
||||||
|
|
||||||
|
-- 1. photo_users:改密策略
|
||||||
|
-- must_change_password=1 表示下次登录必须先改成规定复杂度的新密码(管理员建号时勾选)
|
||||||
|
-- password_locked=1 表示密码永不允许用户自行修改(管理员统一下发)
|
||||||
|
SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'photo_users' AND COLUMN_NAME = 'must_change_password');
|
||||||
|
SET @s := IF(@c = 0,
|
||||||
|
'ALTER TABLE photo_users ADD COLUMN must_change_password TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''1=下次登录必须先改密码'' AFTER active',
|
||||||
|
'DO 0');
|
||||||
|
PREPARE st FROM @s; EXECUTE st; DEALLOCATE PREPARE st;
|
||||||
|
|
||||||
|
SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'photo_users' AND COLUMN_NAME = 'password_locked');
|
||||||
|
SET @s := IF(@c = 0,
|
||||||
|
'ALTER TABLE photo_users ADD COLUMN password_locked TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''1=密码锁定,用户不可自行修改'' AFTER must_change_password',
|
||||||
|
'DO 0');
|
||||||
|
PREPARE st FROM @s; EXECUTE st; DEALLOCATE PREPARE st;
|
||||||
|
|
||||||
|
-- 2. 用户分组
|
||||||
|
CREATE TABLE IF NOT EXISTS photo_groups (
|
||||||
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
name VARCHAR(50) NOT NULL COMMENT '分组名,后台展示用',
|
||||||
|
remark VARCHAR(200) NOT NULL DEFAULT '' COMMENT '备注',
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY uk_name (name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户分组';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS photo_group_members (
|
||||||
|
group_id INT UNSIGNED NOT NULL,
|
||||||
|
user_id INT UNSIGNED NOT NULL,
|
||||||
|
PRIMARY KEY (group_id, user_id),
|
||||||
|
KEY idx_user (user_id),
|
||||||
|
CONSTRAINT fk_gm_group FOREIGN KEY (group_id) REFERENCES photo_groups(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_gm_user FOREIGN KEY (user_id) REFERENCES photo_users(user_id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='分组成员';
|
||||||
|
|
||||||
|
-- 3. 广场分区
|
||||||
|
-- visibility: public=匿名可看 / member=登录用户可看 / group=仅指定分组可看
|
||||||
|
CREATE TABLE IF NOT EXISTS photo_zones (
|
||||||
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
name VARCHAR(50) NOT NULL,
|
||||||
|
description VARCHAR(200) NOT NULL DEFAULT '',
|
||||||
|
visibility ENUM('public','member','group') NOT NULL DEFAULT 'public',
|
||||||
|
sort_order INT NOT NULL DEFAULT 0,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY uk_zone_name (name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='广场分区';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS photo_zone_groups (
|
||||||
|
zone_id INT UNSIGNED NOT NULL,
|
||||||
|
group_id INT UNSIGNED NOT NULL,
|
||||||
|
PRIMARY KEY (zone_id, group_id),
|
||||||
|
CONSTRAINT fk_zg_zone FOREIGN KEY (zone_id) REFERENCES photo_zones(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_zg_group FOREIGN KEY (group_id) REFERENCES photo_groups(id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='分区可看分组';
|
||||||
|
|
||||||
|
-- 4. photos_square 挂分区(可空:空 = 默认分区「全部」)
|
||||||
|
SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'photos_square' AND COLUMN_NAME = 'zone_id');
|
||||||
|
SET @s := IF(@c = 0,
|
||||||
|
'ALTER TABLE photos_square ADD COLUMN zone_id INT UNSIGNED DEFAULT NULL COMMENT ''所属分区,NULL=默认分区'' AFTER user_id, ADD KEY idx_zone (zone_id)',
|
||||||
|
'DO 0');
|
||||||
|
PREPARE st FROM @s; EXECUTE st; DEALLOCATE PREPARE st;
|
||||||
|
|
||||||
|
-- 5. 默认分区:已有的已审内容全部归到这里,保持"所有登录/匿名都能看"的现状不变
|
||||||
|
INSERT INTO photo_zones (name, description, visibility, sort_order)
|
||||||
|
SELECT '综合广场', '默认分区,公开可见', 'public', 0
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM photo_zones);
|
||||||
Reference in New Issue
Block a user