From 8d49d498dd10684e5468a0683c33dfe8bcee2755 Mon Sep 17 00:00:00 2001 From: Guillaume Viguier Date: Mon, 10 Jul 2017 11:37:39 +0200 Subject: #29 - error message when server URL missing scheme --- src/components/nsNextcloud.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/nsNextcloud.js b/src/components/nsNextcloud.js index f016e06..b4334cb 100644 --- a/src/components/nsNextcloud.js +++ b/src/components/nsNextcloud.js @@ -51,12 +51,16 @@ function wwwFormUrlEncode (aStr) { .replace(/\@/g, '%40'); } +function validURL(value) { + return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value); +} + /** * Our Nextcloud Provider */ function Nextcloud () { - //this.log = Log4Moz.getConfiguredLogger("Nextcloud", Log4Moz.Level.Info, Log4Moz.Level.Debug, - // Log4Moz.Level.Debug); + // this.log = Log4Moz.getConfiguredLogger("Nextcloud", Log4Moz.Level.Info, Log4Moz.Level.Debug, + // Log4Moz.Level.Debug); this.log = Log4Moz.getConfiguredLogger("Nextcloud"); } @@ -379,7 +383,7 @@ Nextcloud.prototype = { ], 2); - if (authPrompter.promptPassword( + if (validURL(serverUrl) && authPrompter.promptPassword( this.displayName, promptString, serverUrl, @@ -411,8 +415,15 @@ Nextcloud.prototype = { logon: function nsNc_logon (successCallback, failureCallback, aWithUI) { this.log.info("Logging in, aWithUI = " + aWithUI); - if (this._password == undefined || !this._password) + if (this._password == undefined || !this._password) { this._password = this.getPassword(this._userName, !aWithUI); + } + + if (this._password == "") { + this.log.error('Could not retrieve password'); + this._loggedIn = false; + failureCallback(); + } this.log.info("Sending login information..."); -- cgit v1.2.3