luci-base: luci.js: register rpc interceptor to catch expired sessions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
c3ddcbb542
commit
a0d1294566
1 changed files with 40 additions and 16 deletions
|
@ -850,6 +850,25 @@
|
||||||
return (ft != null && ft != false);
|
return (ft != null && ft != false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
notifySessionExpiry: function() {
|
||||||
|
Poll.stop();
|
||||||
|
|
||||||
|
L.ui.showModal(_('Session expired'), [
|
||||||
|
E('div', { class: 'alert-message warning' },
|
||||||
|
_('A new login is required since the authentication session expired.')),
|
||||||
|
E('div', { class: 'right' },
|
||||||
|
E('div', {
|
||||||
|
class: 'btn primary',
|
||||||
|
click: function() {
|
||||||
|
var loc = window.location;
|
||||||
|
window.location = loc.protocol + '//' + loc.host + loc.pathname + loc.search;
|
||||||
|
}
|
||||||
|
}, _('To login…')))
|
||||||
|
]);
|
||||||
|
|
||||||
|
L.raise('SessionError', 'Login session is expired');
|
||||||
|
},
|
||||||
|
|
||||||
setupDOM: function(res) {
|
setupDOM: function(res) {
|
||||||
var domEv = res[0],
|
var domEv = res[0],
|
||||||
uiClass = res[1],
|
uiClass = res[1],
|
||||||
|
@ -859,26 +878,31 @@
|
||||||
|
|
||||||
rpcClass.setBaseURL(rpcBaseURL);
|
rpcClass.setBaseURL(rpcBaseURL);
|
||||||
|
|
||||||
Request.addInterceptor(function(res) {
|
rpcClass.addInterceptor(function(msg, req) {
|
||||||
if (res.status != 403 || res.headers.get('X-LuCI-Login-Required') != 'yes')
|
if (!L.isObject(msg) || !L.isObject(msg.error) || msg.error.code != -32002)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Poll.stop();
|
if (!L.isObject(req) || (req.object == 'session' && req.method == 'access'))
|
||||||
|
return;
|
||||||
|
|
||||||
L.ui.showModal(_('Session expired'), [
|
return rpcClass.declare({
|
||||||
E('div', { class: 'alert-message warning' },
|
'object': 'session',
|
||||||
_('A new login is required since the authentication session expired.')),
|
'method': 'access',
|
||||||
E('div', { class: 'right' },
|
'params': [ 'scope', 'object', 'function' ],
|
||||||
E('div', {
|
'expect': { access: true }
|
||||||
class: 'btn primary',
|
})('uci', 'luci', 'read').catch(L.notifySessionExpiry);
|
||||||
click: function() {
|
});
|
||||||
var loc = window.location;
|
|
||||||
window.location = loc.protocol + '//' + loc.host + loc.pathname + loc.search;
|
|
||||||
}
|
|
||||||
}, _('To login…')))
|
|
||||||
]);
|
|
||||||
|
|
||||||
throw 'Session expired';
|
Request.addInterceptor(function(res) {
|
||||||
|
var isDenied = false;
|
||||||
|
|
||||||
|
if (res.status == 403 && res.headers.get('X-LuCI-Login-Required') == 'yes')
|
||||||
|
isDenied = true;
|
||||||
|
|
||||||
|
if (!isDenied)
|
||||||
|
return;
|
||||||
|
|
||||||
|
L.notifySessionExpiry();
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.probeSystemFeatures().finally(this.initDOM);
|
return this.probeSystemFeatures().finally(this.initDOM);
|
||||||
|
|
Loading…
Reference in a new issue