fix: use RBAC /rbac/user/login.ui for authentication instead of custom login modal
This commit is contained in:
parent
8412f9db18
commit
8006fca0c5
@ -56,13 +56,10 @@ body{font-family:system-ui;background:var(--bg);color:var(--text);min-height:100
|
||||
</div>
|
||||
|
||||
<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-body">
|
||||
<div class="form-group"><label>用户名</label><input type="text" id="login-user" placeholder="用户名" autofocus></div>
|
||||
<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 class="modal-body" style="padding:0;height:calc(100% - 49px)">
|
||||
<iframe id="login-iframe" src="" style="width:100%;height:100%;border:none" allow="same-origin"></iframe>
|
||||
</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';
|
||||
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 showLogin(){document.getElementById('login-modal').classList.add('show');document.getElementById('login-user').focus()}
|
||||
function closeLogin(){document.getElementById('login-modal').classList.remove('show')}
|
||||
async function doLogin(){
|
||||
var u=document.getElementById('login-user').value;
|
||||
var p=document.getElementById('login-pass').value;
|
||||
if(!u||!p){document.getElementById('login-msg').textContent='请输入用户名和密码';return}
|
||||
var fd=new FormData();fd.append('username',u);fd.append('password',p);
|
||||
try{
|
||||
var r=await fetch('/pccs/api/a1b2c3d4e5.dspy',{method:'POST',body:fd});
|
||||
var d=await r.json();
|
||||
if(d.status==='ok'){closeLogin();document.getElementById('login-msg').textContent=''}
|
||||
else document.getElementById('login-msg').textContent=d.message||'登录失败'
|
||||
}catch(e){document.getElementById('login-msg').textContent='网络错误'}
|
||||
function showLogin(){
|
||||
var iframe=document.getElementById('login-iframe');
|
||||
iframe.src='/rbac/user/login.ui';
|
||||
document.getElementById('login-modal').classList.add('show');
|
||||
// poll for session cookie (RBAC sets AIOHTTP_SESSION on successful login)
|
||||
var poll=setInterval(function(){
|
||||
if(document.cookie.indexOf('AIOHTTP_SESSION')>=0){
|
||||
clearInterval(poll);
|
||||
closeLogin();
|
||||
location.reload();
|
||||
}
|
||||
},500);
|
||||
// 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>
|
||||
</body>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user