mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Update all nodes to credentials system and auth middleware
This commit is contained in:
@@ -44,6 +44,9 @@
|
||||
title: {value:""},
|
||||
name: {value:""}
|
||||
},
|
||||
credentials: {
|
||||
pushkey: {type: "password"}
|
||||
},
|
||||
color:"#a7c9a0",
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
@@ -54,35 +57,6 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
$.getJSON('nma/'+this.id,function(data) {
|
||||
if (data.hasPassword) {
|
||||
$('#node-config-input-pushkey').val('__PWRD__');
|
||||
} else {
|
||||
$('#node-config-input-pushkey').val('');
|
||||
}
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var credentials = {};
|
||||
var newPass = $('#node-config-input-pushkey').val();
|
||||
if (newPass != '__PWRD__') {
|
||||
credentials.pushkey = newPass;
|
||||
$.ajax({
|
||||
url: 'nma/'+this.id,
|
||||
type: 'POST',
|
||||
data: credentials,
|
||||
success: function(result){}
|
||||
});
|
||||
}
|
||||
},
|
||||
ondelete: function() {
|
||||
$.ajax({
|
||||
url: 'nma/'+this.id,
|
||||
type: 'DELETE',
|
||||
success: function(result) {}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -21,7 +21,7 @@ module.exports = function(RED) {
|
||||
function NMANode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.title = n.title;
|
||||
var credentials = RED.nodes.getCredentials(n.id);
|
||||
var credentials = this.credentials;
|
||||
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
||||
else { this.error("No NMA API key set"); }
|
||||
var node = this;
|
||||
@@ -50,39 +50,9 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("nma",NMANode);
|
||||
|
||||
var querystring = require('querystring');
|
||||
|
||||
RED.httpAdmin.get('/nma/:id',function(req,res) {
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
if (credentials) {
|
||||
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
|
||||
} else {
|
||||
res.send(JSON.stringify({}));
|
||||
RED.nodes.registerType("nma",NMANode, {
|
||||
credentials: {
|
||||
pushkey: {type: "password"}
|
||||
}
|
||||
});
|
||||
|
||||
RED.httpAdmin.delete('/nma/:id',function(req,res) {
|
||||
RED.nodes.deleteCredentials(req.params.id);
|
||||
res.send(200);
|
||||
});
|
||||
|
||||
RED.httpAdmin.post('/nma/:id',function(req,res) {
|
||||
var body = "";
|
||||
req.on('data', function(chunk) {
|
||||
body+=chunk;
|
||||
});
|
||||
req.on('end', function(){
|
||||
var newCreds = querystring.parse(body);
|
||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||
if (newCreds.pushkey === "") {
|
||||
delete credentials.pushkey;
|
||||
} else {
|
||||
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
||||
}
|
||||
RED.nodes.addCredentials(req.params.id,credentials);
|
||||
res.send(200);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-nma",
|
||||
"version" : "0.0.2",
|
||||
"version" : "0.0.3",
|
||||
"description" : "A Node-RED node to send alerts via Notify-My-Android",
|
||||
"dependencies" : {
|
||||
"nma" : "0.2.2"
|
||||
|
Reference in New Issue
Block a user