注册码 + 管理员系统:
User 模型新增 is_admin 字段
新增 InviteCode 模型(邀请码表)
注册接口必须提供有效邀请码,使用后自动标记
管理员接口:查看所有用户、启用/禁用用户、生成/删除邀请码
前端新增管理面板页面 /admin,导航栏对管理员显示入口
注册页面新增邀请码输入框
选择性超话签到:
新增 GET /api/v1/accounts/{id}/topics 接口获取超话列表
POST /signin 接口支持 {"topic_indices": [0,1,3]} 选择性签到
新增超话选择页面 /accounts/{id}/topics,支持全选/手动勾选
账号详情页新增"选择超话签到"按钮
This commit is contained in:
@@ -86,8 +86,9 @@
|
||||
<button type="submit" class="action-btn action-btn-secondary">🔍 验证 Cookie</button>
|
||||
</form>
|
||||
<form method="POST" action="{{ url_for('manual_signin', account_id=account.id) }}" onsubmit="this.querySelector('button').disabled=true; this.querySelector('button').textContent='⏳ 签到中...';">
|
||||
<button type="submit" class="action-btn action-btn-primary">🚀 立即签到</button>
|
||||
<button type="submit" class="action-btn action-btn-primary">🚀 全部签到</button>
|
||||
</form>
|
||||
<a href="{{ url_for('account_topics', account_id=account.id) }}" class="action-btn action-btn-secondary">🎯 选择超话签到</a>
|
||||
<a href="{{ url_for('add_task', account_id=account.id) }}" class="action-btn action-btn-secondary">⏰ 添加定时任务</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
115
frontend/templates/admin.html
Normal file
115
frontend/templates/admin.html
Normal file
@@ -0,0 +1,115 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}管理面板 - 微博超话签到{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
|
||||
@media (max-width: 768px) { .admin-grid { grid-template-columns: 1fr; } }
|
||||
.admin-title {
|
||||
font-size: 28px; font-weight: 700; margin-bottom: 24px;
|
||||
background: linear-gradient(135deg, #6366f1, #a855f7);
|
||||
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
|
||||
}
|
||||
.stat-row { display: flex; gap: 16px; margin-bottom: 24px; }
|
||||
.stat-card {
|
||||
flex: 1; background: rgba(255,255,255,0.9); border-radius: 16px;
|
||||
padding: 20px; text-align: center; border: 1px solid rgba(0,0,0,0.05);
|
||||
}
|
||||
.stat-num { font-size: 32px; font-weight: 700; color: #6366f1; }
|
||||
.stat-label { font-size: 13px; color: #94a3b8; margin-top: 4px; }
|
||||
.user-row, .code-row {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 14px 0; border-bottom: 1px solid #f1f5f9; font-size: 14px;
|
||||
}
|
||||
.user-row:last-child, .code-row:last-child { border-bottom: none; }
|
||||
.code-text {
|
||||
font-family: 'SF Mono', Monaco, monospace; background: #eef2ff; color: #6366f1;
|
||||
padding: 4px 12px; border-radius: 8px; font-size: 14px; font-weight: 600;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.code-used { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div style="max-width: 960px; margin: 0 auto;">
|
||||
<h1 class="admin-title">🛡️ 管理面板</h1>
|
||||
|
||||
<div class="stat-row">
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ users|length }}</div>
|
||||
<div class="stat-label">总用户数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ users|selectattr('is_active')|list|length }}</div>
|
||||
<div class="stat-label">活跃用户</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ invite_codes|rejectattr('is_used')|list|length }}</div>
|
||||
<div class="stat-label">可用邀请码</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-grid">
|
||||
<div class="card">
|
||||
<div class="card-header" style="display:flex; justify-content:space-between; align-items:center;">
|
||||
🎟️ 邀请码管理
|
||||
<form method="POST" action="{{ url_for('create_invite_code') }}" style="display:inline;">
|
||||
<button type="submit" class="btn btn-primary" style="padding:6px 16px; font-size:13px;">+ 生成邀请码</button>
|
||||
</form>
|
||||
</div>
|
||||
{% if invite_codes %}
|
||||
{% for code in invite_codes %}
|
||||
<div class="code-row">
|
||||
<div>
|
||||
<span class="code-text {{ 'code-used' if code.is_used }}">{{ code.code }}</span>
|
||||
{% if code.is_used %}
|
||||
<span style="color:#94a3b8; font-size:12px; margin-left:8px;">已使用</span>
|
||||
{% else %}
|
||||
<span style="color:#10b981; font-size:12px; margin-left:8px;">可用</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
{% if not code.is_used %}
|
||||
<form method="POST" action="{{ url_for('delete_invite_code', code_id=code.id) }}" style="display:inline;" onsubmit="return confirm('确定删除?');">
|
||||
<button type="submit" class="btn btn-danger" style="padding:4px 12px; font-size:12px;">删除</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p style="color:#94a3b8; text-align:center; padding:24px; font-size:14px;">暂无邀请码,点击上方按钮生成</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">👥 用户管理</div>
|
||||
{% for u in users %}
|
||||
<div class="user-row">
|
||||
<div>
|
||||
<span style="font-weight:600; color:#1e293b;">{{ u.username }}</span>
|
||||
{% if u.is_admin %}<span class="badge badge-info" style="margin-left:6px;">管理员</span>{% endif %}
|
||||
<div style="font-size:12px; color:#94a3b8;">{{ u.email or '-' }}</div>
|
||||
</div>
|
||||
<div style="display:flex; align-items:center; gap:8px;">
|
||||
{% if u.is_active %}
|
||||
<span class="badge badge-success">正常</span>
|
||||
{% else %}
|
||||
<span class="badge badge-danger">已禁用</span>
|
||||
{% endif %}
|
||||
{% if not u.is_admin %}
|
||||
<form method="POST" action="{{ url_for('toggle_user', user_id=u.id) }}" style="display:inline;">
|
||||
<button type="submit" class="btn {{ 'btn-danger' if u.is_active else 'btn-primary' }}" style="padding:4px 12px; font-size:12px;">
|
||||
{{ '禁用' if u.is_active else '启用' }}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -223,6 +223,9 @@
|
||||
<a href="{{ url_for('dashboard') }}" class="navbar-brand">🔥 微博超话签到</a>
|
||||
<div class="navbar-menu">
|
||||
<a href="{{ url_for('dashboard') }}">控制台</a>
|
||||
{% if session.get('user', {}).get('is_admin') %}
|
||||
<a href="{{ url_for('admin_panel') }}">🛡️ 管理</a>
|
||||
{% endif %}
|
||||
<div class="navbar-user">
|
||||
<span>👤 {{ session.get('user').get('username') }}</span>
|
||||
<a href="{{ url_for('logout') }}" class="btn-logout">退出</a>
|
||||
|
||||
@@ -55,6 +55,10 @@
|
||||
<label for="confirm_password">确认密码</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" required placeholder="再次输入密码">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="invite_code">邀请码</label>
|
||||
<input type="text" id="invite_code" name="invite_code" required placeholder="请输入邀请码">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" style="width:100%; padding:14px; font-size:16px; border-radius:16px;">注册</button>
|
||||
</form>
|
||||
<div class="auth-link">已有账号?<a href="{{ url_for('login') }}">登录</a></div>
|
||||
|
||||
139
frontend/templates/topics.html
Normal file
139
frontend/templates/topics.html
Normal file
@@ -0,0 +1,139 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}超话签到 - {{ account.remark or account.weibo_user_id }}{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
.topics-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
|
||||
.topics-header h1 { font-size: 24px; font-weight: 700; color: #1e293b; }
|
||||
.topic-list { display: flex; flex-direction: column; gap: 0; }
|
||||
.topic-item {
|
||||
display: flex; align-items: center; gap: 14px; padding: 14px 16px;
|
||||
border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: background 0.15s;
|
||||
}
|
||||
.topic-item:hover { background: #f8fafc; }
|
||||
.topic-item:last-child { border-bottom: none; }
|
||||
.topic-cb { width: 20px; height: 20px; accent-color: #6366f1; cursor: pointer; }
|
||||
.topic-name { font-weight: 500; color: #1e293b; font-size: 15px; }
|
||||
.topic-id { font-size: 12px; color: #94a3b8; font-family: monospace; }
|
||||
.select-bar {
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
padding: 16px 0; border-bottom: 1px solid #e2e8f0; margin-bottom: 8px;
|
||||
}
|
||||
.select-bar label { font-weight: 600; color: #475569; font-size: 14px; cursor: pointer; }
|
||||
.signin-btn {
|
||||
padding: 14px 32px; border-radius: 16px; border: none; font-size: 16px;
|
||||
font-weight: 600; cursor: pointer; color: white;
|
||||
background: linear-gradient(135deg, #6366f1, #818cf8);
|
||||
box-shadow: 0 2px 12px rgba(99,102,241,0.3); transition: all 0.2s;
|
||||
}
|
||||
.signin-btn:hover { box-shadow: 0 4px 20px rgba(99,102,241,0.4); transform: translateY(-1px); }
|
||||
.signin-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
|
||||
.result-box {
|
||||
margin-top: 20px; padding: 16px; border-radius: 14px; display: none;
|
||||
font-size: 14px; font-weight: 500;
|
||||
}
|
||||
.result-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
|
||||
.result-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div style="max-width: 720px; margin: 0 auto;">
|
||||
<div class="topics-header">
|
||||
<div>
|
||||
<h1>🔥 选择签到超话</h1>
|
||||
<div style="color:#94a3b8; font-size:14px; margin-top:4px;">
|
||||
{{ account.remark or account.weibo_user_id }} · 共 {{ topics|length }} 个超话
|
||||
</div>
|
||||
</div>
|
||||
<a href="{{ url_for('account_detail', account_id=account.id) }}" class="btn btn-secondary">← 返回</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
{% if topics %}
|
||||
<div class="select-bar">
|
||||
<label><input type="checkbox" id="selectAll" class="topic-cb" checked onchange="toggleAll()"> 全选 (<span id="selectedCount">{{ topics|length }}</span>/{{ topics|length }})</label>
|
||||
<button class="signin-btn" id="signinBtn" onclick="doSignin()">🚀 签到选中超话</button>
|
||||
</div>
|
||||
<div class="topic-list" id="topicList">
|
||||
{% for topic in topics %}
|
||||
<label class="topic-item">
|
||||
<input type="checkbox" class="topic-cb topic-check" data-index="{{ loop.index0 }}" checked onchange="updateCount()">
|
||||
<div>
|
||||
<div class="topic-name">{{ topic.title }}</div>
|
||||
<div class="topic-id">{{ topic.containerid }}</div>
|
||||
</div>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p style="color:#94a3b8; text-align:center; padding:40px; font-size:15px;">
|
||||
未找到关注的超话,请确认 Cookie 有效且已关注超话
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="resultBox" class="result-box"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleAll() {
|
||||
const checked = document.getElementById('selectAll').checked;
|
||||
document.querySelectorAll('.topic-check').forEach(cb => cb.checked = checked);
|
||||
updateCount();
|
||||
}
|
||||
|
||||
function updateCount() {
|
||||
const total = document.querySelectorAll('.topic-check').length;
|
||||
const checked = document.querySelectorAll('.topic-check:checked').length;
|
||||
document.getElementById('selectedCount').textContent = checked;
|
||||
document.getElementById('selectAll').checked = (checked === total);
|
||||
}
|
||||
|
||||
async function doSignin() {
|
||||
const btn = document.getElementById('signinBtn');
|
||||
const resultBox = document.getElementById('resultBox');
|
||||
const indices = [];
|
||||
document.querySelectorAll('.topic-check:checked').forEach(cb => {
|
||||
indices.push(parseInt(cb.dataset.index));
|
||||
});
|
||||
|
||||
if (indices.length === 0) {
|
||||
resultBox.className = 'result-box result-error';
|
||||
resultBox.style.display = 'block';
|
||||
resultBox.textContent = '请至少选择一个超话';
|
||||
return;
|
||||
}
|
||||
|
||||
btn.disabled = true;
|
||||
btn.textContent = '⏳ 签到中...';
|
||||
resultBox.style.display = 'none';
|
||||
|
||||
try {
|
||||
const resp = await fetch('{{ url_for("signin_selected", account_id=account.id) }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({topic_indices: indices}),
|
||||
});
|
||||
const data = await resp.json();
|
||||
|
||||
resultBox.style.display = 'block';
|
||||
if (data.success) {
|
||||
resultBox.className = 'result-box result-success';
|
||||
resultBox.textContent = data.message;
|
||||
} else {
|
||||
resultBox.className = 'result-box result-error';
|
||||
resultBox.textContent = data.message || '签到失败';
|
||||
}
|
||||
} catch (e) {
|
||||
resultBox.className = 'result-box result-error';
|
||||
resultBox.style.display = 'block';
|
||||
resultBox.textContent = '请求失败: ' + e.message;
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '🚀 签到选中超话';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user