This commit is contained in:
@@ -48,9 +48,15 @@
|
||||
<a href="{% url 'elastic:user_manage' %}" onclick="return handleNavClick(this, '/elastic/user_manage/');">用户管理</a>
|
||||
{% endif %}
|
||||
<a href="/accounts/profile/">个人中心</a>
|
||||
{% if is_admin %}
|
||||
{% if is_admin or has_manage_key or can_manage_registration_codes %}
|
||||
<a href="{% url 'elastic:registration_code_manage_page' %}" onclick="return handleNavClick(this, '/elastic/registration-codes/manage/');">注册码管理</a>
|
||||
{% endif %}
|
||||
{% if is_admin %}
|
||||
<a href="{% url 'accounts:registration_code_requests_page' %}">注册码申请管理</a>
|
||||
{% endif %}
|
||||
{% if not is_admin and not has_manage_key and not can_manage_registration_codes and not has_registration_code %}
|
||||
<a id="applyRegBtn" href="javascript:void(0)">申请注册码管理</a>
|
||||
{% endif %}
|
||||
<a id="logoutBtn">退出登录</a>
|
||||
<div id="logoutMsg"></div>
|
||||
{% csrf_token %}
|
||||
@@ -89,6 +95,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="applyRegModal" style="display:none; position:fixed; inset:0; background:rgba(0,0,0,0.45); z-index:3000; align-items:center; justify-content:center;">
|
||||
<div class="card" style="width:min(560px, calc(100vw - 40px));">
|
||||
<div class="header">
|
||||
<h3 style="margin:0;">申请注册码管理权限</h3>
|
||||
<button id="applyRegClose" class="btn" type="button" style="background:#e5e7eb;">关闭</button>
|
||||
</div>
|
||||
<div class="muted" style="margin-bottom:10px;">填写申请理由,管理员同意后可进入“注册码管理”页面。</div>
|
||||
<div style="margin-top:10px;">
|
||||
<label for="applyReason" style="display:block; margin-bottom:6px; font-weight:600;">申请理由</label>
|
||||
<textarea id="applyReason" rows="5" style="width:100%; padding:10px 12px; border:1px solid #d1d5db; border-radius:10px; box-sizing:border-box; resize: vertical;"></textarea>
|
||||
</div>
|
||||
<div id="applyRegMsg" class="muted" style="margin-top:10px;"></div>
|
||||
<div style="display:flex; gap:10px; justify-content:flex-end; margin-top:14px;">
|
||||
<button id="applyRegSubmit" class="btn btn-primary" type="button">提交申请</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 获取CSRF令牌的函数
|
||||
function getCookie(name) {
|
||||
@@ -155,6 +179,68 @@
|
||||
}
|
||||
});
|
||||
|
||||
const applyRegBtn = document.getElementById('applyRegBtn');
|
||||
const applyRegModal = document.getElementById('applyRegModal');
|
||||
const applyRegClose = document.getElementById('applyRegClose');
|
||||
const applyRegSubmit = document.getElementById('applyRegSubmit');
|
||||
const applyRegMsg = document.getElementById('applyRegMsg');
|
||||
const applyReason = document.getElementById('applyReason');
|
||||
|
||||
function openApplyRegModal() {
|
||||
if (!applyRegModal) return;
|
||||
applyRegMsg.textContent = '';
|
||||
applyReason.value = '';
|
||||
applyRegModal.style.display = 'flex';
|
||||
}
|
||||
function closeApplyRegModal() {
|
||||
if (!applyRegModal) return;
|
||||
applyRegModal.style.display = 'none';
|
||||
}
|
||||
if (applyRegBtn) applyRegBtn.addEventListener('click', openApplyRegModal);
|
||||
if (applyRegClose) applyRegClose.addEventListener('click', closeApplyRegModal);
|
||||
if (applyRegModal) {
|
||||
applyRegModal.addEventListener('click', (e) => {
|
||||
if (e.target === applyRegModal) closeApplyRegModal();
|
||||
});
|
||||
}
|
||||
if (applyRegSubmit) {
|
||||
applyRegSubmit.addEventListener('click', async () => {
|
||||
const reason = (applyReason.value || '').trim();
|
||||
if (!reason) {
|
||||
applyRegMsg.textContent = '请填写申请理由';
|
||||
return;
|
||||
}
|
||||
applyRegMsg.textContent = '提交中...';
|
||||
const csrftoken = getCookie('csrftoken');
|
||||
try {
|
||||
const resp = await fetch('/accounts/registration-code/request/submit/', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrftoken || ''
|
||||
},
|
||||
body: JSON.stringify({ reason })
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (resp.ok && data.ok) {
|
||||
applyRegMsg.textContent = '已提交申请,请等待管理员审核';
|
||||
if (applyRegBtn) {
|
||||
applyRegBtn.textContent = '已提交申请';
|
||||
applyRegBtn.disabled = true;
|
||||
applyRegBtn.style.opacity = '0.6';
|
||||
applyRegBtn.style.cursor = 'not-allowed';
|
||||
}
|
||||
setTimeout(() => closeApplyRegModal(), 800);
|
||||
} else {
|
||||
applyRegMsg.textContent = (data && data.message) ? data.message : '提交失败';
|
||||
}
|
||||
} catch (e) {
|
||||
applyRegMsg.textContent = '提交失败';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function fetchJSON(url){ return fetch(url, {credentials:'same-origin'}).then(r=>r.json()); }
|
||||
function qs(params){ const u = new URLSearchParams(params); return u.toString(); }
|
||||
|
||||
@@ -25,10 +25,14 @@ def home(request):
|
||||
except Exception:
|
||||
perm = 1
|
||||
has_manage_key = bool((u or {}).get("manage_key") or [])
|
||||
can_manage_registration_codes = bool(int((u or {}).get("can_manage_registration_codes") or 0) == 1)
|
||||
has_registration_code = bool(str((u or {}).get("registration_code") or "").strip())
|
||||
context = {
|
||||
"user_id": uid,
|
||||
"username": (u or {}).get("username"),
|
||||
"is_admin": (int(perm) == 0),
|
||||
"has_manage_key": has_manage_key,
|
||||
"can_manage_registration_codes": can_manage_registration_codes,
|
||||
"has_registration_code": has_registration_code,
|
||||
}
|
||||
return render(request, "main/home.html", context)
|
||||
|
||||
Reference in New Issue
Block a user