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

Basic auth #131

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions app/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ var UI = (function(UI, undefined) {
select.addEventListener("change", function(e) {
e.preventDefault();
if (this.value == "custom") {
document.getElementById("server_config_host").style.display = "block";
document.getElementById("custom_light_wallet").style.display = "block";
} else {
document.getElementById("server_config_host").style.display = "none";
document.getElementById("custom_light_wallet").style.display = "none";
}
});
} else {
Expand All @@ -500,12 +500,11 @@ var UI = (function(UI, undefined) {
content = "<h1 data-18n='node_config'></h1>" +
"<div class='input-group'><label><span data-i18n='host' class='label'>" + UI.t("host") + "</span> <span class='error' id='host-error'></span></label>";

var found = false;
if (configuration.lightWalletHosts && configuration.lightWalletHosts.length) {
content += "<select id='server_config_host_select'>";
content += "<option value='' data-i18n='select_your_host'>" + UI.t("select_your_host") + "</option>";

var found = false;

for (var i=0; i<configuration.lightWalletHosts.length; i++) {
var lightWalletHost = configuration.lightWalletHosts[i];
if (!found && (configuration.lightWalletHost && (configuration.lightWalletHost + ":" + configuration.lightWalletPort) == lightWalletHost)) {
Expand All @@ -517,11 +516,31 @@ var UI = (function(UI, undefined) {
content += "<option value='custom'" + (!found ? " selected='selected'" : "") + " data-i18n='custom'>" + UI.t("custom") + "</option>";
content += "</select>";
content += "<hr />";
content += "<input type='text' id='server_config_host' placeholder='" + UI.t("custom_host") + "' data-i18n='[placeholder]custom_host' value='" + (!found && configuration.lightWalletHost ? UI.format(configuration.lightWalletHost) + (configuration.lightWalletPort ? ":" + UI.format(configuration.lightWalletPort) : "") : "") + "' " + (found ? " style='display:none'" : "") + " /></div>";
} else {
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>";
}

var hostValue = "";
if(!found && configuration.lightWalletHost) {
hostValue += UI.format(configuration.lightWalletHost);
if(configuration.lightWalletPort) {
hostValue += ":" + UI.format(configuration.lightWalletPort);
}
}

var lwUser = configuration.lightWalletUser ? UI.format(configuration.lightWalletUser) : '';
var lwPassword = configuration.lightWalletPassword ? UI.format(configuration.lightWalletUPassword) : '';

content += "<div id='custom_light_wallet' style='margin-top: 10px; display:" + (found ? "none" : "block") + ";'>";
content += "<input type='text' id='server_config_host' placeholder='" + UI.t("custom_host") + "' data-i18n='[placeholder]custom_host' value='" + hostValue + "' />";
content += "<div class='input-group' style='margin-top: 10px;'>"
+ "<label for='light_wallet_user' data-i18n=light_wallet_user'>" + UI.t("light_wallet_user") + "</label>"
+ "<input type='text' name='light_wallet_user' id='light_wallet_user' value='" + lwUser + "' />"
+ "</div>";
content += "<div class='input-group'>"
+ "<label for='light_wallet_password' data-i18n=light_wallet_password'>" + UI.t("light_wallet_password") + "</label>"
+ "<input type='password' name='light_wallet_password' id='light_wallet_password' value='" + lwPassword + "' />"
+ "</div>";
content += "</div>";

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

var select = document.getElementById("server_config_host_select");
var lightWalletUser = "";
var lightWalletPassword = "";
if (select) {
var selectedHost = select.options[select.selectedIndex].value;
if (selectedHost == "custom") {
selectedHost = document.getElementById("server_config_host").value;
lightWalletUser = document.getElementById("light_wallet_user").value;
lightWalletPassword = document.getElementById("light_wallet_password").value;
}
} else {
selectedHost = document.getElementById("server_config_host").value;
Expand All @@ -586,6 +609,14 @@ var UI = (function(UI, undefined) {

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

if (lightWalletUser !== "") {
config.lightWalletUser = lightWalletUser;
}
if (lightWalletPassword !== "") {
config.lightWalletPassword = lightWalletPassword;
}

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
50 changes: 46 additions & 4 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,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 @@ -2017,8 +2019,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 = https.get('https://iotasupport.com/providers.json?' + (new Date().getTime()));
req.on('response', function (res) {
var body = '';
Expand Down Expand Up @@ -2108,6 +2118,32 @@ var App = (function(App, undefined) {
lightWalletHostChange = true;
}
}

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

if (configuration.hasOwnProperty("lightWalletPassword")) {
var lightWalletPassword = configuration.lightWalletPassword;
if (lightWalletPassword != settings.lightWalletPassword) {
settings.lightWalletPassword = lightWalletPassword;
lightWalletHostChange = true;
}
} else {
if (settings.hasOwnProperty("lightWalletPassword")) {
delete settings["lightWalletPassword"]
lightWalletHostChange = true;
}
}
} else {
if (configuration.hasOwnProperty("nodes")) {
var nodes = [];
Expand Down Expand Up @@ -2195,10 +2231,16 @@ var App = (function(App, undefined) {
if (relaunch || !App.windowIsReady()) {
App.relaunchApplication();
} else if (lightWalletHostChange && settings.lightWallet == 1) {
win.webContents.send("updateSettings", {
var updatedSettings = {
"host": settings.lightWalletHost,
"port": settings.lightWalletPort
});
};
if(settings.lightWalletUser) {
updatedSettings.lightWalletUser = settings.lightWalletUser;
updatedSettings.lightWalletPassword = settings.lightWalletPassword;
}

win.webContents.send("updateSettings", updatedSettings);
} else {
win.webContents.send("updateSettings", {
"depth": settings.depth,
Expand Down
14 changes: 6 additions & 8 deletions app/windows/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ var UI = (function(UI, undefined) {
document.getElementById("host-select").addEventListener("change", function(e) {
e.preventDefault();
if (this.value == "custom") {
document.getElementById("host").style.display = "block";
document.getElementById("host-format-example").style.display = "block";
document.getElementById("custom_light_wallet").style.display = "block";
} else {
document.getElementById("host").style.display = "none";
document.getElementById("host-format-example").style.display = "none";
document.getElementById("custom_light_wallet").style.display = "none";
}
UI.updateContentSize();
});
Expand Down Expand Up @@ -122,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 All @@ -142,8 +142,7 @@ var UI = (function(UI, undefined) {

if (_lightWalletHosts && _lightWalletHosts.length) {
document.getElementById("host-select").style.display = "block";
document.getElementById("host").style.display = "none";
document.getElementById("host-format-example").style.display = "none";
document.getElementById("custom_light_wallet").style.display = "none";
document.getElementById("host-select").innerHTML = "";

var content = "<option value='' data-i18n='select_your_host'>" + UI.t("select_your_host") + "</option>";
Expand All @@ -157,8 +156,7 @@ var UI = (function(UI, undefined) {
document.getElementById("host-select").innerHTML = content;
} else {
document.getElementById("host-select").style.display = "none";
document.getElementById("host").style.display = "block";
document.getElementById("host-format-example").style.display = "block";
document.getElementById("custom_light_wallet").style.display = "block";
}

UI.updateContentSize();
Expand Down
18 changes: 16 additions & 2 deletions app/windows/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ <h1 id="title" data-i18n="choose_wallet_type"></h1>
<div id="light-node-section">
<p class="label"><span data-i18n="host"></span>: <span id="host-error" class="error"></span></p>
<p><select name="host_select" id="host-select" style="width:100%;font-size:110%"></select></p>
<p><input type="text" name="host" id="host" placeholder="" value="" style="width:100%;font-size:110%" data-i18n="[placeholder]custom_host" /></p>
<p class="note" id="host-format-example" data-i18n="add_in_following_format_example"></p>
<div id="custom_light_wallet">
<p>
<input type="text" name="host" id="host" style="width:100%;font-size:110%" data-i18n="[placeholder]custom_host" />

<div class="input-group">
<label for="light_wallet_user" data-i18n="light_wallet_user"></label>
<input type="text" name="light_wallet_user" id="light_wallet_user" />
</div>

<div class="input-group">
<label form="light_wallet_password" data-i18n="light_wallet_password"></label>
<input type="password" name="light_wallet_password" id="light_wallet_password" />
</div>
</p>
<p class="note" id="host-format-example" data-i18n="add_in_following_format_example"></p>
</div>
</div>
<div id="full-node-section">
<p class="label"><span data-i18n="server_port"></span>: <span id="port-error" class="error"></span></p>
Expand Down
4 changes: 3 additions & 1 deletion locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,7 @@
"invalid_transaction_hash": "Invalid Transaction Hash",
"seed_character_set": "Only uppercase latin letters and the number 9 are allowed.",
"double_spend_warning": "Double Spend Warning",
"double_spend_attempt": "You are attempting to spend an already used input. You should wait for your transaction to be confirmed first before attempting to make a conflicting transaction. Do you want to continue anyway?"
"double_spend_attempt": "You are attempting to spend an already used input. You should wait for your transaction to be confirmed first before attempting to make a conflicting transaction. Do you want to continue anyway?",
"light_wallet_user":"Username",
"light_wallet_password": "Password"
}
21 changes: 17 additions & 4 deletions ui/js/ui.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ var UI = (function(UI, $, undefined) {
if (params.has("interrupt")) {
interruptAttachingToTangle = true;
}

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 @@ -98,10 +106,15 @@ var UI = (function(UI, $, undefined) {
return;
}

iota = new IOTA({
"host": connection.host,
"port": connection.port
});
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
5 changes: 5 additions & 0 deletions ui/js/ui.login.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ var UI = (function(UI, $, undefined) {
"interrupt": 1
}

if(connection.auth) {
params.auth_password = connection.auth.password;
params.auth_user = connection.auth.user;
}

window.location.href = "index.html?" + $.param(params);
});

Expand Down
43 changes: 42 additions & 1 deletion ui/js/ui.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ var UI = (function(UI, $, undefined) {
}

var changeNode = false;
var hasAuth = false;

if (settings.hasOwnProperty("host") && settings.host != connection.host) {
connection.host = settings.host;
Expand All @@ -257,8 +258,48 @@ var UI = (function(UI, $, undefined) {
changeNode = true;
}

if (settings.hasOwnProperty("lightWalletUser")) {
hasAuth = true;

if (settings.lightWalletUser != connection.lightWalletUser) {
connection.lightWalletUser = settings.lightWalletUser;
changeNode = true;
}
} else {
if(connection.hasOwnProperty("lightWalletUser")) {
delete connection["lightWalletUser"]
changeNode = true;
}
}

if (settings.hasOwnProperty("lightWalletPassword")) {
hasAuth = true;
if (settings.lightWalletPassword != connection.lightWalletPassword) {
connection.lightWalletPassword = settings.lightWalletPassword;
changeNode = true;
}
} else {
if(connection.hasOwnProperty("lightWalletPassword")) {
delete connection["lightWalletPassword"]
changeNode = true;
}
}

if (changeNode) {
iota.changeNode({"host": connection.host, "port": connection.port});
var nodeSettings = {
"host": connection.host,
"port": connection.port,
};

if (hasAuth) {
nodeSettings.auth = {
"type": "basic",
"user": connection.lightWalletUser,
"password": connection.lightWalletPassword
};
}

iota.changeNode(nodeSettings);

if (localAttachToTangle) {
iota.api.attachToTangle = localAttachToTangle;
Expand Down