Update all nodes to credentials system and auth middleware

This commit is contained in:
Nick O'Leary
2015-02-06 21:10:14 +00:00
parent f4fdebfba5
commit 08791f1914
29 changed files with 177 additions and 783 deletions

View File

@@ -55,6 +55,10 @@
name: {value:""},
priority: {value:0}
},
credentials: {
deviceid: {type:"text"},
pushkey: {type: "password"}
},
color:"#a7c9a0",
inputs:1,
outputs:0,
@@ -71,39 +75,6 @@
min:-1,
max:2
});
$.getJSON('pushover/'+this.id,function(data) {
if (data.deviceid) {
$('#node-config-input-deviceid').val(data.deviceid);
}
if (data.hasPassword) {
$('#node-config-input-pushkey').val('__PWRD__');
} else {
$('#node-config-input-pushkey').val('');
}
});
},
oneditsave: function() {
var credentials = {};
var newUser = $('#node-config-input-deviceid').val();
var newPass = $('#node-config-input-pushkey').val();
credentials.deviceid = newUser;
if (newPass != '__PWRD__') {
credentials.pushkey = newPass;
}
$.ajax({
url: 'pushover/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
ondelete: function() {
$.ajax({
url: 'pushover/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -23,7 +23,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
this.title = n.title;
this.priority = n.priority;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { this.error("No Pushover api token set"); }
if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; }
@@ -69,44 +69,10 @@ module.exports = function(RED) {
}
});
}
RED.nodes.registerType("pushover",PushoverNode);
var querystring = require('querystring');
RED.httpAdmin.get('/pushover/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
} else {
res.send(JSON.stringify({}));
}
});
RED.httpAdmin.delete('/pushover/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/pushover/: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.deviceid === null || newCreds.deviceid === "") {
delete credentials.deviceid;
} else {
credentials.deviceid = newCreds.deviceid;
}
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
RED.nodes.registerType("pushover",PushoverNode,{
credentials: {
deviceid: {type:"text"},
pushkey: {type: "password"}
}
});
}

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-pushover",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node to send alerts via Pushover",
"dependencies" : {
"pushover-notifications" : "0.2.0"