fix(portal): 管理員忘記密碼自救援出口(arcrun-rag#25)

唯一 admin 忘記 portal 密碼就永久卡死:requirePortalAdmin 系列端點全部要
先有 portal session 才進得去,bootstrap 又只能跑一次——登入頁只會叫他
「聯絡管理員」,而他自己就是管理員,沒有下一步。

新增 POST /portal/admin/recover-password,複用 bootstrap 已在用的 console
owner session 當人閘(與 portal 密碼完全獨立存放的另一組帳密)。畫面入口:
/console → 設定 → 「Portal 帳號密碼救援」;/portal 登入頁加一行連結指過去。

本機真瀏覽器 E2E 驗證(wrangler dev 18787/18788 + 本機靜態伺服,真的走一輪
forgot-password 狀態):first-time setup 建帳號 → 故意打錯密碼確認鎖死
(email 或密碼錯誤)→ 點連結進 /console → 用 console 密碼登入 → 設定頁輸入
portal email → 產生新密碼 BPq2Rs4p7dBWMd6d → 回 /portal 用新密碼登入成功。

cypher-executor 4 個新測試 + 既有 59/60 綠(唯一失敗是既有 pre-existing
/portal HTML 殼 404,與本次無關,git stash 驗證過)。
This commit is contained in:
uncle6me-web
2026-08-09 15:06:17 +08:00
parent 23d36b311a
commit 19c82df05f
4 changed files with 131 additions and 0 deletions
+30
View File
@@ -445,6 +445,15 @@ window.ARCRUN_API_BASE = (window.ARCRUN_CONFIG && window.ARCRUN_CONFIG.apiBase)
</div>
</div>
<div class="panel">
<div style="font-size:17px;font-weight:600">Portal 帳號密碼救援</div>
<div style="margin-top:4px;font-size:14px;line-height:1.65;color:rgba(var(--ink-rgb),.55)">忘記某個 Portal(RAG 搜尋頁)帳號的密碼,包含你自己那組管理員帳號——不需要先登進 Portal。輸入該帳號的 Email,會產生一組新密碼,只顯示這一次,請立刻抄下並拿去 Portal 登入頁使用。</div>
<div style="margin-top:14px;display:flex;flex-direction:column;gap:10px">
<input type="email" id="st-portal-recover-email" class="txt" placeholder="Portal 帳號 Email">
<button class="btn" id="st-portal-recover-btn">產生新密碼</button>
<div id="st-portal-recover-status" style="font-size:14px;min-height:1.2em"></div>
</div>
</div>
<div class="panel">
<div style="font-size:17px;font-weight:600;margin-bottom:12px">系統資訊</div>
<div id="st-info"><div class="muted">載入中…</div></div>
@@ -1526,6 +1535,27 @@ function taipeiMonthDay(ms) { var d = new Date(ms + TAIPEI_OFFSET_MS); return {
})
.catch(function (e) { st.innerHTML = '<span class="err">請求失敗:' + esc(friendlyErr(e)) + '</span>'; });
});
// arcrun-rag#25portal admin 密碼救援——只吃 console owner sessionS.token,本頁登入用的
// 那把),不吃 portal session,所以就算忘記 portal 密碼、進不去 portal 也走得通。
$('st-portal-recover-btn').addEventListener('click', function () {
var email = $('st-portal-recover-email').value.trim();
var st = $('st-portal-recover-status');
if (!email) { st.innerHTML = '<span class="err">請輸入 Email</span>'; return; }
st.textContent = '處理中…';
fetch(API_BASE + '/portal/admin/recover-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + S.token },
body: JSON.stringify({ email: email })
})
.then(function (r) { return r.json().then(function (d) { return { ok: r.ok, d: d }; }); })
.then(function (x) {
if (!x.ok) { st.innerHTML = '<span class="err">' + esc(x.d.error || '失敗') + '</span>'; return; }
st.innerHTML = '<span class="ok">新密碼:<code style="font-size:15px;user-select:all">' + esc(x.d.password) + '</code>(只顯示這一次,請立刻抄下)</span>';
$('st-portal-recover-email').value = '';
toast('新密碼已產生,請立刻抄下');
})
.catch(function (e) { st.innerHTML = '<span class="err">請求失敗:' + esc(friendlyErr(e)) + '</span>'; });
});
// t36:原本這裡綁在那顆假開關上(點了只會 toast 一段 CLI 指示)。開關已移除,
// 這個 handler 也必須一起拿掉——留著會讓 $('st-vec-switch') 回 null、addEventListener
// 當場拋錯,把後面所有綁定(含登出)一起打斷。