切换到本地 Tailwind CSS 构建并清理项目文件
- 移除 CDN Tailwind,改用本地构建的 style.css - 添加 package.json、tailwind.config.js、input.css 构建配置 - 清理 prd.json、progress.txt 及误创建的文件 - 修复 login.rs 中未使用变量命名 (_token → token) - 更新 .gitignore 排除 node_modules 和 package-lock.json Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c4dfd1f445
commit
0b15cc7e1c
@ -1 +0,0 @@
|
||||
/home/xfy/Developer/yggdrasil/src/db/mod.rs
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
/dist
|
||||
/.dioxus
|
||||
/.omc
|
||||
/node_modules
|
||||
/package-lock.json
|
||||
|
||||
@ -10,9 +10,9 @@ title = "Yggdrasil - Dioxus SSR"
|
||||
watch_path = ["src", "Cargo.toml"]
|
||||
|
||||
[web.resource]
|
||||
style = []
|
||||
style = ["style.css"]
|
||||
script = []
|
||||
|
||||
[web.resource.dev]
|
||||
style = []
|
||||
style = ["style.css"]
|
||||
script = []
|
||||
|
||||
3
input.css
Normal file
3
input.css
Normal file
@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
18
package.json
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "yggdrasil",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build:css": "tailwindcss -i input.css -o public/style.css --minify",
|
||||
"watch:css": "tailwindcss -i input.css -o public/style.css --watch",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"devDependencies": {
|
||||
"tailwindcss": "^3.4.19"
|
||||
}
|
||||
}
|
||||
119
prd.json
119
prd.json
@ -1,119 +0,0 @@
|
||||
{
|
||||
"project": "Blog Auth System",
|
||||
"source": "consensus plan from deep-interview + omc-plan",
|
||||
"planPath": ".omc/plans/blog-auth-consensus.md",
|
||||
"stories": [
|
||||
{
|
||||
"id": "US-001",
|
||||
"title": "数据库配置与建表",
|
||||
"description": "添加依赖、配置 deadpool 连接池、创建 PostgreSQL 用户表和 session 表",
|
||||
"acceptanceCriteria": [
|
||||
"Cargo.toml 包含所有必要依赖",
|
||||
"src/db/mod.rs 和 src/db/pool.rs 存在,使用 std::sync::LazyLock 全局初始化 deadpool",
|
||||
"migrations/001_init.sql 存在,包含 users 表、sessions 表、idx_one_admin 部分唯一索引",
|
||||
"SQL 文件可成功在 PostgreSQL 中执行"
|
||||
],
|
||||
"filesExpected": [
|
||||
"Cargo.toml",
|
||||
".env",
|
||||
"src/db/mod.rs",
|
||||
"src/db/pool.rs",
|
||||
"migrations/001_init.sql"
|
||||
],
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"id": "US-002",
|
||||
"title": "用户模型与认证模块",
|
||||
"description": "创建 User/Session 模型和认证工具函数(密码哈希、session 管理)",
|
||||
"acceptanceCriteria": [
|
||||
"src/models/user.rs 定义 User 结构体和 UserRole 枚举",
|
||||
"src/models/session.rs 定义 Session 结构体",
|
||||
"src/auth/password.rs 实现 argon2 密码哈希和验证",
|
||||
"src/auth/session.rs 实现 UUID v4 token 生成和过期检查",
|
||||
"cargo check 在此阶段无编译错误"
|
||||
],
|
||||
"filesExpected": [
|
||||
"src/models/mod.rs",
|
||||
"src/models/user.rs",
|
||||
"src/models/session.rs",
|
||||
"src/auth/mod.rs",
|
||||
"src/auth/password.rs",
|
||||
"src/auth/session.rs"
|
||||
],
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"id": "US-003",
|
||||
"title": "认证 API (Server Functions)",
|
||||
"description": "实现 register, login, logout, get_current_user 四个 Dioxus server function",
|
||||
"acceptanceCriteria": [
|
||||
"register(): 输入验证 + 首个用户 admin + 后续关闭注册",
|
||||
"login(): 验证密码 + session 创建 + token 返回",
|
||||
"logout(): session 清理",
|
||||
"get_current_user(): 查询有效 session 返回 Option<User>",
|
||||
"所有函数处理 pool.get().await 超时错误"
|
||||
],
|
||||
"filesExpected": [
|
||||
"src/api/mod.rs",
|
||||
"src/api/auth.rs"
|
||||
],
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"id": "US-004",
|
||||
"title": "前端页面 - 注册与登录",
|
||||
"description": "使用 Tailwind CSS 实现注册页和登录页,支持暗色/亮色主题",
|
||||
"acceptanceCriteria": [
|
||||
"src/pages/register.rs: 注册表单 + 前端验证 + 错误提示",
|
||||
"src/pages/login.rs: 登录表单 + cookie 设置 + 跳转",
|
||||
"src/pages/admin.rs: 认证检查 + 欢迎信息 + 登出",
|
||||
"src/theme.rs: 暗色/亮色主题切换 + localStorage 持久化",
|
||||
"Tailwind CSS CDN + dark: modifier 实现主题"
|
||||
],
|
||||
"filesExpected": [
|
||||
"src/pages/mod.rs",
|
||||
"src/pages/register.rs",
|
||||
"src/pages/login.rs",
|
||||
"src/pages/admin.rs",
|
||||
"src/theme.rs"
|
||||
],
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"id": "US-005",
|
||||
"title": "后台页面与路由整合",
|
||||
"description": "Admin页面、路由定义、session清理任务、main.rs整合",
|
||||
"acceptanceCriteria": [
|
||||
"src/router.rs: Dioxus 路由定义 (/login, /register, /admin, /)",
|
||||
"src/main.rs: 整合所有模块 + server block 启动 dotenvy + session 清理任务",
|
||||
"src/tasks/session_cleanup.rs: 每小时清理过期 session",
|
||||
"cargo check --features server 无错误",
|
||||
"cargo check --target wasm32-unknown-unknown 无错误"
|
||||
],
|
||||
"filesExpected": [
|
||||
"src/router.rs",
|
||||
"src/main.rs",
|
||||
"src/tasks/session_cleanup.rs",
|
||||
"src/tasks/mod.rs"
|
||||
],
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"id": "US-006",
|
||||
"title": "验证",
|
||||
"description": "端到端验证所有功能",
|
||||
"acceptanceCriteria": [
|
||||
"启动 PostgreSQL,运行 migration",
|
||||
"注册首个用户 -> role=admin",
|
||||
"再次注册 -> 收到 'Registration is closed'",
|
||||
"登录 -> 返回 token",
|
||||
"get_current_user (带 cookie) -> 返回用户信息",
|
||||
"错误密码 -> 显示 'Invalid credentials'",
|
||||
"Server 和 WASM 目标均编译通过"
|
||||
],
|
||||
"filesExpected": [],
|
||||
"passes": true
|
||||
}
|
||||
]
|
||||
}
|
||||
38
progress.txt
38
progress.txt
@ -1,38 +0,0 @@
|
||||
# Ralph Progress Log
|
||||
|
||||
## Session Start
|
||||
- Date: 2026-05-25
|
||||
- Source: .omc/plans/blog-auth-consensus.md
|
||||
- User requirement: 每完成一个功能,提交一次
|
||||
|
||||
## Stories
|
||||
- [x] US-001: 数据库配置与建表
|
||||
- [x] US-002: 用户模型与认证模块
|
||||
- [x] US-003: 认证 API
|
||||
- [x] US-004: 前端页面 - 注册与登录
|
||||
- [x] US-005: 后台页面与路由整合
|
||||
- [x] US-006: 验证
|
||||
|
||||
## Commits
|
||||
1. US-001: 数据库配置与建表
|
||||
2. US-002: 用户模型与认证模块
|
||||
3. US-003: 认证 API (Server Functions)
|
||||
4. US-004: 前端页面 - 注册与登录
|
||||
5. US-005: 后台页面与路由整合
|
||||
6. US-006: 验证 + 修复编译和运行时问题
|
||||
7. Fix clippy warnings
|
||||
|
||||
## Implementation Details
|
||||
- PostgreSQL + tokio-postgres + deadpool 连接池
|
||||
- argon2 密码哈希
|
||||
- UUID v4 session token + 30天过期
|
||||
- Dioxus 0.7.9 SSR Fullstack + `#[server]` 函数
|
||||
- Tailwind CSS CDN + darkMode class 主题切换
|
||||
- 首个注册用户自动 admin,后续注册关闭
|
||||
- wasm32 和 server 双目标编译
|
||||
|
||||
## Verification Results
|
||||
- cargo check (server) ✅
|
||||
- cargo check (wasm32) ✅
|
||||
- cargo clippy ✅ (warnings only)
|
||||
- API tests: register ✅, login ✅, get_current_user ✅, re-register blocked ✅, wrong password ✅
|
||||
1
public/style.css
Normal file
1
public/style.css
Normal file
File diff suppressed because one or more lines are too long
@ -19,7 +19,7 @@ pub fn LoginPage() -> Element {
|
||||
|
||||
spawn(async move {
|
||||
match login(username_val, password_val).await {
|
||||
Ok(AuthResponse { success: true, token: Some(_token), .. }) => {
|
||||
Ok(AuthResponse { success: true, token: Some(token), .. }) => {
|
||||
// 设置 cookie (client-side, not HttpOnly but works for now)
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
|
||||
@ -28,10 +28,6 @@ pub fn AppRouter() -> Element {
|
||||
rsx! {
|
||||
div {
|
||||
class: theme_class,
|
||||
script { src: "https://cdn.tailwindcss.com" }
|
||||
script {
|
||||
"tailwind.config = {{ darkMode: 'class' }}"
|
||||
}
|
||||
ThemeToggle {}
|
||||
Router::<Route> {}
|
||||
}
|
||||
|
||||
9
tailwind.config.js
Normal file
9
tailwind.config.js
Normal file
@ -0,0 +1,9 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
darkMode: 'class',
|
||||
content: ['./src/**/*.rs', './index.html'],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user