agent / templates /login.html
samlax12's picture
Update templates/login.html
ba1c27f verified
<!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;
}
/* 登录容器样式 */
.login-container {
width: 100%;
max-width: 450px;
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;
}
.login-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;
}
.login-header {
text-align: center;
margin-bottom: 2.5rem;
}
.login-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;
}
.login-header p {
color: var(--neutral-600);
margin-bottom: 0;
font-size: 0.95rem;
}
.user-type-switch {
margin-bottom: 2rem;
}
.user-type-switch .btn-group {
width: 100%;
box-shadow: var(--card-shadow);
border-radius: var(--border-radius-lg);
padding: 0.25rem;
background-color: var(--neutral-100);
}
.user-type-switch .btn {
flex: 1;
background: transparent;
border: none;
padding: 0.75rem 1rem;
font-weight: 500;
color: var(--neutral-700);
border-radius: var(--border-radius);
transition: var(--transition-base);
}
.user-type-switch .btn:hover {
color: var(--primary-color);
}
.user-type-switch .btn.active {
background: white;
color: var(--secondary-color);
box-shadow: var(--card-shadow);
}
/* 表单样式 */
.form-floating {
margin-bottom: 1.25rem;
}
.form-floating > .form-control {
padding: 1rem 1rem;
height: calc(3.5rem + 2px);
border-radius: var(--border-radius-lg);
border: 1px solid var(--neutral-200);
font-size: 0.95rem;
transition: var(--transition-base);
}
.form-floating > .form-control:focus {
border-color: var(--secondary-color);
box-shadow: 0 0 0 3px rgba(74, 108, 253, 0.1);
}
.form-floating > label {
padding: 1rem;
color: var(--neutral-500);
}
.form-check {
display: flex;
align-items: center;
margin-bottom: 1.5rem;
}
.form-check-input {
width: 1.25em;
height: 1.25em;
margin-right: 0.75rem;
background-color: white;
border: 1px solid var(--neutral-300);
border-radius: 0.25em;
transition: all 0.15s ease-in-out;
}
.form-check-input:checked {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.form-check-label {
color: var(--neutral-700);
font-size: 0.95rem;
}
/* 按钮样式 */
.btn-primary {
background: linear-gradient(to right, var(--secondary-color), var(--secondary-light));
border: none;
width: 100%;
padding: 0.85rem;
font-weight: 500;
border-radius: var(--border-radius-lg);
transition: var(--transition-base);
}
.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(-1px);
}
.btn-outline-primary {
color: var(--secondary-color);
border-color: var(--secondary-color);
background-color: transparent;
}
.btn-outline-primary:hover, .btn-outline-primary:focus {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
color: white;
box-shadow: 0 4px 10px rgba(74, 108, 253, 0.2);
}
/* 学生说明部分 */
.student-instructions {
margin-top: 1.5rem;
padding: 1.25rem;
background-color: var(--neutral-50);
border-radius: var(--border-radius-lg);
border: 1px solid var(--neutral-200);
font-size: 0.95rem;
color: var(--neutral-700);
transition: var(--transition-smooth);
}
.student-instructions p {
margin-bottom: 0.75rem;
}
.student-instructions p:last-child {
margin-bottom: 0;
}
.student-instructions strong {
color: var(--neutral-900);
}
/* 页脚样式 */
.login-footer {
text-align: center;
margin-top: 2rem;
color: var(--neutral-500);
font-size: 0.85rem;
}
/* 动画效果 */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.fade-in {
opacity: 0;
animation: fadeIn 0.4s ease-out forwards;
}
/* 输入组样式 */
.input-group {
position: relative;
}
.input-group .form-control {
padding-right: 3.5rem;
border-radius: var(--border-radius-lg);
}
.input-group .btn {
position: absolute;
right: 0;
top: 0;
bottom: 0;
z-index: 5;
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
color: var(--neutral-700);
background-color: var(--neutral-100);
border: 1px solid var(--neutral-200);
border-left: none;
transition: var(--transition-base);
}
.input-group .btn:hover, .input-group .btn:focus {
background-color: var(--neutral-200);
}
</style>
</head>
<body>
<div class="login-container fade-in">
<div class="login-header">
<h1>AI助教开发平台</h1>
<p id="login-subtitle">教师端登录</p>
</div>
<div class="user-type-switch">
<div class="btn-group" role="group" id="user-type-buttons">
<button type="button" class="btn active" id="teacher-button">教师</button>
<button type="button" class="btn" id="student-button">学生</button>
</div>
</div>
<form id="login-form">
<div class="form-floating">
<input type="text" class="form-control" id="username" placeholder="用户名" required>
<label for="username">用户名</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="password" placeholder="密码" required>
<label for="password">密码</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember-me">
<label class="form-check-label" for="remember-me">
记住我
</label>
</div>
<div id="student-instructions" class="student-instructions" style="display: none;">
<p><strong>学生登录说明:</strong></p>
<p>您也可以直接使用教师分享的链接访问AI助手,无需登录。</p>
<div class="input-group mt-3">
<input type="text" class="form-control" id="access-token" placeholder="输入访问令牌">
<button class="btn" type="button" id="access-button">
<i class="bi bi-arrow-right"></i>
</button>
</div>
</div>
<button type="submit" class="btn btn-primary mt-3">
<i class="bi bi-box-arrow-in-right me-2"></i>登录
</button>
</form>
<div class="login-footer">
© 2025 教育AI助手开发平台 版权所有
</div>
</div>
<script>
// 硬编码用户
const users = {
teachers: [
{ username: 'teacher', password: '123456', name: '李志刚' },
{ username: 'admin', password: 'admin123', name: '管理员' }
],
students: [
{ username: 'student1', password: '123456', name: '张三' },
{ username: 'student2', password: '123456', name: '李四' }
]
};
// DOM元素
const teacherButton = document.getElementById('teacher-button');
const studentButton = document.getElementById('student-button');
const loginSubtitle = document.getElementById('login-subtitle');
const studentInstructions = document.getElementById('student-instructions');
const loginForm = document.getElementById('login-form');
const accessButton = document.getElementById('access-button');
// 切换用户类型
teacherButton.addEventListener('click', function() {
teacherButton.classList.add('active');
studentButton.classList.remove('active');
loginSubtitle.textContent = '教师端登录';
studentInstructions.style.display = 'none';
});
studentButton.addEventListener('click', function() {
studentButton.classList.add('active');
teacherButton.classList.remove('active');
loginSubtitle.textContent = '学生端登录';
studentInstructions.style.display = 'block';
});
// 处理登录表单提交
// 处理登录表单提交
loginForm.addEventListener('submit', async function(e) {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const isTeacher = teacherButton.classList.contains('active');
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: username,
password: password,
type: isTeacher ? 'teacher' : 'student'
})
});
const data = await response.json();
if (data.success) {
// 登录成功,重定向到相应页面
window.location.href = isTeacher ? '/index.html' : '/student_portal.html';
} else {
showAlert('用户名或密码错误', 'danger');
}
} catch (error) {
console.error('登录失败:', error);
showAlert('登录请求失败,请重试', 'danger');
}
});
// 处理访问令牌
accessButton.addEventListener('click', function() {
const token = document.getElementById('access-token').value.trim();
if (token) {
// 简单验证令牌格式
if (token.length >= 32) {
// 这里应该向服务器验证令牌有效性,这里简化处理
// 直接从URL中提取agent_id (假设格式为: [agent_id]?token=[token])
if (token.includes('?token=')) {
window.location.href = '/student/' + token;
} else {
// 假设这是一个纯token,需要输入Agent ID
const agentId = prompt('请输入Agent ID');
if (agentId) {
window.location.href = `/student/${agentId}?token=${token}`;
}
}
} else {
showAlert('无效的访问令牌格式', 'warning');
}
} else {
showAlert('请输入访问令牌', 'warning');
}
});
// 显示提示信息
function showAlert(message, type) {
// 移除现有的提示
const existingAlert = document.querySelector('.alert');
if (existingAlert) {
existingAlert.remove();
}
// 创建新提示
const alert = document.createElement('div');
alert.className = `alert alert-${type} fade-in`;
alert.role = 'alert';
alert.style.marginBottom = '1.5rem';
alert.innerHTML = `
<i class="bi ${type === 'danger' ? 'bi-exclamation-triangle' : 'bi-info-circle'} me-2"></i>
${message}
`;
// 添加到表单上方
loginForm.insertAdjacentElement('beforebegin', alert);
// 3秒后自动移除
setTimeout(() => {
alert.style.opacity = '0';
setTimeout(() => alert.remove(), 300);
}, 3000);
}
// 页面加载时检查是否已经登录
// window.addEventListener('DOMContentLoaded', function() {
// const currentUser = localStorage.getItem('currentUser');
// if (currentUser) {
// const userData = JSON.parse(currentUser);
// if (userData.type === 'teacher') {
// window.location.href = '/index.html';
// } else if (userData.type === 'student') {
// window.location.href = '/student_portal.html';
// }
// }
// });
</script>
</body>
</html>