mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Updated xmpp node to use config node instead of additional creds file.
This commit is contained in:
parent
2f83f71ace
commit
eddf21af74
@ -74,7 +74,7 @@
|
||||
outputs:2,
|
||||
icon: "xmpp.png",
|
||||
label: function() {
|
||||
return this.name||this.server||"xmpp";
|
||||
return this.name||"xmpp";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return (this.name||!this.server)?"node_label_italic":"";
|
||||
@ -85,7 +85,7 @@
|
||||
<script type="text/x-red" data-template-name="xmpp-server">
|
||||
<div class="form-row node-input-server">
|
||||
<label for="node-config-input-server"><i class="icon-bookmark"></i> Server</label>
|
||||
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="Server" style="width: 40%;" >
|
||||
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="localhost" style="width: 40%;" >
|
||||
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
||||
<input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
|
||||
</div>
|
||||
@ -103,12 +103,10 @@
|
||||
RED.nodes.registerType('xmpp-server',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
server: {value:"localhost",required:true},
|
||||
server: {required:true},
|
||||
port: {value:5222,required:true,validate:RED.validators.number()},
|
||||
user: {required:true},
|
||||
pass: {required:true}
|
||||
//user -> credentials
|
||||
//pass -> credentials
|
||||
|
||||
},
|
||||
label: function() {
|
||||
@ -119,6 +117,12 @@
|
||||
if (data.user) {
|
||||
$('#node-config-input-user').val(data.user);
|
||||
}
|
||||
if (data.server) {
|
||||
$('#node-config-input-server').val(data.server);
|
||||
}
|
||||
if (data.port) {
|
||||
$('#node-config-input-port').val(data.port);
|
||||
}
|
||||
if (data.hasPassword) {
|
||||
$('#node-config-input-pass').val('__PWRD__');
|
||||
} else {
|
||||
@ -130,11 +134,15 @@
|
||||
oneditsave: function() {
|
||||
var newUser = $('#node-config-input-user').val();
|
||||
var newPass = $('#node-config-input-pass').val();
|
||||
//var newServer = $('#node-config-input-server').val();
|
||||
//var newPort = $('#node-config-input-port').val();
|
||||
var credentials = {};
|
||||
credentials.user = newUser;
|
||||
if (newPass != '__PWRD__') {
|
||||
credentials.password = newPass;
|
||||
}
|
||||
//credentials.server = newServer;
|
||||
//credentials.port = newPort;
|
||||
$.ajax({
|
||||
url: 'xmpp-server/'+this.id,
|
||||
type: 'POST',
|
||||
|
@ -22,16 +22,16 @@ console.warn=(function() { // suppress warning from stringprep when not needed)
|
||||
};
|
||||
})();
|
||||
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
var xmpp = require('simple-xmpp');
|
||||
console.warn = orig;
|
||||
|
||||
try {
|
||||
var xmppkey = RED.settings.xmpp || require(process.env.NODE_RED_HOME+"/../xmppkeys.js");
|
||||
} catch(err) {
|
||||
// throw new Error("Failed to load XMPP credentials");
|
||||
}
|
||||
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
var xmpp = require('simple-xmpp');
|
||||
console.warn = orig;
|
||||
|
||||
function XMPPServerNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.server = n.server;
|
||||
@ -50,6 +50,10 @@ RED.httpAdmin.get('/xmpp-server/: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 if (xmppkey && xmppkey.jid && xmppkey.password) {
|
||||
RED.nodes.addCredentials(req.params.id,{user:xmppkey.jid,password:xmppkey.password});
|
||||
credentials = RED.nodes.getCredentials(req.params.id);
|
||||
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
|
||||
} else {
|
||||
res.send(JSON.stringify({}));
|
||||
}
|
||||
@ -87,14 +91,21 @@ RED.httpAdmin.post('/xmpp-server/:id',function(req,res) {
|
||||
function XmppNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.server = n.server;
|
||||
this.serverConfig = RED.nodes.getNode(this.server);
|
||||
try {
|
||||
this.serverConfig = RED.nodes.getNode(this.server);
|
||||
} catch (err) {
|
||||
}
|
||||
if (this.serverConfig){
|
||||
this.host = this.serverConfig.server;
|
||||
this.port = this.serverConfig.port;
|
||||
this.jid = this.serverConfig.username;
|
||||
this.password = this.serverConfig.password;
|
||||
} else {
|
||||
console.log("no serverConfig found");
|
||||
} else if (xmppkey) {
|
||||
console.warn("no serverConfig found, trying old creds file");
|
||||
this.host = n.server;
|
||||
this.port = n.port;
|
||||
this.jid = xmppkey.jid;
|
||||
this.password = xmppkey.password;
|
||||
}
|
||||
|
||||
this.join = n.join || false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user