diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-03-23 13:13:09 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-03-23 13:13:09 +0100 |
commit | 47e405b5b74839a53aeea2887a7cee87787d3f28 (patch) | |
tree | 81bad14cf271e119e441fc9a01e98e7f34639f41 /lib/passwords.js | |
parent | fae26306deee2d4dd95c2f4704f320b2b6747e29 (diff) | |
download | bugzilla-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/passwords.js')
-rw-r--r-- | lib/passwords.js | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/lib/passwords.js b/lib/passwords.js deleted file mode 100644 index af76f47..0000000 --- a/lib/passwords.js +++ /dev/null @@ -1,58 +0,0 @@ -// Released under the MIT/X11 license -// http://www.opensource.org/licenses/mit-license.php -"use strict"; -var Cc = require("chrome").Cc; -var Ci = require("chrome").Ci; -var components = require("chrome").components; - -function getLoginInfo(username, pass, - domain, realm) { - var nsLoginInfo = new components. - Constructor("@mozilla.org/login-manager/loginInfo;1", - Ci.nsILoginInfo, "init"); - return new nsLoginInfo(domain, - null, realm, username, pass, "", ""); -} - -function getPasswordManager() { - return Cc["@mozilla.org/login-manager;1"]. - getService(Ci.nsILoginManager); -} - -exports.setLogin = function setLogin (username, pass, - domain, realm) { - var lInfo = getLoginInfo(username, pass, domain, realm); - getPasswordManager().addLogin(lInfo); -}; - -var getPassword = exports.getPassword = function getPassword(username, - domain, realm) { - - var pwMgr = getPasswordManager(); - var logins = pwMgr.findLogins({}, domain, "", realm); - var ourLogins = Array.filter(logins, function (x) { - return (x.username = username); - }, this); - // What to do when we have more than one password? - if (ourLogins.length > 0) { - return ourLogins[0].password; - } else { - return null; - } -}; - -exports.removeLogin = function removeLogin(username, - domain, realm) { - var pass = getPassword(username, domain, realm); - var pwMgr = getPasswordManager(); - var logins = pwMgr.findLogins({}, domain, "", realm); - - // Don't do Array.forEach here ... emulating break there - // is an abomination - for (var i = 0, ii = logins.length; i < ii; i++) { - if (logins[i].username === username) { - pwMgr.removeLogin(logins[i]); - break; - } - } -}; |