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

Commit 3fdc0f1

Browse files
committed
Adds basic auth user and password functionality
1 parent 19cf768 commit 3fdc0f1

File tree

5 files changed

+63
-4
lines changed

5 files changed

+63
-4
lines changed

app/js/index.js

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

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+
525535
content += "<div class='input-group'><label data-i18n='min_weight_magnitude'>" + i18n.t("min_weight_magnitude") + "</label>" +
526536
"<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 {
@@ -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
@@ -1539,6 +1539,8 @@ var App = (function(App, undefined) {
15391539
"showStatus": settings.showStatusBar,
15401540
"host": (settings.lightWallet == 1 ? settings.lightWalletHost : "http://localhost"),
15411541
"port": (settings.lightWallet == 1 ? settings.lightWalletPort : settings.port),
1542+
"auth_user": (settings.lightWallet == 1 ? settings.lightWalletUser : null),
1543+
"auth_password": (settings.lightWallet == 1 ? settings.lightWalletPassword : null),
15421544
"depth": settings.depth,
15431545
"minWeightMagnitude": settings.minWeightMagnitude,
15441546
"ccurlPath": ccurlPath,
@@ -1974,7 +1976,16 @@ var App = (function(App, undefined) {
19741976
walletType = settings.lightWallet;
19751977
}
19761978
if (walletType == 1) {
1977-
var config = {"lightWallet": 1, "lightWalletHost": settings.lightWalletHost, "lightWalletPort": settings.lightWalletPort, "minWeightMagnitude": settings.minWeightMagnitude, "testNet": isTestNet, "minWeightMagnitudeMinimum": minWeightMagnitudeMinimum};
1979+
var config = {
1980+
"lightWallet": 1,
1981+
"lightWalletHost": settings.lightWalletHost,
1982+
"lightWalletPassword": settings.lightWalletPassword,
1983+
"lightWalletPort": settings.lightWalletPort,
1984+
"lightWalletUser": settings.lightWalletUser,
1985+
"minWeightMagnitude": settings.minWeightMagnitude,
1986+
"testNet": isTestNet,
1987+
"minWeightMagnitudeMinimum": minWeightMagnitudeMinimum
1988+
};
19781989

19791990
var req = http.get('http://provider.iota.org/list.json?' + (new Date().getTime()));
19801991
req.on('response', function (res) {
@@ -2063,6 +2074,22 @@ var App = (function(App, undefined) {
20632074
lightWalletHostChange = true;
20642075
}
20652076
}
2077+
2078+
if (configuration.hasOwnProperty("lightWalletUser")) {
2079+
var lightWalletUser = configuration.lightWalletUser;
2080+
if (lightWalletUser != settings.lightWalletUser) {
2081+
settings.lightWalletUser = lightWalletUser;
2082+
lightWalletHostChange = true;
2083+
}
2084+
}
2085+
2086+
if (configuration.hasOwnProperty("lightWalletPassword")) {
2087+
var lightWalletPassword = configuration.lightWalletPassword;
2088+
if (lightWalletPassword != settings.lightWalletPassword) {
2089+
settings.lightWalletPassword = lightWalletPassword;
2090+
lightWalletHostChange = true;
2091+
}
2092+
}
20662093
} else {
20672094
if (configuration.hasOwnProperty("nodes")) {
20682095
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,8 @@
289289
"russian":"Russian",
290290
"swedish":"Swedish",
291291
"korean":"Korean",
292-
"seed":"Seed"
292+
"seed":"Seed",
293+
294+
"light_wallet_user":"Username",
295+
"light_wallet_password": "Password"
293296
}

ui/js/ui.init.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ var UI = (function(UI, $, undefined) {
8080
if (params.has("allowShortSeedLogin")) {
8181
connection.allowShortSeedLogin = params.get("allowShortSeedLogin") == 1;
8282
}
83+
84+
if (params.has("auth_user")) {
85+
connection.auth = {
86+
"type": "basic",
87+
"user": params.get("auth_user"),
88+
"password": params.get("auth_password")
89+
};
90+
}
8391
}
8492

8593
UI.makeMultilingual(connection.language, function() {
@@ -95,10 +103,15 @@ var UI = (function(UI, $, undefined) {
95103
return;
96104
}
97105

98-
iota = new IOTA({
106+
var connectionSettings = {
99107
"host": connection.host,
100108
"port": connection.port
101-
});
109+
};
110+
if (connection.auth) {
111+
connectionSettings.auth = connection.auth;
112+
}
113+
114+
iota = new IOTA(connectionSettings);
102115

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

0 commit comments

Comments
 (0)