diff --git a/accounts/templates/accounts/profile.html b/accounts/templates/accounts/profile.html
index 2431e5b..3d2e7ae 100644
--- a/accounts/templates/accounts/profile.html
+++ b/accounts/templates/accounts/profile.html
@@ -15,13 +15,14 @@
/* 主内容区 */
.main-content { margin-left: 220px; padding: 40px; }
- .profile-card { background: #fff; border-radius: 14px; box-shadow: 0 10px 24px rgba(31,35,40,0.08); padding: 30px; margin-bottom: 30px; }
+ .profile-card { background: #fff; border-radius: 14px; box-shadow: 0 10px 24px rgba(31,35,40,0.08); padding: 30px; margin-bottom: 40px; }
+ .rc-card { margin-top: 18px; }
.profile-header { display: flex; align-items: center; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 20px; }
.profile-info h2 { margin: 0; color: #1e1e2e; }
.profile-info p { margin: 5px 0; color: #666; }
.label { font-weight: bold; color: #333; margin-right: 10px; }
- .section-title { font-size: 20px; font-weight: bold; margin-bottom: 20px; color: #1e1e2e; }
+ .section-title { font-size: 20px; font-weight: bold; margin: 34px 0 24px; color: #1e1e2e; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.image-item { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.05); transition: transform 0.2s; }
.image-item:hover { transform: translateY(-5px); }
@@ -66,34 +67,13 @@
用户名: {{ profile_user.username }}
用户ID: {{ profile_user.user_id }}
+
注册码: {{ profile_user.registration_code|default:"无" }}
所属: {{ profile_user.key|join:"、"|default:"未填写" }}
可管理级别: {{ profile_user.manage_key|join:"、"|default:"无" }}
权限级别: {{ permission_name }}
- {% if permission_name != "管理员" and not profile_user.manage_key %}
-
- {% endif %}
-
我的提交
{% if achievements %}
{% endif %}
+
+
+
+ {% if permission_name != "管理员" and not profile_user.manage_key %}
+
+ {% endif %}
@@ -205,6 +229,88 @@
}
});
}
+
+ const rcForm = document.getElementById('rcForm');
+ if (rcForm) {
+ let rcPreviewTimer = null;
+ let rcPreviewSeq = 0;
+ const rcInput = document.getElementById('newRegCode');
+ const rcPreview = document.getElementById('rcPreview');
+
+ async function refreshRcPreview(code) {
+ const seq = ++rcPreviewSeq;
+ if (!code) {
+ rcPreview.innerHTML = '输入注册码后自动显示 key 预览
';
+ return;
+ }
+ rcPreview.innerHTML = '正在查询...
';
+ try {
+ const resp = await fetch(`/accounts/profile/registration-code/preview/?code=${encodeURIComponent(code)}`, { method: 'GET', credentials: 'same-origin' });
+ const data = await resp.json();
+ if (seq !== rcPreviewSeq) return;
+ if (!(resp.ok && data && data.ok)) {
+ const msg = (data && data.message) ? data.message : '查询失败';
+ rcPreview.innerHTML = `${msg}
`;
+ return;
+ }
+ const keys = ((data.data || {}).keys || []).map(String).filter(Boolean);
+ const manageKeys = ((data.data || {}).manage_keys || []).map(String).filter(Boolean);
+ const keysText = keys.length ? keys.join('、') : '无';
+ const manageText = manageKeys.length ? manageKeys.join('、') : '无';
+ rcPreview.innerHTML = `key:${keysText}
manage_key:${manageText}
`;
+ } catch (e) {
+ if (seq !== rcPreviewSeq) return;
+ rcPreview.innerHTML = '查询失败
';
+ }
+ }
+
+ if (rcInput) {
+ rcInput.addEventListener('input', () => {
+ const code = (rcInput.value || '').trim();
+ if (rcPreviewTimer) window.clearTimeout(rcPreviewTimer);
+ rcPreviewTimer = window.setTimeout(() => refreshRcPreview(code), 300);
+ });
+ refreshRcPreview((rcInput.value || '').trim());
+ }
+
+ rcForm.addEventListener('submit', async (e) => {
+ e.preventDefault();
+ const msg = document.getElementById('rcMsg');
+ msg.textContent = '';
+ msg.className = 'msg';
+ const code = (document.getElementById('newRegCode').value || '').trim();
+ if (!code) {
+ msg.textContent = '请输入注册码';
+ msg.className = 'msg error';
+ return;
+ }
+ if (!confirm('确定要替换注册码吗?该操作会替换你当前的 key。')) return;
+ try {
+ const csrftoken = getCookie('csrftoken');
+ const resp = await fetch('/accounts/profile/registration-code/replace/', {
+ method: 'POST',
+ credentials: 'same-origin',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-CSRFToken': csrftoken || ''
+ },
+ body: JSON.stringify({ code })
+ });
+ const data = await resp.json();
+ if (resp.ok && data.ok) {
+ msg.textContent = '替换成功';
+ msg.className = 'msg success';
+ window.location.reload();
+ } else {
+ msg.textContent = (data && data.message) ? data.message : '替换失败';
+ msg.className = 'msg error';
+ }
+ } catch (err) {
+ msg.textContent = '替换失败';
+ msg.className = 'msg error';
+ }
+ });
+ }