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

Commit

Permalink
Adds basic auth user and password functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bmavity committed Jun 22, 2017
1 parent 19cf768 commit 3fdc0f1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
14 changes: 14 additions & 0 deletions app/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ var UI = (function(UI, undefined) {
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>";
}

content += "<div class='input-group'>"
+ "<label data-i18n=light_wallet_user'>" + i18n.t("light_wallet_user") + "</label>"
+ "<input type='text' min='" + configuration.lightWalletUser + "' name='light_wallet_user' id='light_wallet_user' placeholder='' value='" + String(configuration.lightWalletUser ? configuration.lightWalletUser : '').escapeHTML() + "' />"
+ "</div>";

content += "<div class='input-group'>"
+ "<label data-i18n=light_wallet_password'>" + i18n.t("light_wallet_password") + "</label>"
+ "<input type='password' min='" + configuration.lightWalletPassword + "' name='light_wallet_password' id='light_wallet_password' placeholder='' value='" + String(configuration.lightWalletPassword ? configuration.lightWalletPassword : '').escapeHTML() + "' />"
+ "</div>";

content += "<div class='input-group'><label data-i18n='min_weight_magnitude'>" + i18n.t("min_weight_magnitude") + "</label>" +
"<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>";
} else {
Expand Down Expand Up @@ -586,6 +596,10 @@ var UI = (function(UI, undefined) {

config.lightWalletHost = res[1];
config.lightWalletPort = res[2];

config.lightWalletUser = document.getElementById("light_wallet_user").value;
config.lightWalletPassword = document.getElementById("light_wallet_password").value;

config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
} else {
config.port = parseInt(document.getElementById("server_config_port").value, 10);
Expand Down
29 changes: 28 additions & 1 deletion app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,8 @@ var App = (function(App, undefined) {
"showStatus": settings.showStatusBar,
"host": (settings.lightWallet == 1 ? settings.lightWalletHost : "http://localhost"),
"port": (settings.lightWallet == 1 ? settings.lightWalletPort : settings.port),
"auth_user": (settings.lightWallet == 1 ? settings.lightWalletUser : null),
"auth_password": (settings.lightWallet == 1 ? settings.lightWalletPassword : null),
"depth": settings.depth,
"minWeightMagnitude": settings.minWeightMagnitude,
"ccurlPath": ccurlPath,
Expand Down Expand Up @@ -1974,7 +1976,16 @@ var App = (function(App, undefined) {
walletType = settings.lightWallet;
}
if (walletType == 1) {
var config = {"lightWallet": 1, "lightWalletHost": settings.lightWalletHost, "lightWalletPort": settings.lightWalletPort, "minWeightMagnitude": settings.minWeightMagnitude, "testNet": isTestNet, "minWeightMagnitudeMinimum": minWeightMagnitudeMinimum};
var config = {
"lightWallet": 1,
"lightWalletHost": settings.lightWalletHost,
"lightWalletPassword": settings.lightWalletPassword,
"lightWalletPort": settings.lightWalletPort,
"lightWalletUser": settings.lightWalletUser,
"minWeightMagnitude": settings.minWeightMagnitude,
"testNet": isTestNet,
"minWeightMagnitudeMinimum": minWeightMagnitudeMinimum
};

var req = http.get('http://provider.iota.org/list.json?' + (new Date().getTime()));
req.on('response', function (res) {
Expand Down Expand Up @@ -2063,6 +2074,22 @@ var App = (function(App, undefined) {
lightWalletHostChange = true;
}
}

if (configuration.hasOwnProperty("lightWalletUser")) {
var lightWalletUser = configuration.lightWalletUser;
if (lightWalletUser != settings.lightWalletUser) {
settings.lightWalletUser = lightWalletUser;
lightWalletHostChange = true;
}
}

if (configuration.hasOwnProperty("lightWalletPassword")) {
var lightWalletPassword = configuration.lightWalletPassword;
if (lightWalletPassword != settings.lightWalletPassword) {
settings.lightWalletPassword = lightWalletPassword;
lightWalletHostChange = true;
}
}
} else {
if (configuration.hasOwnProperty("nodes")) {
var nodes = [];
Expand Down
2 changes: 2 additions & 0 deletions app/windows/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ var UI = (function(UI, undefined) {
settings.lightWallet = 1;
settings.lightWalletHost = res[1];
settings.lightWalletPort = res[2];
settings.lightWalletUser = document.getElementById("light_wallet_user").value;
settings.lightWalletPassword = document.getElementById("light_wallet_password").value;
}
}

Expand Down
5 changes: 4 additions & 1 deletion locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,8 @@
"russian":"Russian",
"swedish":"Swedish",
"korean":"Korean",
"seed":"Seed"
"seed":"Seed",

"light_wallet_user":"Username",
"light_wallet_password": "Password"
}
17 changes: 15 additions & 2 deletions ui/js/ui.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ var UI = (function(UI, $, undefined) {
if (params.has("allowShortSeedLogin")) {
connection.allowShortSeedLogin = params.get("allowShortSeedLogin") == 1;
}

if (params.has("auth_user")) {
connection.auth = {
"type": "basic",
"user": params.get("auth_user"),
"password": params.get("auth_password")
};
}
}

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

iota = new IOTA({
var connectionSettings = {
"host": connection.host,
"port": connection.port
});
};
if (connection.auth) {
connectionSettings.auth = connection.auth;
}

iota = new IOTA(connectionSettings);

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

0 comments on commit 3fdc0f1

Please sign in to comment.