agent / templates /token_verification.html
samlax12's picture
Upload 25 files
20f7a0a verified
raw
history blame contribute delete
18.5 kB
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<title>访问验证 - 教育AI助手平台</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
:root {
/* 优雅的配色方案 */
--primary-color: #0f2d49;
--primary-light: #234a70;
--secondary-color: #4a6cfd;
--secondary-light: #7b91ff;
--tertiary-color: #f7f9fe;
--success-color: #10b981;
--success-light: rgba(16, 185, 129, 0.1);
--warning-color: #f59e0b;
--warning-light: rgba(245, 158, 11, 0.1);
--info-color: #0ea5e9;
--info-light: rgba(14, 165, 233, 0.1);
--danger-color: #ef4444;
--danger-light: rgba(239, 68, 68, 0.1);
--neutral-50: #f9fafb;
--neutral-100: #f3f4f6;
--neutral-200: #e5e7eb;
--neutral-300: #d1d5db;
--neutral-400: #9ca3af;
--neutral-500: #6b7280;
--neutral-600: #4b5563;
--neutral-700: #374151;
--neutral-800: #1f2937;
--neutral-900: #111827;
/* 样式变量 */
--border-radius-sm: 0.25rem;
--border-radius: 0.375rem;
--border-radius-lg: 0.5rem;
--border-radius-xl: 0.75rem;
--border-radius-2xl: 1rem;
--card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
--card-shadow-hover: 0 10px 20px rgba(0, 0, 0, 0.05), 0 6px 6px rgba(0, 0, 0, 0.1);
--card-shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
--transition-base: all 0.2s ease-in-out;
--transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
--font-family: 'Inter', 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
}
/* 基础样式 */
body {
font-family: var(--font-family);
background-color: var(--neutral-50);
color: var(--neutral-800);
margin: 0;
padding: 0;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 600;
color: var(--neutral-900);
}
.text-gradient {
background: linear-gradient(135deg, var(--secondary-color), var(--secondary-light));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
color: transparent;
}
/* 验证容器样式 */
.verification-container {
width: 100%;
max-width: 500px;
padding: 2.5rem;
background-color: white;
border-radius: var(--border-radius-xl);
box-shadow: var(--card-shadow-lg);
transition: var(--transition-smooth);
position: relative;
overflow: hidden;
}
.verification-container:hover {
box-shadow: var(--card-shadow-hover);
}
.verification-container::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 4px;
background: linear-gradient(to right, var(--secondary-color), var(--secondary-light));
border-radius: 4px 4px 0 0;
}
.verification-header {
text-align: center;
margin-bottom: 2rem;
}
.verification-header h1 {
font-size: 1.75rem;
font-weight: 700;
margin-bottom: 0.5rem;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: -0.01em;
}
.verification-header p {
color: var(--neutral-600);
margin-bottom: 0;
font-size: 0.95rem;
}
/* 加载状态 */
.loading-container {
text-align: center;
margin-bottom: 1.5rem;
}
.spinner-border {
width: 3rem;
height: 3rem;
color: var(--secondary-color);
margin-bottom: 1.5rem;
}
.loading-container h2 {
margin-bottom: 0.75rem;
font-size: 1.4rem;
color: var(--primary-color);
}
.loading-container p {
color: var(--neutral-600);
font-size: 0.95rem;
}
/* Agent信息卡片 */
.agent-info {
padding: 1.5rem;
background-color: var(--neutral-50);
border-radius: var(--border-radius-lg);
margin-bottom: 1.75rem;
border: 1px solid var(--neutral-200);
position: relative;
overflow: hidden;
transition: var(--transition-base);
}
.agent-info:hover {
border-color: var(--secondary-color);
box-shadow: 0 4px 10px rgba(74, 108, 253, 0.1);
}
.agent-info::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
background: linear-gradient(to bottom, var(--secondary-color), var(--secondary-light));
border-radius: 4px 0 0 4px;
}
.agent-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.75rem;
color: var(--primary-color);
display: flex;
align-items: center;
}
.agent-title i {
margin-right: 0.75rem;
font-size: 1.1rem;
color: var(--secondary-color);
}
.agent-description {
color: var(--neutral-700);
margin-bottom: 1rem;
font-size: 0.95rem;
line-height: 1.5;
}
.agent-meta {
display: flex;
flex-wrap: wrap;
gap: 1rem;
font-size: 0.9rem;
color: var(--neutral-600);
}
.agent-meta-item {
display: flex;
align-items: center;
}
.agent-meta-item i {
margin-right: 0.5rem;
font-size: 0.95rem;
color: var(--secondary-color);
}
/* 验证操作按钮 */
.verification-actions {
margin-bottom: 1.5rem;
}
.btn {
font-weight: 500;
padding: 0.75rem 1.25rem;
border-radius: var(--border-radius-lg);
transition: var(--transition-base);
}
.btn-primary {
background: linear-gradient(to right, var(--secondary-color), var(--secondary-light));
border: none;
color: white;
}
.btn-primary:hover, .btn-primary:focus {
background: linear-gradient(to right, var(--secondary-light), var(--secondary-color));
box-shadow: 0 4px 10px rgba(74, 108, 253, 0.3);
transform: translateY(-2px);
}
.btn-outline-secondary {
color: var(--neutral-700);
border-color: var(--neutral-300);
background-color: white;
}
.btn-outline-secondary:hover, .btn-outline-secondary:focus {
background-color: var(--neutral-100);
border-color: var(--neutral-400);
color: var(--neutral-900);
}
/* 过期/错误状态 */
.expired-container {
text-align: center;
color: var(--danger-color);
margin-bottom: 1.5rem;
}
.expired-container i {
font-size: 3rem;
margin-bottom: 1rem;
display: block;
}
.expired-container h2 {
margin-bottom: 0.75rem;
font-size: 1.5rem;
color: var(--danger-color);
}
.expired-container p {
color: var(--neutral-700);
margin-bottom: 1.5rem;
}
/* 页脚样式 */
.verification-footer {
text-align: center;
margin-top: 2rem;
color: var(--neutral-500);
font-size: 0.85rem;
}
.verification-footer a {
color: var(--secondary-color);
text-decoration: none;
transition: var(--transition-base);
}
.verification-footer a:hover {
text-decoration: underline;
color: var(--secondary-light);
}
/* 动画效果 */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.fade-in {
opacity: 0;
animation: fadeIn 0.4s ease-out forwards;
}
/* 响应式样式 */
@media (max-width: 576px) {
.verification-container {
padding: 1.5rem;
margin: 0 1rem;
}
.verification-header h1 {
font-size: 1.5rem;
}
.agent-title {
font-size: 1.15rem;
}
.agent-meta {
flex-direction: column;
gap: 0.5rem;
}
}
</style>
</head>
<body>
<div class="verification-container fade-in" id="main-container">
<div class="loading-container" id="loading-container">
<div class="spinner-border" role="status">
<span class="visually-hidden">验证中...</span>
</div>
<h2>正在验证访问权限</h2>
<p class="text-muted">请稍候,我们正在验证您的访问令牌...</p>
</div>
<div class="verification-header" id="verification-header" style="display: none;">
<h1>访问 AI 助手</h1>
<p>您正在使用访问令牌访问以下 AI 助手</p>
</div>
<div class="agent-info" id="agent-info" style="display: none;">
<!-- 将由JavaScript填充 -->
</div>
<div class="verification-actions" id="verification-actions" style="display: none;">
<div class="row g-3">
<div class="col-12">
<button class="btn btn-primary w-100" id="access-btn">
<i class="bi bi-robot me-2"></i>开始对话
</button>
</div>
<div class="col-12">
<button class="btn btn-outline-secondary w-100" id="back-btn">
<i class="bi bi-arrow-left me-2"></i>返回
</button>
</div>
</div>
</div>
<div class="expired-container" id="expired-container" style="display: none;">
<i class="bi bi-exclamation-triangle"></i>
<h2>访问令牌无效</h2>
<p>您使用的访问令牌无效或已过期,请联系教师获取新的访问令牌。</p>
<button class="btn btn-outline-secondary mt-3" id="back-btn-expired">
<i class="bi bi-arrow-left me-2"></i>返回
</button>
</div>
<div class="verification-footer" id="verification-footer" style="display: none;">
<p>教育 AI 助手平台 | <a href="/login.html">登录</a></p>
</div>
</div>
<script>
// 解析URL参数
function getUrlParams() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const pathParts = window.location.pathname.split('/');
return {
agentId: pathParts[pathParts.length - 1] || '',
token: urlParams.get('token') || ''
};
}
// 页面加载函数
document.addEventListener('DOMContentLoaded', async function() {
const { agentId, token } = getUrlParams();
if (!token) {
showExpiredState('未提供访问令牌');
return;
}
try {
// 验证令牌
const response = await fetch('/api/verify_token', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token: token,
agent_id: agentId
})
});
const result = await response.json();
if (result.success) {
// 显示Agent信息
showAgentInfo(result.agent);
} else {
showExpiredState(result.message);
}
} catch (error) {
console.error('验证出错:', error);
showExpiredState('验证过程中出错');
}
});
// 显示Agent信息
function showAgentInfo(agent) {
// 隐藏加载区域
document.getElementById('loading-container').style.display = 'none';
// 显示验证内容
document.getElementById('verification-header').style.display = 'block';
document.getElementById('agent-info').style.display = 'block';
document.getElementById('verification-actions').style.display = 'block';
document.getElementById('verification-footer').style.display = 'block';
// 填充Agent信息
const agentInfoElement = document.getElementById('agent-info');
// 构建主题和教师信息
let metaHtml = '<div class="agent-meta">';
if (agent.subject) {
metaHtml += `
<div class="agent-meta-item">
<i class="bi bi-book"></i>
${agent.subject}
</div>
`;
}
if (agent.instructor) {
metaHtml += `
<div class="agent-meta-item">
<i class="bi bi-person"></i>
${agent.instructor}
</div>
`;
}
metaHtml += '</div>';
agentInfoElement.innerHTML = `
<div class="agent-title">
<i class="bi bi-robot"></i>${agent.name}
</div>
<div class="agent-description">
${agent.description || '暂无描述'}
</div>
${metaHtml}
`;
// 设置按钮链接
document.getElementById('access-btn').addEventListener('click', function() {
const { token } = getUrlParams();
window.location.href = `/student/${agent.id}?token=${token}`;
});
document.getElementById('back-btn').addEventListener('click', function() {
// 检查是否从学生门户进入
const hasHistory = document.referrer.includes('student_portal.html');
if (hasHistory) {
window.history.back();
} else {
window.location.href = '/student_portal.html';
}
});
}
// 显示过期状态
function showExpiredState(message) {
// 隐藏加载区域
document.getElementById('loading-container').style.display = 'none';
// 显示过期内容
document.getElementById('expired-container').style.display = 'block';
document.getElementById('verification-footer').style.display = 'block';
// 更新过期消息
const expiredContainer = document.getElementById('expired-container');
expiredContainer.querySelector('p').textContent = message || '您使用的访问令牌无效或已过期,请联系教师获取新的访问令牌。';
// 设置返回按钮
document.getElementById('back-btn-expired').addEventListener('click', function() {
// 检查是否从学生门户进入
const hasHistory = document.referrer.includes('student_portal.html');
if (hasHistory) {
window.history.back();
} else {
window.location.href = '/login.html';
}
});
}
</script>
</body>
</html>