aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libbugzilla.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-23 13:13:09 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-23 13:13:09 +0100
commit47e405b5b74839a53aeea2887a7cee87787d3f28 (patch)
tree81bad14cf271e119e441fc9a01e98e7f34639f41 /lib/libbugzilla.js
parentfae26306deee2d4dd95c2f4704f320b2b6747e29 (diff)
downloadbugzilla-triage-47e405b5b74839a53aeea2887a7cee87787d3f28.tar.gz
Convert to using passwords.js from Add-on SDK, not out own.
Exccessive callbacks are considered harmful!
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) {