Skip to content

Commit 1396faf

Browse files
committed
1 parent 3f20a58 commit 1396faf

4 files changed

Lines changed: 149 additions & 153 deletions

File tree

nodes/http-auth-multiple.html

Lines changed: 93 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,104 @@
11
<script type="text/javascript">
2-
RED.nodes.registerType("node-red-contrib-httpauthmultiple", {
3-
category: "config",
4-
defaults: {
5-
name: { value: "" },
6-
authType: { value: "Basic", required: true },
7-
realm: { value: "", required: true },
8-
hashed: { value: false, required: true },
9-
auths: { value: {} }
10-
},
11-
color: "#E7E7AE",
12-
icon: "white-globe.png",
13-
label: function() { return (this.name || "http auth multiple"); },
14-
oneditprepare: function() {
15-
function resizeRule(rule) {
16-
var newWidth = rule.width();
17-
rule.find('.red-ui-typedInput').typedInput("width", (newWidth - 15) / 2);
2+
/* global RED:false, $:false */
3+
RED.nodes.registerType('http-basic-auth-multiple', {
4+
category: 'config',
5+
defaults: {
6+
name: { value: '' },
7+
realm: { value: '', required: true },
8+
auths: { value: {} },
9+
},
10+
color: '#E7E7AE',
11+
icon: 'white-globe.png',
12+
label: function () { return (this.name || 'http auth multiple'); },
13+
oneditprepare: function () {
14+
function resizeRule(rule) {
15+
const newWidth = rule.width();
16+
rule.find('.red-ui-typedInput').typedInput('width', (newWidth - 15) / 2);
17+
}
18+
const authList = $('#node-input-auths-container').css('min-height', '150px').css('min-width', '450px')
19+
.editableList({
20+
addItem: function (container, i, auth) {
21+
const row = $('<div/>').appendTo(container);
1822

19-
}
20-
var authList = $("#node-input-auths-container").css('min-height', '150px').css('min-width', '450px')
21-
.editableList({
22-
addItem: function(container, i, auth) {
23-
var row = $('<div/>').appendTo(container);
23+
const propertyUser = $('<input/>',
24+
{ class: 'node-input-auth-user', type: 'text', style: 'width: 30%;', placeholder: 'user' }).appendTo(row);
2425

25-
var propertyUser = $('<input/>', { class: "node-input-auth-user", type: "text", style: "width: 30%;", placeholder: "user" })
26-
.appendTo(row);
26+
const propertyRealm = $('<input/>',
27+
{ class: 'node-input-auth-realm', type: 'text', style: 'margin-left: 3%; width: 30%;', placeholder: 'realm' }).appendTo(row);
2728

28-
var propertyRealm = $('<input/>', { class: "node-input-auth-realm", type: "text", style: "margin-left: 3%; width: 30%;", placeholder: "realm" })
29-
.appendTo(row);
29+
const propertyPassword = $('<input/>',
30+
{ class: 'node-input-auth-password', type: 'text', style: 'margin-left: 3%; width: 30%;', placeholder: 'password' }).appendTo(row);
3031

31-
var propertyPassword = $('<input/>', { class: "node-input-auth-password", type: "text", style: "margin-left: 3%; width: 30%;", placeholder: "password" })
32-
.appendTo(row);
32+
propertyUser.val(auth.user);
33+
propertyRealm.val(auth.realm);
34+
propertyPassword.val(auth.password);
3335

34-
propertyUser.val(auth.user);
35-
propertyRealm.val(auth.realm);
36-
propertyPassword.val(auth.password);
36+
resizeRule(container);
37+
},
38+
resizeItem: resizeRule,
39+
removable: true,
40+
});
3741

38-
resizeRule(container);
39-
},
40-
resizeItem: resizeRule,
41-
removable: true
42-
});
42+
if (this.auths) {
43+
for (const key in this.auths) {
44+
if ((this.auths[key]).length) {
45+
this.auths[key].forEach(function (value, index) {
46+
authList.editableList('addItem', { realm: key, user: value.user, password: value.password });
47+
});
48+
}
49+
}
50+
}
51+
},
52+
oneditsave: function () {
53+
const auths = $('#node-input-auths-container').editableList('items');
54+
const node = this;
55+
node.auths = {};
56+
auths.each(function (i) {
57+
const auth = $(this);
58+
const user = auth.find('.node-input-auth-user').val();
59+
const realm = auth.find('.node-input-auth-realm').val();
60+
const password = auth.find('.node-input-auth-password').val();
4361

44-
if (this.auths) {
45-
for (var key in this.auths) {
46-
if ((this.auths[key]).length) {
47-
this.auths[key].forEach(function(value, index) {
48-
authList.editableList('addItem', { realm: key, user: value.user, password: value.password });
49-
})
50-
}
51-
}
52-
}
53-
},
54-
oneditsave: function() {
55-
var auths = $("#node-input-auths-container").editableList('items');
56-
var node = this;
57-
node.auths = {};
58-
auths.each(function(i) {
59-
var auth = $(this);
60-
var user = auth.find(".node-input-auth-user").val();
61-
var realm = auth.find(".node-input-auth-realm").val();
62-
var password = auth.find(".node-input-auth-password").val();
62+
if (!node.auths[realm]) {
63+
node.auths[realm] = [];
64+
}
6365

64-
if (!node.auths[realm]) {
65-
node.auths[realm] = [];
66-
}
67-
68-
if (realm && user && password) {
69-
node.auths[realm].push({
70-
"user": user,
71-
"password": password
72-
});
73-
}
74-
});
75-
76-
},
77-
paletteLabel: "http auth"
78-
});
66+
if (realm && user && password) {
67+
node.auths[realm].push({
68+
user,
69+
password,
70+
});
71+
}
72+
});
73+
},
74+
paletteLabel: 'http auth',
75+
});
7976
</script>
80-
<script type="text/x-red" data-template-name="node-red-contrib-httpauthmultiple">
77+
<script type="text/x-red" data-template-name="http-basic-auth-multiple">
78+
<div class="form-row">
79+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
80+
<input type="texth" id="node-config-input-name">
81+
</div>
82+
<div class="form-row">
83+
<label for="node-input-authType"><i class="fa fa-list"></i> Auth Type</label>
84+
<select id="node-input-authType">
85+
<option value="Basic">Basic</option>
86+
<option value="Digest">Digest</option>
87+
</select>
88+
</div>
8189
<div class="form-row">
82-
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
83-
<input type="texth" id="node-config-input-name">
84-
</div>
85-
<div class="form-row">
86-
<label for="node-input-authType"><i class="fa fa-list"></i> Auth Type</label>
87-
<select id="node-input-authType">
88-
<option value="Basic">Basic</option>
89-
<option value="Digest">Digest</option>
90-
</select>
91-
</div>
92-
<div class="form-row">
93-
<label for="node-config-input-realm"><i class="fa fa-globe"></i> Realm</label>
94-
<input type="text" id="node-config-input-realm">
95-
</div>
96-
<div class="form-row">
97-
<label for="node-config-input-hashed"><i class="fa fa-asterisk"></i> Hashed</label>
98-
<input type="checkbox" id="node-config-input-hashed">
99-
</div>
100-
<div class="form-row">
101-
<label><i class="fa fa-list"></i> Auths</span>
102-
</label>
103-
</div>
104-
<div class="form-row node-input-auths-container-row">
105-
<ol id="node-input-auths-container"></ol>
106-
</div>
107-
</script>
90+
<label for="node-config-input-realm"><i class="fa fa-globe"></i> Realm</label>
91+
<input type="text" id="node-config-input-realm">
92+
</div>
93+
<div class="form-row">
94+
<label for="node-config-input-hashed"><i class="fa fa-asterisk"></i> Hashed</label>
95+
<input type="checkbox" id="node-config-input-hashed">
96+
</div>
97+
<div class="form-row">
98+
<label><i class="fa fa-list"></i> Auths</span>
99+
</label>
100+
</div>
101+
<div class="form-row node-input-auths-container-row">
102+
<ol id="node-input-auths-container"></ol>
103+
</div>
104+
</script>

nodes/http-auth-multiple.js

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
1-
var fs = require("fs");
2-
3-
module.exports = function(RED) {
4-
"use strict";
5-
6-
function HttpAuthMultipleNode(config) {
7-
RED.nodes.createNode(this, config);
8-
9-
var authType = config.authType;
10-
var realm = config.realm.trim();
11-
var realmL = realm.toLowerCase();
12-
var hashed = config.hashed;
13-
var users = {};
14-
for (var key in config.auths) {
15-
16-
config.auths[key].forEach(function(value, index) {
17-
18-
var _username = value.user.trim();
19-
var _usernameL = _username.toLowerCase();
20-
var _realm = key;
21-
var _realmL = _realm.toLowerCase();
22-
var _password = value.password;
23-
24-
if (_realmL == realmL) {
25-
users[_usernameL] = {
26-
realm: _realm,
27-
username: _username,
28-
password: _password,
29-
hashed: hashed
30-
};
31-
}
32-
});
33-
}
34-
35-
this.authType = config.authType;
36-
this.realm = config.realm;
37-
this.getUser = function(_realm, _username) {
38-
var _realmL = _realm.trim().toLowerCase();
39-
var _usernameL = _username.trim().toLowerCase();
40-
if (_realmL == realmL && users[_usernameL]) {
41-
return {
42-
realm: users[_usernameL].realm,
43-
username: users[_usernameL].username,
44-
password: users[_usernameL].password,
45-
hashed: users[_usernameL].hashed
46-
};
47-
}
48-
return null;
49-
};
50-
}
51-
52-
RED.nodes.registerType("node-red-contrib-httpauthmultiple", HttpAuthMultipleNode);
53-
};
1+
module.exports = function (RED) {
2+
'use strict';
3+
4+
function HttpAuthMultipleNode(config) {
5+
RED.nodes.createNode(this, config);
6+
7+
const realm = config.realm.trim();
8+
const realmL = realm.toLowerCase();
9+
const users = {};
10+
for (const key in config.auths) {
11+
config.auths[key].forEach(function (value, index) {
12+
const _username = value.user.trim();
13+
const _usernameL = _username.toLowerCase();
14+
const _realm = key;
15+
const _realmL = _realm.toLowerCase();
16+
const _password = value.password;
17+
18+
if (_realmL === realmL) {
19+
users[_usernameL] = {
20+
realm: _realm,
21+
username: _username,
22+
password: _password,
23+
};
24+
}
25+
});
26+
}
27+
28+
this.realm = config.realm;
29+
this.getUser = function (_realm, _username) {
30+
const _realmL = _realm.trim().toLowerCase();
31+
const _usernameL = _username.trim().toLowerCase();
32+
if (_realmL === realmL && users[_usernameL]) {
33+
return {
34+
realm: users[_usernameL].realm,
35+
username: users[_usernameL].username,
36+
password: users[_usernameL].password,
37+
};
38+
}
39+
return null;
40+
};
41+
}
42+
43+
RED.nodes.registerType('http-basic-auth-multiple', HttpAuthMultipleNode);
44+
};

nodes/http-auth.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
name: { value: '' },
99
file: { value: '', type: 'http-basic-auth-file', required: false },
1010
cred: { value: '', type: 'http-basic-auth-cred', required: false },
11+
multiple: { value: '', type: 'http-basic-auth-multiple', required: false },
1112
realm: { value: '' },
1213
username: { value: '' },
1314
password: { value: '' },
@@ -54,7 +55,15 @@
5455
</fieldset>
5556

5657
<fieldset>
57-
<legend>Option 3: File</legend>
58+
<legend>Option 3: Multiple</legend>
59+
<div class="form-row">
60+
<label for="node-input-cred"><i class="fa fa-list"></i> Credentials</label>
61+
<input type="text" id="node-input-multiple" />
62+
</div>
63+
</fieldset>
64+
65+
<fieldset>
66+
<legend>Option 4: File</legend>
5867
<div class="form-row">
5968
<label for="node-input-file"><i class="fa fa-list"></i> File</label>
6069
<input type="text" id="node-input-file" />

nodes/http-auth.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ module.exports = function (RED) {
8282
getUser = file.getUser;
8383
}
8484

85-
var multiple = RED.nodes.getNode(config.multiple);
85+
const multiple = RED.nodes.getNode(config.multiple);
8686
if (multiple) {
87-
src = "multiple";
88-
authType = multiple.authType;
87+
src = 'multiple';
8988
realm = multiple.realm.trim();
9089
realmL = realm.toLowerCase();
9190
getUser = multiple.getUser;

0 commit comments

Comments
 (0)