aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libbugzilla.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbugzilla.js')
-rw-r--r--lib/libbugzilla.js135
1 files changed, 79 insertions, 56 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 28e2be1..aeccead 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -73,36 +73,53 @@ function getRealBugNoSlow(bugNo, location, callback) {
}).get();
}
-function getPassword(login, domain) {
+function getPassword(login, domain, callback) {
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 pass = passUtils.getPassword(login,
- domain, BTSPassRealm);
var retObject = {
password: null, // password string or null if no password provided
withoutPass: false // whether user doesn't want to use password at all
};
- // pass === null means no appropriate password in the storage
- if (!preferences.get(prefName,false) && (pass === null)) {
- var passwordText = prompts.promptPassword(passPrompt);
- if (passwordText && passwordText.length > 0) {
- passUtils.setLogin(login, passwordText, domain,
- BTSPassRealm);
- retObject.password = passwordText;
- } else {
- var switchOff = prompts.promptYesNoCancel(switchPrompt);
- if (switchOff) {
- preferences.set(prefName,true);
+ passUtils.search({
+ username: login,
+ url: domain,
+ realm: BTSPassRealm,
+ onComplete: function onComplete([credential]) {
+ if (credential) {
+ // We found the password, just go ahead and use it
+ retObject.password = credential.password;
+ callback(retObject);
+ } else {
+ // We don't have a stored password, ask for one
+ var passwordText = prompts.promptPassword(passPrompt);
+ if (passwordText && passwordText.length > 0) {
+ // Right, we've got it … store it and then use it.
+ retObject.password = passwordText;
+ passUtils.store({
+ username: login,
+ password: passwordText,
+ url: domain,
+ realm: BTSPassRealm,
+ onComplete: function onComplete() {
+ callback(retObject);
+ }
+ });
+ } else {
+ // We don't have password, and user haven't entered one?
+ // Does he want to live passwordless?
+ // FIXME should we call the callback at all?
+ var switchOff = prompts.promptYesNoCancel(switchPrompt);
+ if (switchOff) {
+ preferences.set(prefName,true);
+ }
+ retObject.withoutPass = switchOff;
+ callback(retObject);
+ }
}
- retObject.withoutPass = switchOff;
}
- } else {
- retObject.password = pass;
- }
- return retObject;
+ });
}
exports.changeJSONURL = function changeJSONURL() {
@@ -184,20 +201,21 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
var locURL = new urlMod.URL(locationLoginObj.location);
var passDomain = locURL.scheme + "://" + locURL.host;
- var passwObj = getPassword(locationLoginObj.login, passDomain);
- // In order to avoid sending whole password to the content script,
- // we are sending just these two Booleans.
- config.constantData.passwordState = {
- passAvailable: (passwObj.password !== null),
- withoutPass: passwObj.withoutPass
- };
-
- callback(new Message("CreateButtons", {
- instPkgs: installedPackages,
- constData: config.constantData,
- config: config.configData,
- kNodes: config.gJSONData.configData.killNodes
- }));
+ getPassword(locationLoginObj.login, passDomain, function (passwObj) {
+ // In order to avoid sending whole password to the content script,
+ // we are sending just these two Booleans.
+ config.constantData.passwordState = {
+ passAvailable: (passwObj.password !== null),
+ withoutPass: passwObj.withoutPass
+ };
+
+ callback(new Message("CreateButtons", {
+ instPkgs: installedPackages,
+ constData: config.constantData,
+ config: config.configData,
+ kNodes: config.gJSONData.configData.killNodes
+ }));
+ });
};
exports.getClipboard = function getClipboard(cb) {
@@ -261,29 +279,34 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment)
// Make a XML-RPC call ... most of the business logic should stay in the content script
exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) {
var urlObj = urlMod.URL(url);
- var passwObj = getPassword(login, urlObj.schema + "://" + urlObj.host);
- if (!passwObj.password) {
- return null; // TODO this should happen, only when user presses Escape in password prompt
- }
-
- var msg = new xrpc.XMLRPCMessage(method);
- params.forEach(function (par) {
- msg.addParameter(par);
- });
- msg.addParameter(login);
- msg.addParameter(passwObj.password);
-
- Request({
- url: url,
- onComplete: function(response) {
- if (response.status == 200) {
- var resp = parseXMLfromString(response.text);
- callback(resp.toXMLString());
+ getPassword(login,
+ urlObj.schema + "://" + urlObj.host,
+ function (passwObj) {
+ if (!passwObj.password) {
+ // TODO this should happen, only when user presses Escape in password prompt
+ return null;
}
- },
- content: msg.xml(),
- contentType: "text/xml"
- }).post();
+
+ var msg = new xrpc.XMLRPCMessage(method);
+ params.forEach(function (par) {
+ msg.addParameter(par);
+ });
+ msg.addParameter(login);
+ msg.addParameter(passwObj.password);
+
+ Request({
+ url: url,
+ onComplete: function(response) {
+ if (response.status == 200) {
+ var resp = parseXMLfromString(response.text);
+ callback(resp.toXMLString());
+ }
+ },
+ content: msg.xml(),
+ contentType: "text/xml"
+ }).post();
+ }
+ );
};
exports.initialize = function initialize(config, callback) {