125续15l-4: 登录页'已阅用户协议'勾选门控+PHP同步签章
- login.php: token直进/密码/邮箱三路登录前加已阅协议勾选门 * rules目录无.md → 整段隐藏(不要求勾选/签章) * 已签署 → 无感登录直接跳转(原逻辑), 仅未签才停留要求签署 * 未签 → 须读完协议(滚到底部)才可勾选, 勾选时同步写签章 - api/sync.php: 新增 rules_status / rules_mark / rules_content 三action * rules_status: 返回 skipped/need_agreement/already_signed/fingerprint(协议版本指纹) * rules_mark: 写rules_ack+生成 用户协议/签收回执/<玩家>.md 签章(与Java口径对齐) * rules_content: 后台查看协议原文+已签玩家清单 - core.php: 建 rules_ack 表(player_name主键, 玩家单独记忆勾选/签署) - db_schema_mysql.sql: 同步 rules_ack 快照(utf8mb4_bin, 长文本列不写DEFAULT)
This commit is contained in:
@@ -53,6 +53,58 @@ require_once __DIR__ . '/captcha_guard.php';
|
||||
.btn-dim:hover { background: #484f58; color: var(--text); }
|
||||
.actions { display: flex; gap: 8px; justify-content: center; }
|
||||
.player-name { color: var(--green); font-weight: 600; font-size: 16px; }
|
||||
|
||||
/* ===== 用户协议勾选门控 ===== */
|
||||
.agreement-box {
|
||||
margin: 16px 0 4px; padding: 12px 14px;
|
||||
background: rgba(88,166,255,0.06); border: 1px solid var(--border);
|
||||
border-radius: 8px; text-align: left;
|
||||
}
|
||||
.agreement-box .ag-row { display: flex; align-items: flex-start; gap: 10px; }
|
||||
.agreement-box input[type=checkbox] {
|
||||
margin-top: 3px; width: 16px; height: 16px; flex-shrink: 0;
|
||||
accent-color: var(--accent); cursor: pointer;
|
||||
}
|
||||
.agreement-box .ag-text { font-size: 13px; color: var(--dim); line-height: 1.6; }
|
||||
.agreement-box .ag-text b { color: var(--text); }
|
||||
.agreement-box .ag-link {
|
||||
display: inline-block; margin-top: 6px; font-size: 12px; color: var(--accent);
|
||||
cursor: pointer; text-decoration: underline;
|
||||
}
|
||||
.agreement-box .ag-tip { font-size: 11px; color: var(--yellow); margin-top: 6px; }
|
||||
/* 阅读弹窗:滚动到底部才解锁勾选 */
|
||||
.ag-modal-mask {
|
||||
position: fixed; inset: 0; background: rgba(0,0,0,0.6);
|
||||
display: none; align-items: center; justify-content: center; z-index: 999;
|
||||
}
|
||||
.ag-modal-mask.show { display: flex; }
|
||||
.ag-modal {
|
||||
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
|
||||
width: 520px; max-width: 92%; max-height: 80vh; display: flex; flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
.ag-modal .ag-head {
|
||||
padding: 14px 18px; border-bottom: 1px solid var(--border);
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
}
|
||||
.ag-modal .ag-head h3 { margin: 0; font-size: 15px; color: var(--accent); }
|
||||
.ag-modal .ag-close { cursor: pointer; color: var(--dim); font-size: 20px; line-height: 1; }
|
||||
.ag-body {
|
||||
padding: 14px 18px; overflow-y: auto; flex: 1;
|
||||
font-size: 13px; line-height: 1.75; color: var(--text); white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.ag-foot {
|
||||
padding: 12px 18px; border-top: 1px solid var(--border);
|
||||
display: flex; justify-content: space-between; align-items: center; gap: 10px;
|
||||
}
|
||||
.ag-foot .ag-progress { font-size: 12px; color: var(--dim); }
|
||||
.ag-foot .ag-btn {
|
||||
padding: 8px 18px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 600;
|
||||
background: var(--accent); color: #fff;
|
||||
}
|
||||
.ag-foot .ag-btn:disabled { background: var(--border); color: var(--dim); cursor: not-allowed; }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -107,7 +159,34 @@ require_once __DIR__ . '/captcha_guard.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ★ 用户协议送达:勾选门控(rules 目录无协议时整段隐藏) -->
|
||||
<div id="agreementSection" class="agreement-box" style="display:none">
|
||||
<div class="ag-row">
|
||||
<input type="checkbox" id="agreementCb">
|
||||
<div class="ag-text" id="agText">
|
||||
我已阅读并同意 <b id="agTitle">用户协议</b> 的全部条款。
|
||||
<br><span class="ag-link" onclick="openAgreement()">📄 查看协议原文(须读完)</span>
|
||||
<div class="ag-tip" id="agTip" style="display:none"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 登录按钮区 -->
|
||||
<div class="actions" id="actions" style="display:none"></div>
|
||||
|
||||
<!-- ★ 协议阅读弹窗:滚到底部才能勾选 -->
|
||||
<div class="ag-modal-mask" id="agModalMask">
|
||||
<div class="ag-modal">
|
||||
<div class="ag-head">
|
||||
<h3 id="agModalTitle">服务器用户协议</h3>
|
||||
<span class="ag-close" onclick="closeAgreement()">×</span>
|
||||
</div>
|
||||
<div class="ag-body" id="agModalBody"></div>
|
||||
<div class="ag-foot">
|
||||
<span class="ag-progress" id="agProgress">尚未阅读</span>
|
||||
<button class="ag-btn" id="agModalBtn" disabled onclick="confirmAgreement()">我已完成阅读</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
@@ -135,10 +214,227 @@ require_once __DIR__ . '/captcha_guard.php';
|
||||
throw new Error('NoToken');
|
||||
}
|
||||
|
||||
// ===== 用户协议送达门控 =====
|
||||
// 语义:rules 目录无 .md → 整段隐藏(无需勾选、不要求签章);
|
||||
// 有协议 → 必须勾选"已阅"且读过弹窗(滚到底部)才能登录;已签过 → 默认勾选。
|
||||
let AG = { loaded: false, skipped: true, need: false, fingerprint: '', title: '服务器用户协议', already: false };
|
||||
let AG_READ = false; // 本次会话是否完整阅读过协议
|
||||
|
||||
// 加载协议状态(登录页打开即调)
|
||||
async function loadAgreementStatus(player) {
|
||||
try {
|
||||
const url = new URL('./api/sync.php', location.href);
|
||||
url.searchParams.set('action', 'rules_status');
|
||||
if (player) url.searchParams.set('player', player);
|
||||
const res = await fetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'} });
|
||||
const data = await res.json();
|
||||
if (data.success && data.data) {
|
||||
AG.skipped = !!data.data.skipped;
|
||||
AG.need = !AG.skipped;
|
||||
AG.fingerprint = data.data.fingerprint || '';
|
||||
AG.title = data.data.title || AG.title;
|
||||
AG.already = !!data.data.already_signed;
|
||||
} else {
|
||||
AG.skipped = true; // 接口异常时降级为跳过(不阻塞登录,避免 PHP 故障锁死用户)
|
||||
AG.need = false;
|
||||
}
|
||||
} catch (e) {
|
||||
AG.skipped = true; AG.need = false; // 网络异常降级跳过,不锁死登录
|
||||
}
|
||||
AG.loaded = true;
|
||||
applyAgreementUI();
|
||||
}
|
||||
|
||||
function applyAgreementUI() {
|
||||
const sec = document.getElementById('agreementSection');
|
||||
const cb = document.getElementById('agreementCb');
|
||||
if (!AG.loaded) return;
|
||||
if (AG.skipped) {
|
||||
sec.style.display = 'none';
|
||||
setAgreementGate(false);
|
||||
return;
|
||||
}
|
||||
sec.style.display = 'block';
|
||||
document.getElementById('agTitle').textContent = AG.title;
|
||||
if (AG.already) {
|
||||
cb.checked = true;
|
||||
AG_READ = true; // 已签过:本次会话视为已读,直接放行
|
||||
} else {
|
||||
cb.checked = false;
|
||||
AG_READ = false;
|
||||
}
|
||||
setAgreementGate(true);
|
||||
}
|
||||
|
||||
// 勾选框只在「已勾选 且 已阅读」时可勾(已签玩家自动满足)
|
||||
function setAgreementGate(on) {
|
||||
const cb = document.getElementById('agreementCb');
|
||||
const tip = document.getElementById('agTip');
|
||||
if (!on) { cb.disabled = false; tip.style.display = 'none'; syncLoginButtons(); return; }
|
||||
// 需要协议:未读且未签 → 锁勾选框,提示先阅读
|
||||
if (AG.already) { cb.disabled = false; tip.style.display = 'none'; syncLoginButtons(); return; }
|
||||
if (AG_READ) { cb.disabled = false; tip.style.display = 'none'; syncLoginButtons(); return; }
|
||||
cb.disabled = true;
|
||||
cb.checked = false;
|
||||
tip.style.display = 'block';
|
||||
tip.textContent = '请先点击上方「查看协议原文」完整阅读(滚动至底部)后,方可勾选。';
|
||||
syncLoginButtons();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// 勾选联动
|
||||
document.getElementById('agreementCb').addEventListener('change', (e) => {
|
||||
if (e.target.checked) {
|
||||
// 勾选成功 = 触发签章(PHP 同步写 rules_ack + 生成回执)
|
||||
fireAgreementMark();
|
||||
document.getElementById('agTip').style.display = 'none';
|
||||
}
|
||||
syncLoginButtons();
|
||||
});
|
||||
});
|
||||
|
||||
// 打开阅读弹窗
|
||||
function openAgreement() {
|
||||
if (!AG.need) return;
|
||||
loadAgreementContent();
|
||||
const mask = document.getElementById('agModalMask');
|
||||
mask.classList.add('show');
|
||||
const body = document.getElementById('agModalBody');
|
||||
body.scrollTop = 0;
|
||||
updateAgProgress();
|
||||
}
|
||||
function closeAgreement() {
|
||||
document.getElementById('agModalMask').classList.remove('show');
|
||||
}
|
||||
|
||||
// 拉协议原文填充弹窗
|
||||
async function loadAgreementContent() {
|
||||
const body = document.getElementById('agModalBody');
|
||||
body.textContent = '加载中...';
|
||||
try {
|
||||
const url = new URL('./api/sync.php', location.href);
|
||||
url.searchParams.set('action', 'rules_content');
|
||||
const res = await fetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'} });
|
||||
const data = await res.json();
|
||||
if (data.success && data.data && data.data.has_agreement) {
|
||||
body.textContent = data.data.content;
|
||||
document.getElementById('agModalTitle').textContent = data.data.title || AG.title;
|
||||
} else {
|
||||
body.textContent = '(服务器未配置用户协议)';
|
||||
}
|
||||
// 滚到顶部,让用户从头读
|
||||
setTimeout(() => { body.scrollTop = 0; updateAgProgress(); }, 30);
|
||||
} catch (e) {
|
||||
body.textContent = '协议加载失败:' + e.message;
|
||||
}
|
||||
}
|
||||
|
||||
// 阅读进度:滚到底部(容差 8px)→ 解锁勾选
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('agModalBody').addEventListener('scroll', updateAgProgress);
|
||||
});
|
||||
function updateAgProgress() {
|
||||
const body = document.getElementById('agModalBody');
|
||||
const prog = document.getElementById('agProgress');
|
||||
const btn = document.getElementById('agModalBtn');
|
||||
const remain = body.scrollHeight - body.clientHeight - body.scrollTop;
|
||||
if (remain <= 8) {
|
||||
AG_READ = true;
|
||||
prog.textContent = '已读至底部 ✓';
|
||||
prog.style.color = 'var(--green)';
|
||||
btn.disabled = false;
|
||||
setAgreementGate(AG.need); // 已读 → 解锁勾选框
|
||||
} else {
|
||||
prog.textContent = '请向下滚动至协议末尾';
|
||||
prog.style.color = 'var(--dim)';
|
||||
if (!AG.already) btn.disabled = true; // 已签玩家本就不需要再读
|
||||
}
|
||||
}
|
||||
|
||||
// 点「我已完成阅读」→ 关闭弹窗并自动勾选
|
||||
function confirmAgreement() {
|
||||
closeAgreement();
|
||||
const cb = document.getElementById('agreementCb');
|
||||
if (!cb.checked) {
|
||||
cb.checked = true;
|
||||
fireAgreementMark();
|
||||
document.getElementById('agTip').style.display = 'none';
|
||||
}
|
||||
syncLoginButtons();
|
||||
}
|
||||
|
||||
// 勾选时同步写签章(PHP rules_ack + 回执文件)
|
||||
let AG_MARKED = false;
|
||||
async function fireAgreementMark() {
|
||||
if (AG_MARKED) return;
|
||||
const player = document.getElementById('playerName')?.value?.trim() || '';
|
||||
if (!player) return;
|
||||
AG_MARKED = true;
|
||||
try {
|
||||
const url = new URL('./api/sync.php', location.href);
|
||||
url.searchParams.set('action', 'rules_mark');
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({player: player, fingerprint: AG.fingerprint})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!data.success) console.warn('[agreement] 签章回执:', data.message);
|
||||
} catch (e) { console.warn('[agreement] 签章失败(不阻塞登录):', e.message); }
|
||||
}
|
||||
|
||||
// 三条登录路按钮的可用性 = 协议门是否放行
|
||||
function agreementGatePass() {
|
||||
if (!AG.loaded || AG.skipped || !AG.need) return true;
|
||||
const cb = document.getElementById('agreementCb');
|
||||
return !!(cb && cb.checked);
|
||||
}
|
||||
function syncLoginButtons() {
|
||||
const pass = agreementGatePass();
|
||||
// 密码/邮箱登录按钮
|
||||
document.querySelectorAll('#loginPasswordTab .btn-primary, #loginEmailTab .btn-primary').forEach(b => {
|
||||
b.disabled = !pass;
|
||||
});
|
||||
const hint = document.getElementById('agTip');
|
||||
}
|
||||
|
||||
// 拦截:未过协议门 → 禁止发起登录
|
||||
function requireAgreement() {
|
||||
if (agreementGatePass()) return true;
|
||||
const tip = document.getElementById('agTip');
|
||||
if (tip) { tip.style.display = 'block'; tip.textContent = '请先勾选「已阅用户协议」并完成阅读。'; }
|
||||
alert('请先阅读并勾选「已阅用户协议」后再登录');
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===== 有Token → 验证Token =====
|
||||
tokenSection.style.display = 'block';
|
||||
// ★ 加载协议门控(player.php 已签过则自动勾选)
|
||||
loadAgreementStatus('');
|
||||
doTokenLogin();
|
||||
|
||||
// ===== 未签玩家:勾选门放行后点「进入 Web 端」完成跳转 =====
|
||||
function enterWeb(player) {
|
||||
// 二次校验协议门(防止用户没真正勾选就点按钮)
|
||||
if (AG.need && !AG.already) {
|
||||
if (!agreementGatePass()) {
|
||||
alert('请先完整阅读并勾选「已阅用户协议」');
|
||||
return;
|
||||
}
|
||||
}
|
||||
fireAgreementMark();
|
||||
statusBox.className = 'status-box success';
|
||||
statusBox.innerHTML = '✅ 已签署用户协议!<br><br>欢迎, <span class="player-name">' + player + '</span><br><small style="color:var(--dim)">正在跳转到玩家商城...</small>';
|
||||
fetch('./api/sync.php?action=web_access_check', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({web_token: TOKEN, access_action: 'view'})
|
||||
}).catch(() => {});
|
||||
setTimeout(() => {
|
||||
window.location.href = 'player.php?login=' + encodeURIComponent(player) + '&token=' + encodeURIComponent(TOKEN);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// ===== Token验证 =====
|
||||
async function doTokenLogin() {
|
||||
try {
|
||||
@@ -167,6 +463,24 @@ require_once __DIR__ . '/captcha_guard.php';
|
||||
localStorage.setItem('sdf1_token', TOKEN);
|
||||
localStorage.setItem('sdf1_login_time', Date.now());
|
||||
|
||||
// ★ 协议门控:先加载该玩家签署状态。
|
||||
// 语义(用户明令):已签署 → 无感登录,按原逻辑直接跳转,不拦截;
|
||||
// 仅「有协议且未签」才停留要求签署。无协议(skipped) → 同样无感放行。
|
||||
await loadAgreementStatus(player);
|
||||
const needSign = (AG.need && !AG.already);
|
||||
if (needSign) {
|
||||
// 仅未签玩家:停留 + 展示勾选门 + 「进入 Web 端」按钮
|
||||
statusBox.className = 'status-box success';
|
||||
statusBox.innerHTML = '✅ Token验证成功!<br><br>欢迎, <span class="player-name">' + player + '</span><br><small style="color:var(--yellow)">首次使用请勾选「已阅用户协议」完成签署后再进入。</small>';
|
||||
applyAgreementUI();
|
||||
document.getElementById('agreementSection').style.display = AG.need ? 'block' : 'none';
|
||||
actionsDiv.style.display = 'flex';
|
||||
actionsDiv.innerHTML = '<button class="btn btn-primary" style="width:100%" onclick="enterWeb(' + JSON.stringify(player) + ')">进入 Web 端</button>';
|
||||
return;
|
||||
}
|
||||
// ★ 已签 / 无协议 → 无感登录:直接跳转(fireAgreementMark 幂等,未签才补写)
|
||||
fireAgreementMark();
|
||||
|
||||
// ★ Token验证成功 → 直接跳转到player.php(跳过密码,token本身即身份证明)
|
||||
statusBox.className = 'status-box success';
|
||||
statusBox.innerHTML = '✅ Token验证成功!<br><br>欢迎, <span class="player-name">' + player + '</span><br><small style="color:var(--dim)">正在跳转到玩家商城...</small>';
|
||||
@@ -199,6 +513,9 @@ require_once __DIR__ . '/captcha_guard.php';
|
||||
const player = document.getElementById('playerName').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
// ★ 协议门:未签先要求签署(已签/无协议自动放行,requireAgreement 幂等)
|
||||
if (!requireAgreement()) return;
|
||||
fireAgreementMark(); // 放行后补写/确认签章(幂等)
|
||||
if (!password) { showPwdError('请输入密码'); return; }
|
||||
|
||||
// ★ 人机验证(2026-10-02):CF 渲染完即有 token(基本无感);VA 没做会在这里拉起验证
|
||||
@@ -372,6 +689,9 @@ require_once __DIR__ . '/captcha_guard.php';
|
||||
async function doEmailLogin() {
|
||||
const player = document.getElementById('playerName').value;
|
||||
const code = document.getElementById('emailCode').value.trim();
|
||||
// ★ 协议门:未签先要求签署(已签/无协议自动放行)
|
||||
if (!requireAgreement()) return;
|
||||
fireAgreementMark(); // 放行后补写/确认签章(幂等)
|
||||
if (!code) { showPwdError('请输入验证码'); return; }
|
||||
if (code.length !== 6) { showPwdError('验证码为6位数字'); return; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user