From 3f70ba468a91e0f5abe20034dd50e3c63a6fcb1a Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Fri, 16 Jul 2010 04:25:30 +0200 Subject: Use Firefox nsILoginManager to store password and make it optional. Fixes #16. --- lib/bzpage.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'lib/bzpage.js') diff --git a/lib/bzpage.js b/lib/bzpage.js index 3ac61d6..45e1196 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -3,6 +3,7 @@ // http://www.opensource.org/licenses/mit-license.php "use strict"; var util = require("util"); +var passUtils = require("passwords"); var apiUtils = require("api-utils"); var simpleStorage = require("simple-storage"); var preferences = require("preferences-service"); @@ -13,6 +14,7 @@ var NumberOfFrames = 7; var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id="; var BTSPrefNS = "bugzilla-triage.setting."; exports.BTSPrefNS = BTSPrefNS; +var BTSPassRealm = "BTSXMLRPCPass"; // ==================================================================================== // BZPage's methods @@ -679,15 +681,30 @@ BZPage.prototype.getAttachments = function getAttachments () { * * @return String with the password */ -BZPage.prototype.getPassword = function getPassword () { - var prefName = BTSPrefNS+"BZpassword"; - if (preferences.isSet(prefName)) { - return preferences.get(prefName,undefined); - } else { - var passwordText = util.getPassword(); - if (passwordText) { - preferences.set(prefName, passwordText); +BZPage.prototype.getPassword = function getPassword (login) { + var passPrompt = "Enter your Bugzilla password for fixing MIME attachment types"; + var switchPrompt = "Do you want to switch off features requiring password completely?"; + var prefName = BTSPrefNS+"withoutPassowrd"; + var loc = this.win.location; + var domain = loc.protocol + "//" + loc.hostname; + + var pass = passUtils.getPassword(login, domain, BTSPassRealm); + // pass === null means no appropriate password in the storage + if (!preferences.get(prefName,false) && (pass === null)) { + var passwordText = util.getPassword(passPrompt); + if (passwordText && passwordText.length > 0) { + passUtils.setLogin(login, passwordText, domain, + BTSPassRealm); + return passwordText; + } else { + var switchOff = util.promptOKNoCancel(switchPrompt); + if (switchOff) { + preferences.set(prefName,true); + } + return null; } + } else { + return pass; } }; -- cgit