|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
<title>VvvebJs 身份验证测试</title>
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
<style>
|
|
|
.status-ok { color: #28a745; }
|
|
|
.status-error { color: #dc3545; }
|
|
|
.status-warning { color: #ffc107; }
|
|
|
.debug-info { background: #f8f9fa; padding: 15px; border-radius: 5px; font-family: monospace; font-size: 12px; }
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="container mt-5">
|
|
|
<div class="row">
|
|
|
<div class="col-md-8 mx-auto">
|
|
|
<h1 class="mb-4">🔐 VvvebJs 身份验证测试</h1>
|
|
|
|
|
|
<div class="card mb-4">
|
|
|
<div class="card-header">
|
|
|
<h3>身份验证状态检查</h3>
|
|
|
</div>
|
|
|
<div class="card-body">
|
|
|
<div id="authStatus">
|
|
|
<div class="text-center">
|
|
|
<div class="spinner-border" role="status">
|
|
|
<span class="visually-hidden">检查中...</span>
|
|
|
</div>
|
|
|
<p class="mt-2">正在检查身份验证状态...</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div id="testResults" style="display: none;">
|
|
|
<h5>测试结果</h5>
|
|
|
<div class="debug-info" id="debugInfo"></div>
|
|
|
</div>
|
|
|
|
|
|
<div class="mt-3">
|
|
|
<button class="btn btn-primary" onclick="testAuth()">🔄 重新测试</button>
|
|
|
<button class="btn btn-warning" onclick="testSave()">🚀 测试保存</button>
|
|
|
<a href="index.html" class="btn btn-secondary">🏠 返回登录页</a>
|
|
|
<a href="editor.html" class="btn btn-success">📝 返回编辑器</a>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="card">
|
|
|
<div class="card-header">
|
|
|
<h3>保存测试</h3>
|
|
|
</div>
|
|
|
<div class="card-body">
|
|
|
<div id="saveTestResults">
|
|
|
<p>点击 "测试保存" 按钮来测试文件保存功能</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
// 页面加载时自动检查身份验证
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
testAuth();
|
|
|
});
|
|
|
|
|
|
function testAuth() {
|
|
|
const statusDiv = document.getElementById('authStatus');
|
|
|
const resultsDiv = document.getElementById('testResults');
|
|
|
const debugDiv = document.getElementById('debugInfo');
|
|
|
|
|
|
statusDiv.innerHTML = `
|
|
|
<div class="text-center">
|
|
|
<div class="spinner-border" role="status">
|
|
|
<span class="visually-hidden">检查中...</span>
|
|
|
</div>
|
|
|
<p class="mt-2">正在检查身份验证状态...</p>
|
|
|
</div>
|
|
|
`;
|
|
|
|
|
|
fetch('save.php?action=checkAuth')
|
|
|
.then(response => {
|
|
|
console.log('Auth check response status:', response.status);
|
|
|
return response.json();
|
|
|
})
|
|
|
.then(data => {
|
|
|
console.log('Auth check data:', data);
|
|
|
|
|
|
if (data.authenticated) {
|
|
|
statusDiv.innerHTML = `
|
|
|
<div class="alert alert-success">
|
|
|
<h5 class="status-ok">✅ 身份验证成功</h5>
|
|
|
<p><strong>用户:</strong> ${data.user || '未知'}</p>
|
|
|
<p>你已成功登录,可以使用VvvebJs编辑器的所有功能。</p>
|
|
|
</div>
|
|
|
`;
|
|
|
} else {
|
|
|
statusDiv.innerHTML = `
|
|
|
<div class="alert alert-danger">
|
|
|
<h5 class="status-error">❌ 身份验证失败</h5>
|
|
|
<p>你当前未登录,需要先登录才能使用编辑器功能。</p>
|
|
|
<a href="index.html" class="btn btn-primary">前往登录</a>
|
|
|
</div>
|
|
|
`;
|
|
|
}
|
|
|
|
|
|
debugDiv.textContent = JSON.stringify(data, null, 2);
|
|
|
resultsDiv.style.display = 'block';
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('Auth check error:', error);
|
|
|
statusDiv.innerHTML = `
|
|
|
<div class="alert alert-danger">
|
|
|
<h5 class="status-error">❌ 检查失败</h5>
|
|
|
<p>无法检查身份验证状态: ${error.message}</p>
|
|
|
</div>
|
|
|
`;
|
|
|
|
|
|
debugDiv.textContent = 'Error: ' + error.message;
|
|
|
resultsDiv.style.display = 'block';
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function testSave() {
|
|
|
const saveResultsDiv = document.getElementById('saveTestResults');
|
|
|
|
|
|
saveResultsDiv.innerHTML = `
|
|
|
<div class="text-center">
|
|
|
<div class="spinner-border" role="status">
|
|
|
<span class="visually-hidden">测试中...</span>
|
|
|
</div>
|
|
|
<p class="mt-2">正在测试保存功能...</p>
|
|
|
</div>
|
|
|
`;
|
|
|
|
|
|
const testHtml = `<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>VvvebJs Auth Test</title>
|
|
|
</head>
|
|
|
<body>
|
|
|
<h1>认证测试文件</h1>
|
|
|
<p>创建时间: ${new Date().toISOString()}</p>
|
|
|
<p>如果你能看到这个文件,说明身份验证和保存功能都正常工作。</p>
|
|
|
</body>
|
|
|
</html>`;
|
|
|
|
|
|
const formData = new FormData();
|
|
|
formData.append('html', testHtml);
|
|
|
formData.append('file', 'auth-test-' + Date.now() + '.html');
|
|
|
|
|
|
fetch('save.php', {
|
|
|
method: 'POST',
|
|
|
body: formData,
|
|
|
headers: {
|
|
|
'X-Requested-With': 'XMLHttpRequest'
|
|
|
}
|
|
|
})
|
|
|
.then(response => {
|
|
|
console.log('Save test response status:', response.status);
|
|
|
return response.json();
|
|
|
})
|
|
|
.then(data => {
|
|
|
console.log('Save test data:', data);
|
|
|
|
|
|
if (data.success) {
|
|
|
saveResultsDiv.innerHTML = `
|
|
|
<div class="alert alert-success">
|
|
|
<h5 class="status-ok">✅ 保存测试成功</h5>
|
|
|
<p><strong>文件:</strong> ${data.file}</p>
|
|
|
<p><strong>外部存储:</strong> ${data.external_storage ? '✅ 成功' : '❌ 失败'}</p>
|
|
|
<p><strong>本地缓存:</strong> ${data.local_cache ? '✅ 成功' : '❌ 失败'}</p>
|
|
|
<p><strong>用户:</strong> ${data.user}</p>
|
|
|
</div>
|
|
|
<div class="debug-info">
|
|
|
${JSON.stringify(data, null, 2)}
|
|
|
</div>
|
|
|
`;
|
|
|
} else {
|
|
|
saveResultsDiv.innerHTML = `
|
|
|
<div class="alert alert-danger">
|
|
|
<h5 class="status-error">❌ 保存测试失败</h5>
|
|
|
<p><strong>错误:</strong> ${data.message}</p>
|
|
|
${data.external_error ? '<p><strong>外部错误:</strong> ' + data.external_error + '</p>' : ''}
|
|
|
</div>
|
|
|
<div class="debug-info">
|
|
|
${JSON.stringify(data, null, 2)}
|
|
|
</div>
|
|
|
`;
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('Save test error:', error);
|
|
|
saveResultsDiv.innerHTML = `
|
|
|
<div class="alert alert-danger">
|
|
|
<h5 class="status-error">❌ 保存测试异常</h5>
|
|
|
<p>请求失败: ${error.message}</p>
|
|
|
</div>
|
|
|
`;
|
|
|
});
|
|
|
}
|
|
|
</script>
|
|
|
</body>
|
|
|
</html> |