feat: 多用户系统发布(登录/注册 + 数据隔离 + 简化前端)
This commit is contained in:
56
deploy_multiuser.sh
Normal file
56
deploy_multiuser.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
# 多用户系统 - 部署脚本
|
||||
|
||||
set -e
|
||||
|
||||
echo "======================================"
|
||||
echo "🚀 部署多用户日记系统"
|
||||
echo "======================================"
|
||||
|
||||
cd /home/ubuntu/diary-system
|
||||
|
||||
# 1. 安装依赖
|
||||
echo "📦 安装 Python 依赖..."
|
||||
cd backend
|
||||
pip3 install -r requirements.txt -q 2>/dev/null || pip3 install -r requirements.txt --break-system-packages -q
|
||||
|
||||
# 2. 数据库迁移
|
||||
echo "🗄️ 执行数据库迁移..."
|
||||
python3 manage.py migrate --run-syncdb
|
||||
|
||||
# 3. 迁移现有数据到默认用户
|
||||
echo "📦 迁移现有数据..."
|
||||
python3 ../migrate_data.py
|
||||
|
||||
# 4. 重启 Gunicorn
|
||||
echo "⚙️ 重启 Gunicorn..."
|
||||
sudo systemctl restart diary-system
|
||||
|
||||
# 5. 检查服务状态
|
||||
echo ""
|
||||
echo "🔍 检查服务状态..."
|
||||
sudo systemctl is-active diary-system > /dev/null && echo " ✅ Gunicorn 运行中" || echo " ❌ Gunicorn 未运行"
|
||||
|
||||
# 6. 测试访问
|
||||
echo ""
|
||||
echo "🧪 测试访问..."
|
||||
sleep 2
|
||||
if curl -s http://127.0.0.1:8002/api/auth/me/ > /dev/null 2>&1; then
|
||||
echo " ✅ 认证 API 正常"
|
||||
else
|
||||
echo " ⚠️ 认证 API 可能有问题"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "======================================"
|
||||
echo "✅ 部署完成!"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
echo "📍 访问地址:http://cssc.datalibstar.com:8001/"
|
||||
echo ""
|
||||
echo "📝 默认用户:"
|
||||
echo " 用户名:beijixing"
|
||||
echo " 密码:beijixing123"
|
||||
echo ""
|
||||
echo "💡 其他用户可以注册新账号使用"
|
||||
echo ""
|
||||
14
frontend-react/public/index.html
Normal file
14
frontend-react/public/index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#667eea" />
|
||||
<meta name="description" content="码神的日记系统 - 记录每天的进步与成长" />
|
||||
<title>码神的日记系统</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>需要启用 JavaScript 才能运行此应用。</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
125
frontend/dashboard.html
Normal file
125
frontend/dashboard.html
Normal file
@@ -0,0 +1,125 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>码神的日记系统 - 仪表盘</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
.container { max-width: 1200px; margin: 0 auto; }
|
||||
header {
|
||||
text-align: center;
|
||||
color: white;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
header h1 { font-size: 2.5em; margin-bottom: 10px; }
|
||||
.user-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: white;
|
||||
padding: 15px 20px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.logout-btn {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.logout-btn:hover { background: #5568d3; }
|
||||
.content {
|
||||
background: white;
|
||||
padding: 40px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
.content h2 { color: #333; margin-bottom: 20px; }
|
||||
.content p { color: #666; margin-bottom: 30px; }
|
||||
.feature-list {
|
||||
text-align: left;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.feature-item {
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
background: #f8f9fa;
|
||||
border-radius: 5px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>⚡ 码神的日记系统</h1>
|
||||
<p>记录每天的进步与成长</p>
|
||||
</header>
|
||||
|
||||
<div class="user-info">
|
||||
<span>👤 欢迎,<strong id="username">用户</strong></span>
|
||||
<button class="logout-btn" onclick="logout()">登出</button>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<h2>🎉 多用户系统已上线!</h2>
|
||||
<p>你现在可以:</p>
|
||||
<div class="feature-list">
|
||||
<div class="feature-item">
|
||||
<strong>📝 写日记</strong> - 记录每天的任务、学到的东西、反思和进步
|
||||
</div>
|
||||
<div class="feature-item">
|
||||
<strong>📅 日历视图</strong> - 通过日历快速查看历史日记
|
||||
</div>
|
||||
<div class="feature-item">
|
||||
<strong>💡 经验总结</strong> - 记录遇到的问题和解决方案
|
||||
</div>
|
||||
<div class="feature-item">
|
||||
<strong>📊 任务管理</strong> - 追踪任务进展和完成率
|
||||
</div>
|
||||
<div class="feature-item">
|
||||
<strong>🔒 数据隔离</strong> - 每个用户的数据完全独立
|
||||
</div>
|
||||
</div>
|
||||
<p style="margin-top: 30px; color: #999;">
|
||||
React 前端正在构建中,当前使用简化版界面<br>
|
||||
完整功能即将上线...
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 检查登录状态
|
||||
fetch('/api/auth/me/')
|
||||
.then(res => {
|
||||
if (!res.ok) {
|
||||
window.location.href = '/';
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.then(data => {
|
||||
document.getElementById('username').textContent = data.username;
|
||||
})
|
||||
.catch(() => {
|
||||
window.location.href = '/';
|
||||
});
|
||||
|
||||
function logout() {
|
||||
fetch('/api/auth/logout/', { method: 'POST' })
|
||||
.then(() => {
|
||||
window.location.href = '/';
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
149
frontend/login.html
Normal file
149
frontend/login.html
Normal file
@@ -0,0 +1,149 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>码神的日记系统 - 登录</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
.auth-card {
|
||||
background: white;
|
||||
padding: 40px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
.auth-card h1 {
|
||||
color: #667eea;
|
||||
font-size: 2em;
|
||||
text-align: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.auth-card h2 {
|
||||
color: #333;
|
||||
font-size: 1.5em;
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
color: #555;
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 1em;
|
||||
}
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
.btn-primary {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.error {
|
||||
background: #fee;
|
||||
color: #c00;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.success {
|
||||
background: #efe;
|
||||
color: #0a0;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-card">
|
||||
<h1>⚡ 码神的日记系统</h1>
|
||||
<h2>登录</h2>
|
||||
|
||||
<div id="message"></div>
|
||||
|
||||
<form id="loginForm">
|
||||
<div class="form-group">
|
||||
<label>用户名</label>
|
||||
<input type="text" id="username" required placeholder="请输入用户名" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>密码</label>
|
||||
<input type="password" id="password" required placeholder="请输入密码" />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-primary">登录</button>
|
||||
</form>
|
||||
|
||||
<p style="text-align: center; margin-top: 20px; color: #666;">
|
||||
默认账号:beijixing / beijixing123
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = '/api';
|
||||
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const messageDiv = document.getElementById('message');
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/auth/login/`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
messageDiv.innerHTML = `<div class="success">✅ 登录成功!正在跳转...</div>`;
|
||||
setTimeout(() => {
|
||||
window.location.href = '/dashboard.html';
|
||||
}, 1000);
|
||||
} else {
|
||||
messageDiv.innerHTML = `<div class="error">❌ ${data.message || '登录失败'}</div>`;
|
||||
}
|
||||
} catch (err) {
|
||||
messageDiv.innerHTML = `<div class="error">❌ 网络错误:${err.message}</div>`;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user