Add optional basic-auth to HTTP Request node

Closes #160
This commit is contained in:
Nick O'Leary
2014-02-19 20:31:42 +00:00
parent ec0b5da29c
commit d8f2f24b44
3 changed files with 135 additions and 2 deletions

View File

@@ -160,6 +160,19 @@
<label for="node-input-url"><i class="icon-tasks"></i> URL</label>
<input type="text" id="node-input-url" placeholder="http://">
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-useAuth" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-useAuth" style="width: 70%;">Use basic authentication?</label>
</div>
<div class="form-row node-input-useAuth-row">
<label for="node-config-input-user"><i class="icon-user"></i> Username</label>
<input type="text" id="node-config-input-user">
</div>
<div class="form-row node-input-useAuth-row">
<label for="node-config-input-pass"><i class="icon-lock"></i> Password</label>
<input type="password" id="node-config-input-pass">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
@@ -193,7 +206,9 @@
defaults: {
name: {value:""},
method:{value:"GET"},
url:{value:""}
url:{value:""},
//user -> credentials
//pass -> credentials
},
inputs:1,
outputs:1,
@@ -204,6 +219,72 @@
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$.getJSON('http-request/'+this.id,function(data) {
if (data.user) {
$('#node-input-useAuth').prop('checked', true);
$(".node-input-useAuth-row").show();
$('#node-config-input-user').data("v",data.user);
$('#node-config-input-user').val(data.user);
} else {
$('#node-input-useAuth').prop('checked', false);
$(".node-input-useAuth-row").hide();
$('#node-config-input-user').data("v",'');
}
if (data.hasPassword) {
$('#node-input-useAuth').prop('checked', true);
$(".node-input-useAuth-row").show();
$('#node-config-input-pass').data("v",'__PWRD__');
$('#node-config-input-pass').val('__PWRD__');
} else {
$('#node-config-input-pass').data("v",'');
$('#node-config-input-pass').val('');
}
});
$("#node-input-useAuth").change(function() {
if ($(this).is(":checked")) {
$(".node-input-useAuth-row").show();
} else {
$(".node-input-useAuth-row").hide();
}
});
},
oneditsave: function() {
var oldUser = $('#node-config-input-user').data("v");
var oldPass = $('#node-config-input-pass').data("v");
var newUser = $('#node-config-input-user').val();
var newPass = $('#node-config-input-pass').val();
if (!$("#node-input-useAuth").is(":checked")) {
newUser = "";
newPass = "";
}
if (oldUser != newUser || oldPass != newPass) {
if (newUser == "" && newPass == "") {
$.ajax({
url: 'http-request/'+this.id,
type: 'DELETE',
success: function(result) {}
});
} else {
var credentials = {};
credentials.user = newUser;
if (newPass != '__PWRD__') {
credentials.password = newPass;
}
$.ajax({
url: 'http-request/'+this.id,
type: 'POST',
data: credentials,
success:function(result){}
});
}
return true;
}
}
});
</script>