Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 35c944d

Browse files
committed
Adds basic auth user and password functionality
1 parent adf3f01 commit 35c944d

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

app/js/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,18 @@ var UI = (function(UI, undefined) {
522522
content += "<input type='text' id='server_config_host' placeholder='" + UI.t("custom_host") + "' data-i18n='[placeholder]custom_host' value='" + (configuration.lightWalletHost ? UI.format(configuration.lightWalletHost) + (configuration.lightWalletPort ? ":" + UI.format(configuration.lightWalletPort) : "") : "") + "' /></div>";
523523
}
524524

525-
content += "<div class='input-group'><label data-i18n='min_weight_magnitude'>" + UI.t("min_weight_magnitude") + "</label>" +
526-
"<input type='number' min='" + UI.format(configuration.minWeightMagnitudeMinimum) + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + UI.format(configuration.minWeightMagnitude ? configuration.minWeightMagnitude : configuration.minWeightMagnitudeMinimum) + "' /></div>";
525+
content += "<div class='input-group'>"
526+
+ "<label data-i18n=light_wallet_user'>" + i18n.t("light_wallet_user") + "</label>"
527+
+ "<input type='text' min='" + configuration.lightWalletUser + "' name='light_wallet_user' id='light_wallet_user' placeholder='' value='" + String(configuration.lightWalletUser ? configuration.lightWalletUser : '').escapeHTML() + "' />"
528+
+ "</div>";
529+
530+
content += "<div class='input-group'>"
531+
+ "<label data-i18n=light_wallet_password'>" + i18n.t("light_wallet_password") + "</label>"
532+
+ "<input type='password' min='" + configuration.lightWalletPassword + "' name='light_wallet_password' id='light_wallet_password' placeholder='' value='" + String(configuration.lightWalletPassword ? configuration.lightWalletPassword : '').escapeHTML() + "' />"
533+
+ "</div>";
534+
535+
content += "<div class='input-group'><label data-i18n='min_weight_magnitude'>" + i18n.t("min_weight_magnitude") + "</label>" +
536+
"<input type='number' min='" + configuration.minWeightMagnitudeMinimum + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + String(configuration.minWeightMagnitude ? configuration.minWeightMagnitude : configuration.minWeightMagnitudeMinimum).escapeHTML() + "' /></div>";
527537
} else {
528538
content = "<h1 data-i18n='node_config'></h1>" +
529539
"<div class='input-group'><label data-i18n='node_port'>" + UI.t("node_port") + "</label>" +
@@ -586,6 +596,10 @@ var UI = (function(UI, undefined) {
586596

587597
config.lightWalletHost = res[1];
588598
config.lightWalletPort = res[2];
599+
600+
config.lightWalletUser = document.getElementById("light_wallet_user").value;
601+
config.lightWalletPassword = document.getElementById("light_wallet_password").value;
602+
589603
config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
590604
} else {
591605
config.port = parseInt(document.getElementById("server_config_port").value, 10);

app/js/main.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,8 @@ var App = (function(App, undefined) {
15581558
"showStatus": settings.showStatusBar,
15591559
"host": (settings.lightWallet == 1 ? settings.lightWalletHost : "http://localhost"),
15601560
"port": (settings.lightWallet == 1 ? settings.lightWalletPort : settings.port),
1561+
"auth_user": (settings.lightWallet == 1 ? settings.lightWalletUser : null),
1562+
"auth_password": (settings.lightWallet == 1 ? settings.lightWalletPassword : null),
15611563
"depth": settings.depth,
15621564
"minWeightMagnitude": settings.minWeightMagnitude,
15631565
"ccurlPath": ccurlPath,
@@ -2009,7 +2011,16 @@ var App = (function(App, undefined) {
20092011
walletType = settings.lightWallet;
20102012
}
20112013
if (walletType == 1) {
2012-
var config = {"lightWallet": 1, "lightWalletHost": settings.lightWalletHost, "lightWalletPort": settings.lightWalletPort, "minWeightMagnitude": settings.minWeightMagnitude, "testNet": isTestNet, "minWeightMagnitudeMinimum": minWeightMagnitudeMinimum};
2014+
var config = {
2015+
"lightWallet": 1,
2016+
"lightWalletHost": settings.lightWalletHost,
2017+
"lightWalletPassword": settings.lightWalletPassword,
2018+
"lightWalletPort": settings.lightWalletPort,
2019+
"lightWalletUser": settings.lightWalletUser,
2020+
"minWeightMagnitude": settings.minWeightMagnitude,
2021+
"testNet": isTestNet,
2022+
"minWeightMagnitudeMinimum": minWeightMagnitudeMinimum
2023+
};
20132024

20142025
var req = https.get('https://iotasupport.com/providers.json?' + (new Date().getTime()));
20152026
req.on('response', function (res) {
@@ -2098,6 +2109,22 @@ var App = (function(App, undefined) {
20982109
lightWalletHostChange = true;
20992110
}
21002111
}
2112+
2113+
if (configuration.hasOwnProperty("lightWalletUser")) {
2114+
var lightWalletUser = configuration.lightWalletUser;
2115+
if (lightWalletUser != settings.lightWalletUser) {
2116+
settings.lightWalletUser = lightWalletUser;
2117+
lightWalletHostChange = true;
2118+
}
2119+
}
2120+
2121+
if (configuration.hasOwnProperty("lightWalletPassword")) {
2122+
var lightWalletPassword = configuration.lightWalletPassword;
2123+
if (lightWalletPassword != settings.lightWalletPassword) {
2124+
settings.lightWalletPassword = lightWalletPassword;
2125+
lightWalletHostChange = true;
2126+
}
2127+
}
21012128
} else {
21022129
if (configuration.hasOwnProperty("nodes")) {
21032130
var nodes = [];

app/windows/js/setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ var UI = (function(UI, undefined) {
120120
settings.lightWallet = 1;
121121
settings.lightWalletHost = res[1];
122122
settings.lightWalletPort = res[2];
123+
settings.lightWalletUser = document.getElementById("light_wallet_user").value;
124+
settings.lightWalletPassword = document.getElementById("light_wallet_password").value;
123125
}
124126
}
125127

locales/en/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,7 @@
310310
"no_connection_to_host":"No Connection to Host",
311311
"request_error":"Request Error",
312312
"invalid_transaction_hash": "Invalid Transaction Hash"
313+
314+
"light_wallet_user":"Username",
315+
"light_wallet_password": "Password"
313316
}

ui/js/ui.init.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ var UI = (function(UI, $, undefined) {
8383
if (params.has("interrupt")) {
8484
interruptAttachingToTangle = true;
8585
}
86+
87+
if (params.has("auth_user")) {
88+
connection.auth = {
89+
"type": "basic",
90+
"user": params.get("auth_user"),
91+
"password": params.get("auth_password")
92+
};
93+
}
8694
}
8795

8896
UI.makeMultilingual(connection.language, function() {
@@ -98,10 +106,15 @@ var UI = (function(UI, $, undefined) {
98106
return;
99107
}
100108

101-
iota = new IOTA({
109+
var connectionSettings = {
102110
"host": connection.host,
103111
"port": connection.port
104-
});
112+
};
113+
if (connection.auth) {
114+
connectionSettings.auth = connection.auth;
115+
}
116+
117+
iota = new IOTA(connectionSettings);
105118

106119
if (connection.host != "http://localhost") {
107120
connection.lightWallet = true;

0 commit comments

Comments
 (0)