2010-08-02 16:37:56 -07:00
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
|
* License.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Weave.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
* Edward Lee <edilee@mozilla.com>
|
|
|
|
|
* Mike Connor <mconnor@mozilla.com>
|
|
|
|
|
* Paul O’Shannessy <paul@oshannessy.com>
|
2010-09-07 18:37:46 -07:00
|
|
|
|
* Philipp von Weitershausen <philipp@weitershausen.de>
|
2010-08-02 16:37:56 -07:00
|
|
|
|
*
|
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
|
*
|
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
Components.utils.import("resource://services-sync/main.js");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
|
|
let Change = {
|
|
|
|
|
_dialog: null,
|
|
|
|
|
_dialogType: null,
|
|
|
|
|
_status: null,
|
|
|
|
|
_statusIcon: null,
|
|
|
|
|
_firstBox: null,
|
|
|
|
|
_secondBox: null,
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
get _passphraseBox() {
|
|
|
|
|
delete this._passphraseBox;
|
|
|
|
|
return this._passphraseBox = document.getElementById("passphraseBox");
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
get _currentPasswordInvalid() {
|
|
|
|
|
return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get _updatingPassphrase() {
|
|
|
|
|
return this._dialogType == "UpdatePassphrase";
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad: function Change_onLoad() {
|
|
|
|
|
/* Load labels */
|
|
|
|
|
let introText = document.getElementById("introText");
|
|
|
|
|
let introText2 = document.getElementById("introText2");
|
|
|
|
|
let warningText = document.getElementById("warningText");
|
|
|
|
|
|
|
|
|
|
// load some other elements & info from the window
|
|
|
|
|
this._dialog = document.getElementById("change-dialog");
|
|
|
|
|
this._dialogType = window.arguments[0];
|
2011-02-03 10:54:00 -08:00
|
|
|
|
this._duringSetup = window.arguments[1];
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._status = document.getElementById("status");
|
|
|
|
|
this._statusIcon = document.getElementById("statusIcon");
|
2010-09-23 15:19:42 -07:00
|
|
|
|
this._statusRow = document.getElementById("statusRow");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._firstBox = document.getElementById("textBox1");
|
|
|
|
|
this._secondBox = document.getElementById("textBox2");
|
|
|
|
|
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._dialog.getButton("finish").disabled = true;
|
|
|
|
|
this._dialog.getButton("back").hidden = true;
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._stringBundle =
|
|
|
|
|
Services.strings.createBundle("chrome://browser/locale/syncGenericChange.properties");
|
|
|
|
|
|
|
|
|
|
switch (this._dialogType) {
|
|
|
|
|
case "UpdatePassphrase":
|
|
|
|
|
case "ResetPassphrase":
|
2010-09-07 18:37:46 -07:00
|
|
|
|
document.getElementById("textBox1Row").hidden = true;
|
|
|
|
|
document.getElementById("textBox2Row").hidden = true;
|
2011-01-24 12:48:36 -08:00
|
|
|
|
document.getElementById("passphraseLabel").value
|
|
|
|
|
= this._str("new.synckey.label");
|
|
|
|
|
document.getElementById("passphraseSpacer").hidden = false;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
if (this._updatingPassphrase) {
|
2011-01-24 12:48:36 -08:00
|
|
|
|
document.getElementById("passphraseHelpBox").hidden = false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
document.title = this._str("new.synckey.title");
|
2011-01-18 22:17:18 -08:00
|
|
|
|
introText.textContent = this._str("new.synckey2.introText");
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._dialog.getButton("finish").label
|
|
|
|
|
= this._str("new.synckey.acceptButton");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2011-01-24 12:48:36 -08:00
|
|
|
|
document.getElementById("generatePassphraseButton").hidden = false;
|
2011-01-27 22:10:31 -08:00
|
|
|
|
document.getElementById("passphraseBackupButtons").hidden = false;
|
2010-11-30 20:39:32 -08:00
|
|
|
|
this._passphraseBox.setAttribute("readonly", "true");
|
2010-09-07 18:37:46 -07:00
|
|
|
|
let pp = Weave.Service.passphrase;
|
2010-11-30 20:39:32 -08:00
|
|
|
|
if (Weave.Utils.isPassphrase(pp))
|
|
|
|
|
pp = Weave.Utils.hyphenatePassphrase(pp);
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._passphraseBox.value = pp;
|
|
|
|
|
this._passphraseBox.focus();
|
2011-05-02 09:26:31 -07:00
|
|
|
|
document.title = this._str("change.synckey2.title");
|
2011-01-24 12:48:36 -08:00
|
|
|
|
introText.textContent = this._str("change.synckey.introText2");
|
|
|
|
|
warningText.textContent = this._str("change.synckey2.warningText");
|
|
|
|
|
this._dialog.getButton("finish").label
|
|
|
|
|
= this._str("change.synckey.acceptButton");
|
2011-02-03 10:54:00 -08:00
|
|
|
|
if (this._duringSetup) {
|
|
|
|
|
this._dialog.getButton("finish").disabled = false;
|
|
|
|
|
}
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "ChangePassword":
|
2010-09-07 18:37:46 -07:00
|
|
|
|
document.getElementById("passphraseRow").hidden = true;
|
|
|
|
|
let box1label = document.getElementById("textBox1Label");
|
|
|
|
|
let box2label = document.getElementById("textBox2Label");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
box1label.value = this._str("new.password.label");
|
|
|
|
|
|
|
|
|
|
if (this._currentPasswordInvalid) {
|
|
|
|
|
document.title = this._str("new.password.title");
|
|
|
|
|
introText.textContent = this._str("new.password.introText");
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._dialog.getButton("finish").label
|
|
|
|
|
= this._str("new.password.acceptButton");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
document.getElementById("textBox2Row").hidden = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
document.title = this._str("change.password.title");
|
|
|
|
|
box2label.value = this._str("new.password.confirm");
|
2010-09-15 06:55:04 -07:00
|
|
|
|
introText.textContent = this._str("change.password2.introText");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
warningText.textContent = this._str("change.password.warningText");
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._dialog.getButton("finish").label
|
|
|
|
|
= this._str("change.password.acceptButton");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-01-24 12:48:36 -08:00
|
|
|
|
document.getElementById("change-page")
|
|
|
|
|
.setAttribute("label", document.title);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_clearStatus: function _clearStatus() {
|
|
|
|
|
this._status.value = "";
|
|
|
|
|
this._statusIcon.removeAttribute("status");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_updateStatus: function Change__updateStatus(str, state) {
|
|
|
|
|
this._updateStatusWithString(this._str(str), state);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_updateStatusWithString: function Change__updateStatusWithString(string, state) {
|
2010-10-14 02:12:52 -07:00
|
|
|
|
this._statusRow.hidden = false;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._status.value = string;
|
|
|
|
|
this._statusIcon.setAttribute("status", state);
|
|
|
|
|
|
|
|
|
|
let error = state == "error";
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._dialog.getButton("cancel").disabled = !error;
|
|
|
|
|
this._dialog.getButton("finish").disabled = !error;
|
2010-10-14 02:12:52 -07:00
|
|
|
|
document.getElementById("printSyncKeyButton").disabled = !error;
|
|
|
|
|
document.getElementById("saveSyncKeyButton").disabled = !error;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
if (state == "success")
|
|
|
|
|
window.setTimeout(window.close, 1500);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onDialogAccept: function() {
|
|
|
|
|
switch (this._dialogType) {
|
|
|
|
|
case "UpdatePassphrase":
|
|
|
|
|
case "ResetPassphrase":
|
|
|
|
|
return this.doChangePassphrase();
|
|
|
|
|
break;
|
|
|
|
|
case "ChangePassword":
|
|
|
|
|
return this.doChangePassword();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
doGeneratePassphrase: function () {
|
2010-11-30 20:39:32 -08:00
|
|
|
|
let passphrase = Weave.Utils.generatePassphrase();
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._passphraseBox.value = Weave.Utils.hyphenatePassphrase(passphrase);
|
|
|
|
|
this._dialog.getButton("finish").disabled = false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
doChangePassphrase: function Change_doChangePassphrase() {
|
2010-11-30 20:39:32 -08:00
|
|
|
|
let pp = Weave.Utils.normalizePassphrase(this._passphraseBox.value);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (this._updatingPassphrase) {
|
2010-09-07 18:37:46 -07:00
|
|
|
|
Weave.Service.passphrase = pp;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (Weave.Service.login()) {
|
2010-09-15 06:55:04 -07:00
|
|
|
|
this._updateStatus("change.synckey2.success", "success");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
Weave.Service.persistLogin();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this._updateStatus("new.passphrase.status.incorrect", "error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this._updateStatus("change.synckey.label", "active");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
if (Weave.Service.changePassphrase(pp))
|
2010-09-15 06:55:04 -07:00
|
|
|
|
this._updateStatus("change.synckey2.success", "success");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
else
|
2010-09-15 06:55:04 -07:00
|
|
|
|
this._updateStatus("change.synckey2.error", "error");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
doChangePassword: function Change_doChangePassword() {
|
|
|
|
|
if (this._currentPasswordInvalid) {
|
|
|
|
|
Weave.Service.password = this._firstBox.value;
|
|
|
|
|
if (Weave.Service.login()) {
|
|
|
|
|
this._updateStatus("change.password.status.success", "success");
|
|
|
|
|
Weave.Service.persistLogin();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this._updateStatus("new.password.status.incorrect", "error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this._updateStatus("change.password.status.active", "active");
|
|
|
|
|
|
|
|
|
|
if (Weave.Service.changePassword(this._firstBox.value))
|
|
|
|
|
this._updateStatus("change.password.status.success", "success");
|
|
|
|
|
else
|
|
|
|
|
this._updateStatus("change.password.status.error", "error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2010-11-30 20:39:32 -08:00
|
|
|
|
validate: function (event) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let valid = false;
|
|
|
|
|
let errorString = "";
|
|
|
|
|
|
|
|
|
|
if (this._dialogType == "ChangePassword") {
|
|
|
|
|
if (this._currentPasswordInvalid)
|
|
|
|
|
[valid, errorString] = gSyncUtils.validatePassword(this._firstBox);
|
|
|
|
|
else
|
|
|
|
|
[valid, errorString] = gSyncUtils.validatePassword(this._firstBox, this._secondBox);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-11-30 20:39:32 -08:00
|
|
|
|
if (!this._updatingPassphrase)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-12-09 22:53:08 -08:00
|
|
|
|
valid = this._passphraseBox.value != "";
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errorString == "")
|
|
|
|
|
this._clearStatus();
|
|
|
|
|
else
|
|
|
|
|
this._updateStatusWithString(errorString, "error");
|
|
|
|
|
|
2010-09-23 15:19:42 -07:00
|
|
|
|
this._statusRow.hidden = valid;
|
2011-01-24 12:48:36 -08:00
|
|
|
|
this._dialog.getButton("finish").disabled = !valid;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_str: function Change__string(str) {
|
|
|
|
|
return this._stringBundle.GetStringFromName(str);
|
|
|
|
|
}
|
|
|
|
|
};
|