fix: use RBAC /rbac/user/login.ui for authentication instead of custom login modal

This commit is contained in:
yumoqing 2026-08-12 12:00:19 +08:00
parent 8412f9db18
commit 8006fca0c5

View File

@ -56,13 +56,10 @@ body{font-family:system-ui;background:var(--bg);color:var(--text);min-height:100
</div> </div>
<div class="modal-overlay" id="login-modal"> <div class="modal-overlay" id="login-modal">
<div class="modal"> <div class="modal" style="width:460px;height:520px;max-width:95vw;max-height:90vh">
<div class="modal-header"><h3 id="modal-title">登录</h3><button class="modal-close" onclick="closeLogin()">✕</button></div> <div class="modal-header"><h3 id="modal-title">登录</h3><button class="modal-close" onclick="closeLogin()">✕</button></div>
<div class="modal-body"> <div class="modal-body" style="padding:0;height:calc(100% - 49px)">
<div class="form-group"><label>用户名</label><input type="text" id="login-user" placeholder="用户名" autofocus></div> <iframe id="login-iframe" src="" style="width:100%;height:100%;border:none" allow="same-origin"></iframe>
<div class="form-group"><label>密码</label><input type="password" id="login-pass" placeholder="密码"></div>
<button class="btn btn-primary" onclick="doLogin()">登录</button>
<p class="msg" id="login-msg"></p>
</div> </div>
</div> </div>
</div> </div>
@ -94,19 +91,24 @@ body{font-family:system-ui;background:var(--bg);color:var(--text);min-height:100
var theme=localStorage.getItem('pccs-theme')||'light'; var theme=localStorage.getItem('pccs-theme')||'light';
document.documentElement.setAttribute('data-theme',theme); document.documentElement.setAttribute('data-theme',theme);
function toggleTheme(){theme=theme==='light'?'dark':'light';document.documentElement.setAttribute('data-theme',theme);localStorage.setItem('pccs-theme',theme)} function toggleTheme(){theme=theme==='light'?'dark':'light';document.documentElement.setAttribute('data-theme',theme);localStorage.setItem('pccs-theme',theme)}
function showLogin(){document.getElementById('login-modal').classList.add('show');document.getElementById('login-user').focus()} function showLogin(){
function closeLogin(){document.getElementById('login-modal').classList.remove('show')} var iframe=document.getElementById('login-iframe');
async function doLogin(){ iframe.src='/rbac/user/login.ui';
var u=document.getElementById('login-user').value; document.getElementById('login-modal').classList.add('show');
var p=document.getElementById('login-pass').value; // poll for session cookie (RBAC sets AIOHTTP_SESSION on successful login)
if(!u||!p){document.getElementById('login-msg').textContent='请输入用户名和密码';return} var poll=setInterval(function(){
var fd=new FormData();fd.append('username',u);fd.append('password',p); if(document.cookie.indexOf('AIOHTTP_SESSION')>=0){
try{ clearInterval(poll);
var r=await fetch('/pccs/api/a1b2c3d4e5.dspy',{method:'POST',body:fd}); closeLogin();
var d=await r.json(); location.reload();
if(d.status==='ok'){closeLogin();document.getElementById('login-msg').textContent=''} }
else document.getElementById('login-msg').textContent=d.message||'登录失败' },500);
}catch(e){document.getElementById('login-msg').textContent='网络错误'} // stop polling after 5 min
setTimeout(function(){clearInterval(poll)},300000);
}
function closeLogin(){
document.getElementById('login-modal').classList.remove('show');
document.getElementById('login-iframe').src='';
} }
</script> </script>
</body> </body>