Initial commit: 心理咨询预约系统
PHP 前后端一体:首页咨询师列表、预约表单、管理后台、二维码准入与邮件通知;敏感配置与提交数据通过 .gitignore 排除。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
51
js/access.js
Normal file
51
js/access.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const ACCESS_STORAGE_KEY = "access_ok";
|
||||
|
||||
async function checkAccess() {
|
||||
if (sessionStorage.getItem(ACCESS_STORAGE_KEY) === "1") {
|
||||
return true;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const urlToken = params.get("access");
|
||||
|
||||
if (!urlToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const config = await loadAppConfig();
|
||||
if (urlToken === config.accessToken) {
|
||||
sessionStorage.setItem(ACCESS_STORAGE_KEY, "1");
|
||||
params.delete("access");
|
||||
const newSearch = params.toString();
|
||||
const newUrl =
|
||||
window.location.pathname + (newSearch ? "?" + newSearch : "") + window.location.hash;
|
||||
window.history.replaceState({}, "", newUrl);
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Access check failed:", e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function showAccessDenied() {
|
||||
const overlay = document.createElement("div");
|
||||
overlay.className = "access-denied";
|
||||
overlay.innerHTML = `
|
||||
<div class="access-denied__icon">🔒</div>
|
||||
<h2 class="access-denied__title">请使用专属二维码访问</h2>
|
||||
<p class="access-denied__desc">本服务仅对指定用户开放<br>请扫描管理员提供的二维码进入</p>
|
||||
`;
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
|
||||
async function initAccessGuard() {
|
||||
const allowed = await checkAccess();
|
||||
if (!allowed) {
|
||||
showAccessDenied();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user