276 lines
15 KiB
HTML
276 lines
15 KiB
HTML
{% extends "base_tailwind.html" %}
|
|
|
|
{% block title %}注册 - {{ brand_name }}{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="min-h-[70vh] flex items-center justify-center py-8">
|
|
<div class="w-full max-w-md">
|
|
<!-- 注册卡片 -->
|
|
<div class="glass rounded-3xl p-8 layer-4 list-item-enter" style="animation-delay: 0ms;">
|
|
<!-- Logo -->
|
|
<div class="text-center mb-8">
|
|
<div class="w-16 h-16 bg-black dark:bg-white rounded-2xl flex items-center justify-center text-white dark:text-black font-bold text-2xl mx-auto mb-4">
|
|
S
|
|
</div>
|
|
<h1 class="text-2xl font-bold text-neutral-900 dark:text-white">创建账号</h1>
|
|
<p class="text-neutral-500 dark:text-neutral-400 mt-2">填写以下信息完成注册</p>
|
|
</div>
|
|
|
|
<!-- 注册表单 -->
|
|
<form id="registerForm" onsubmit="handleRegister(event)" class="space-y-4">
|
|
<!-- 注册码 -->
|
|
<div>
|
|
<label class="input-label">
|
|
注册码
|
|
<span class="text-red-500">*</span>
|
|
</label>
|
|
<div class="relative">
|
|
<input type="text" name="ticket_code" id="ticket_code" class="input-field font-mono uppercase" placeholder="XXXX-XXXX-XXXX-XXXX" required>
|
|
<a href="{{ url_for('main.buy') }}" class="absolute right-3 top-1/2 -translate-y-1/2 text-xs text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition">
|
|
购买注册码
|
|
</a>
|
|
</div>
|
|
<p class="text-xs text-neutral-500 mt-1" id="ticketSchoolHint">输入注册码后将显示可选学校</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="input-label" for="school_id">学校 <span class="text-red-500">*</span></label>
|
|
<select id="school_id" name="school_id" class="input-field" required>
|
|
<option value="">请选择学校</option>
|
|
{% for school in schools %}<option value="{{ school.id }}">{{ school.name }}</option>{% endfor %}
|
|
</select>
|
|
<p class="text-xs text-neutral-500 mt-1">注册后学校不可修改</p>
|
|
</div>
|
|
|
|
<!-- 网站账号 -->
|
|
<div class="border-t border-neutral-200 dark:border-neutral-800 pt-4">
|
|
<h3 class="text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-3">网站登录账号</h3>
|
|
<div class="space-y-4">
|
|
<div>
|
|
<label class="input-label">用户名</label>
|
|
<input type="text" name="username" id="username" class="input-field" placeholder="设置登录用户名" required>
|
|
</div>
|
|
<div>
|
|
<label class="input-label">密码</label>
|
|
<input type="password" name="password" id="password" class="input-field" placeholder="设置登录密码" required>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 教务系统账号 -->
|
|
<div class="border-t border-neutral-200 dark:border-neutral-800 pt-4">
|
|
<h3 class="text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-3">教务系统账号(用于抢课)</h3>
|
|
<div class="space-y-4">
|
|
<div>
|
|
<label class="input-label">学号</label>
|
|
<input type="text" name="jwxt_username" id="jwxt_username" class="input-field" placeholder="请输入学号" required>
|
|
</div>
|
|
<div>
|
|
<label class="input-label">密码</label>
|
|
<input type="password" name="jwxt_password" id="jwxt_password" class="input-field" placeholder="请输入教务系统密码" required>
|
|
</div>
|
|
<div>
|
|
<label class="input-label">姓名(选填)</label>
|
|
<input type="text" name="jwxt_name" id="jwxt_name" class="input-field" placeholder="请输入姓名">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="errorMessage" class="hidden p-3 bg-red-50 dark:bg-red-900/20 border border-red-100 dark:border-red-800 rounded-xl text-sm text-red-800 dark:text-red-200">
|
|
</div>
|
|
|
|
<div id="successMessage" class="hidden p-3 bg-green-50 dark:bg-green-900/20 border border-green-100 dark:border-green-800 rounded-xl text-sm text-green-800 dark:text-green-200">
|
|
</div>
|
|
|
|
<!-- 协议勾选 -->
|
|
<label class="flex items-start gap-2.5 cursor-pointer select-none" id="termsLabel">
|
|
<div class="relative flex-shrink-0 mt-0.5">
|
|
<input type="checkbox" id="agreeTerms" class="sr-only" onchange="updateCheckbox(this)">
|
|
<div id="checkboxBox" class="w-[18px] h-[18px] rounded border-2 border-neutral-300 dark:border-neutral-600 transition-all flex items-center justify-center">
|
|
<svg id="checkIcon" class="w-2.5 h-2.5 text-white dark:text-black hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
<span class="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">
|
|
我已阅读并同意
|
|
<a href="{{ url_for('main.terms') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">用户服务协议</a>
|
|
和
|
|
<a href="{{ url_for('main.privacy') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">隐私政策</a>,包括本服务收集并使用我的教务系统账号信息
|
|
</span>
|
|
</label>
|
|
|
|
<button type="submit" id="submitBtn" class="w-full btn-primary py-3.5 rounded-full text-sm font-bold mt-6">
|
|
注册
|
|
</button>
|
|
</form>
|
|
|
|
<!-- 分割线 -->
|
|
<div class="relative my-6">
|
|
<div class="absolute inset-0 flex items-center">
|
|
<div class="w-full border-t border-neutral-200 dark:border-neutral-800"></div>
|
|
</div>
|
|
<div class="relative flex justify-center text-sm">
|
|
<span class="px-4 bg-white dark:bg-dark-card text-neutral-500">已有账号?</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 登录按钮 -->
|
|
<a href="{{ url_for('main.login') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition">
|
|
立即登录
|
|
</a>
|
|
|
|
<!-- 购买按钮 -->
|
|
<a href="{{ url_for('main.buy') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition mt-3">
|
|
购买注册码
|
|
</a>
|
|
</div>
|
|
|
|
<!-- 返回首页 -->
|
|
<div class="text-center mt-6">
|
|
<a href="{{ url_for('main.buy') }}" class="text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition flex items-center justify-center gap-1">
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
|
|
</svg>
|
|
返回首页
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
function updateCheckbox(input) {
|
|
const box = document.getElementById('checkboxBox');
|
|
const icon = document.getElementById('checkIcon');
|
|
if (input.checked) {
|
|
box.classList.remove('border-neutral-300', 'dark:border-neutral-600');
|
|
box.classList.add('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
|
|
icon.classList.remove('hidden');
|
|
} else {
|
|
box.classList.add('border-neutral-300', 'dark:border-neutral-600');
|
|
box.classList.remove('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
|
|
icon.classList.add('hidden');
|
|
}
|
|
}
|
|
|
|
// 格式化注册码输入
|
|
document.getElementById('ticket_code').addEventListener('input', function(e) {
|
|
let value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
|
let formatted = '';
|
|
for (let i = 0; i < value.length && i < 16; i++) {
|
|
if (i > 0 && i % 4 === 0) formatted += '-';
|
|
formatted += value[i];
|
|
}
|
|
e.target.value = formatted;
|
|
});
|
|
|
|
const allSchools = {{ schools | map(attribute='id') | list | tojson }};
|
|
let ticketCheckTimer;
|
|
document.getElementById('ticket_code').addEventListener('input', () => {
|
|
clearTimeout(ticketCheckTimer);
|
|
ticketCheckTimer = setTimeout(checkTicketSchools, 350);
|
|
});
|
|
|
|
async function checkTicketSchools() {
|
|
const code = document.getElementById('ticket_code').value.replace(/[^A-Z0-9]/gi, '').toUpperCase();
|
|
const select = document.getElementById('school_id');
|
|
const hint = document.getElementById('ticketSchoolHint');
|
|
const choices = [...select.options].slice(1);
|
|
if (code.length !== 16) {
|
|
choices.forEach(option => option.hidden = false);
|
|
select.disabled = false;
|
|
hint.textContent = '输入注册码后将显示可选学校';
|
|
return;
|
|
}
|
|
try {
|
|
const response = await fetch('/api/tickets/schools/' + encodeURIComponent(code));
|
|
const data = await response.json();
|
|
if (code !== document.getElementById('ticket_code').value.replace(/[^A-Z0-9]/gi, '').toUpperCase()) return;
|
|
if (!data.success) {
|
|
choices.forEach(option => option.hidden = false);
|
|
select.disabled = false;
|
|
hint.textContent = data.message;
|
|
return;
|
|
}
|
|
const allowed = data.school_ids === null ? allSchools : data.school_ids;
|
|
choices.forEach(option => option.hidden = !allowed.includes(option.value));
|
|
if (!allowed.includes(select.value)) select.value = allowed.length === 1 ? allowed[0] : '';
|
|
select.disabled = allowed.length === 1;
|
|
hint.textContent = allowed.length === 1 ? '该注册码仅限所选学校,学校已锁定' :
|
|
(data.school_ids === null ? '该注册码适用于全部学校' : '请从注册码允许的学校中选择');
|
|
} catch (error) { hint.textContent = '暂时无法检查注册码适用学校'; }
|
|
}
|
|
|
|
async function handleRegister(event) {
|
|
event.preventDefault();
|
|
|
|
// 验证协议勾选
|
|
if (!document.getElementById('agreeTerms').checked) {
|
|
const errorDiv = document.getElementById('errorMessage');
|
|
errorDiv.textContent = '请先阅读并同意用户服务协议和隐私政策';
|
|
errorDiv.classList.remove('hidden');
|
|
return;
|
|
}
|
|
|
|
// 去掉注册码中的横线,只保留字母和数字
|
|
const ticketCode = document.getElementById('ticket_code').value.replace(/[^A-Z0-9]/gi, '').toUpperCase();
|
|
const username = document.getElementById('username').value.trim();
|
|
const password = document.getElementById('password').value;
|
|
const jwxtUsername = document.getElementById('jwxt_username').value.trim();
|
|
const jwxtPassword = document.getElementById('jwxt_password').value;
|
|
const jwxtName = document.getElementById('jwxt_name').value.trim();
|
|
const schoolId = document.getElementById('school_id').value;
|
|
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
const errorDiv = document.getElementById('errorMessage');
|
|
const successDiv = document.getElementById('successMessage');
|
|
|
|
// 禁用按钮
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<span class="inline-block w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"></span>注册中...';
|
|
errorDiv.classList.add('hidden');
|
|
successDiv.classList.add('hidden');
|
|
|
|
try {
|
|
const response = await fetch('{{ url_for('main.register') }}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
ticket_code: ticketCode,
|
|
username: username,
|
|
password: password,
|
|
jwxt_username: jwxtUsername,
|
|
jwxt_password: jwxtPassword,
|
|
jwxt_name: jwxtName,
|
|
school_id: schoolId
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
successDiv.textContent = data.message || '注册成功,即将跳转到登录页面...';
|
|
successDiv.classList.remove('hidden');
|
|
setTimeout(() => {
|
|
window.location.href = '{{ url_for('main.login') }}';
|
|
}, 1500);
|
|
} else {
|
|
errorDiv.textContent = data.message || '注册失败';
|
|
errorDiv.classList.remove('hidden');
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '注册';
|
|
}
|
|
} catch (error) {
|
|
errorDiv.textContent = '网络错误,请稍后重试';
|
|
errorDiv.classList.remove('hidden');
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '注册';
|
|
}
|
|
}
|
|
</script>
|
|
{% endblock %}
|