mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Prompt for login if comms reconnect fails authentication
This commit is contained in:
parent
0c227be02d
commit
6b0bef61a5
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2014, 2015 IBM Corp.
|
* Copyright 2014, 2016 IBM Corp.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -24,8 +24,10 @@ RED.comms = (function() {
|
|||||||
var ws;
|
var ws;
|
||||||
var pendingAuth = false;
|
var pendingAuth = false;
|
||||||
var reconnectAttempts = 0;
|
var reconnectAttempts = 0;
|
||||||
|
var active = false;
|
||||||
|
|
||||||
function connectWS() {
|
function connectWS() {
|
||||||
|
active = true;
|
||||||
var path = location.hostname;
|
var path = location.hostname;
|
||||||
var port = location.port;
|
var port = location.port;
|
||||||
if (port.length !== 0) {
|
if (port.length !== 0) {
|
||||||
@ -63,9 +65,17 @@ RED.comms = (function() {
|
|||||||
}
|
}
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
var msg = JSON.parse(event.data);
|
var msg = JSON.parse(event.data);
|
||||||
if (pendingAuth && msg.auth == "ok") {
|
if (pendingAuth && msg.auth) {
|
||||||
pendingAuth = false;
|
if (msg.auth === "ok") {
|
||||||
completeConnection();
|
pendingAuth = false;
|
||||||
|
completeConnection();
|
||||||
|
} else if (msg.auth === "fail") {
|
||||||
|
// anything else is an error...
|
||||||
|
active = false;
|
||||||
|
RED.user.login({updateMenu:true},function() {
|
||||||
|
connectWS();
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (msg.topic) {
|
} else if (msg.topic) {
|
||||||
for (var t in subscriptions) {
|
for (var t in subscriptions) {
|
||||||
if (subscriptions.hasOwnProperty(t)) {
|
if (subscriptions.hasOwnProperty(t)) {
|
||||||
@ -83,6 +93,9 @@ RED.comms = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
|
if (!active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (clearErrorTimer) {
|
if (clearErrorTimer) {
|
||||||
clearTimeout(clearErrorTimer);
|
clearTimeout(clearErrorTimer);
|
||||||
clearErrorTimer = null;
|
clearErrorTimer = null;
|
||||||
|
@ -99,6 +99,9 @@ RED.user = (function() {
|
|||||||
}).done(function(data,textStatus,xhr) {
|
}).done(function(data,textStatus,xhr) {
|
||||||
RED.settings.set("auth-tokens",data);
|
RED.settings.set("auth-tokens",data);
|
||||||
$("#node-dialog-login").dialog('destroy').remove();
|
$("#node-dialog-login").dialog('destroy').remove();
|
||||||
|
if (opts.updateMenu) {
|
||||||
|
updateUserMenu();
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
}).fail(function(jqXHR,textStatus,errorThrown) {
|
}).fail(function(jqXHR,textStatus,errorThrown) {
|
||||||
RED.settings.remove("auth-tokens");
|
RED.settings.remove("auth-tokens");
|
||||||
@ -133,7 +136,7 @@ RED.user = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateUserMenu() {
|
function updateUserMenu() {
|
||||||
$("#usermenu-submenu li").remove();
|
$("#btn-usermenu-submenu li").remove();
|
||||||
if (RED.settings.user.anonymous) {
|
if (RED.settings.user.anonymous) {
|
||||||
RED.menu.addItem("btn-usermenu",{
|
RED.menu.addItem("btn-usermenu",{
|
||||||
id:"usermenu-item-login",
|
id:"usermenu-item-login",
|
||||||
@ -163,8 +166,6 @@ RED.user = (function() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (RED.settings.user) {
|
if (RED.settings.user) {
|
||||||
if (!RED.settings.editorTheme || !RED.settings.editorTheme.hasOwnProperty("userMenu")) {
|
if (!RED.settings.editorTheme || !RED.settings.editorTheme.hasOwnProperty("userMenu")) {
|
||||||
|
@ -89,6 +89,7 @@ function start() {
|
|||||||
} else {
|
} else {
|
||||||
var completeConnection = function(userScope,sendAck) {
|
var completeConnection = function(userScope,sendAck) {
|
||||||
if (!userScope || !Permissions.hasPermission(userScope,"status.read")) {
|
if (!userScope || !Permissions.hasPermission(userScope,"status.read")) {
|
||||||
|
ws.send(JSON.stringify({auth:"fail"}));
|
||||||
ws.close();
|
ws.close();
|
||||||
} else {
|
} else {
|
||||||
pendingAuth = false;
|
pendingAuth = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user