aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/bzpage.js8
-rw-r--r--lib/main.js4
-rw-r--r--lib/passwords.js57
-rw-r--r--lib/util.js9
4 files changed, 69 insertions, 9 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index d9d679d..3ac61d6 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -11,8 +11,8 @@ var Color = require("color").Color;
var TriagedDistro = 13;
var NumberOfFrames = 7;
var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id=";
-var BSTPrefNS = "bugzilla-triage.setting.";
-exports.BSTPrefNS = BSTPrefNS;
+var BTSPrefNS = "bugzilla-triage.setting.";
+exports.BTSPrefNS = BTSPrefNS;
// ====================================================================================
// BZPage's methods
@@ -66,7 +66,7 @@ var BZPage = function BZPage(win, config) {
this.doc.getElementById("configurationButton").addEventListener(
"click",
function(evt) {
- var prfNm = BSTPrefNS+"JSONURL";
+ var prfNm = BTSPrefNS+"JSONURL";
var url = preferences.get(prfNm,"");
var reply = that.win.prompt("New location of JSON configuration file",url);
@@ -680,7 +680,7 @@ BZPage.prototype.getAttachments = function getAttachments () {
* @return String with the password
*/
BZPage.prototype.getPassword = function getPassword () {
- var prefName = BSTPrefNS+"BZpassword";
+ var prefName = BTSPrefNS+"BZpassword";
if (preferences.isSet(prefName)) {
return preferences.get(prefName,undefined);
} else {
diff --git a/lib/main.js b/lib/main.js
index e14f947..937f237 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -19,7 +19,7 @@ var urlMod = require("url");
var selfMod = require("self");
var Request = require("request").Request;
var preferences = require("preferences-service");
-var BSTPrefNS = require("bzpage").BSTPrefNS;
+var BTSPrefNS = require("bzpage").BTSPrefNS;
// Use my JSON for now before it is fixed for general public
var JSONURLDefault = "https://fedorahosted.org/released"+
"/bugzilla-triage-scripts/Config_data.json";
@@ -86,7 +86,7 @@ function skipThisPage(doc) {
}
function initialize(callback) {
- var prefName = BSTPrefNS+"JSONURL";
+ var prefName = BTSPrefNS+"JSONURL";
var urlStr = "";
if (preferences.isSet(prefName)) {
diff --git a/lib/passwords.js b/lib/passwords.js
new file mode 100644
index 0000000..49b945f
--- /dev/null
+++ b/lib/passwords.js
@@ -0,0 +1,57 @@
+/*jslint forin: true, rhino: true, onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+"use strict";
+var {Cc,Ci,components} = require("chrome");
+
+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;
+ }
+ }
+};
diff --git a/lib/util.js b/lib/util.js
index b72f7f0..f582d1d 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -197,7 +197,10 @@ var filterByRegexp = exports.filterByRegexp =
*
* @return String with the password
*/
-var getPassword = exports.getPassword = function getPassword() {
+var getPassword = exports.getPassword = function getPassword(prompt) {
+ if (prompt === null) {
+ prompt = "Enter password:";
+ }
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var password = {
@@ -206,7 +209,7 @@ var getPassword = exports.getPassword = function getPassword() {
var check = {
value : true
}; // default the checkbox to true
- var result = prompts.promptPassword(null, "Title", "Enter password:",
+ var result = prompts.promptPassword(null, "Title", prompt,
password, null, check);
// result is true if OK was pressed, false if cancel was pressed.
// password.value is set if OK was pressed.
@@ -216,4 +219,4 @@ var getPassword = exports.getPassword = function getPassword() {
} else {
return undefined;
}
-}; \ No newline at end of file
+};