diff --git a/nodes/core/io/10-mqtt.html b/nodes/core/io/10-mqtt.html
index 3ad7f3239..32c2c731a 100644
--- a/nodes/core/io/10-mqtt.html
+++ b/nodes/core/io/10-mqtt.html
@@ -115,8 +115,8 @@
-
-
+
+
@@ -127,48 +127,14 @@
broker: {value:"",required:true},
port: {value:1883,required:true,validate:RED.validators.number()},
clientid: { value:"" }
- //user -> credentials
- //pass -> credentials
-
+ },
+ credentials: {
+ user: {type:"text"},
+ password: {type: "password"}
},
label: function() {
if (this.broker == "") { this.broker = "localhost"; }
return (this.clientid?this.clientid+"@":"")+this.broker+":"+this.port;
- },
- oneditprepare: function() {
- $.getJSON('mqtt-broker/'+this.id,function(data) {
- if (data.user) {
- $('#node-config-input-user').val(data.user);
- }
- if (data.hasPassword) {
- $('#node-config-input-pass').val('__PWRD__');
- } else {
- $('#node-config-input-pass').val('');
- }
- });
- },
- oneditsave: function() {
- if (this.broker == "") { this.broker = "localhost"; }
- var newUser = $('#node-config-input-user').val();
- var newPass = $('#node-config-input-pass').val();
- var credentials = {};
- credentials.user = newUser;
- if (newPass != '__PWRD__') {
- credentials.password = newPass;
- }
- $.ajax({
- url: 'mqtt-broker/'+this.id,
- type: 'POST',
- data: credentials,
- success:function(result){}
- });
- },
- ondelete: function() {
- $.ajax({
- url: 'mqtt-broker/'+this.id,
- type: 'DELETE',
- success: function(result) {}
- });
}
});
diff --git a/nodes/core/io/10-mqtt.js b/nodes/core/io/10-mqtt.js
index a01952940..129f1a936 100644
--- a/nodes/core/io/10-mqtt.js
+++ b/nodes/core/io/10-mqtt.js
@@ -24,54 +24,18 @@ module.exports = function(RED) {
this.broker = n.broker;
this.port = n.port;
this.clientid = n.clientid;
- var credentials = RED.nodes.getCredentials(n.id);
- if (credentials) {
- this.username = credentials.user;
- this.password = credentials.password;
+ if (this.credentials) {
+ this.username = this.credentials.user;
+ this.password = this.credentials.password;
}
}
- RED.nodes.registerType("mqtt-broker",MQTTBrokerNode);
-
- var querystring = require('querystring');
-
- RED.httpAdmin.get('/mqtt-broker/:id',function(req,res) {
- var credentials = RED.nodes.getCredentials(req.params.id);
- if (credentials) {
- res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
- } else {
- res.send(JSON.stringify({}));
+ RED.nodes.registerType("mqtt-broker",MQTTBrokerNode,{
+ credentials: {
+ user: {type:"text"},
+ password: {type: "password"}
}
});
- RED.httpAdmin.delete('/mqtt-broker/:id',function(req,res) {
- RED.nodes.deleteCredentials(req.params.id);
- res.send(200);
- });
-
- RED.httpAdmin.post('/mqtt-broker/: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.user == null || newCreds.user == "") {
- delete credentials.user;
- } else {
- credentials.user = newCreds.user;
- }
- if (newCreds.password == "") {
- delete credentials.password;
- } else {
- credentials.password = newCreds.password||credentials.password;
- }
- RED.nodes.addCredentials(req.params.id,credentials);
- res.send(200);
- });
- });
-
-
function MQTTInNode(n) {
RED.nodes.createNode(this,n);
this.topic = n.topic;