browser/base/content/sync/genericChange.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 const Ci = Components.interfaces;
michael@0 6 const Cc = Components.classes;
michael@0 7
michael@0 8 Components.utils.import("resource://services-sync/main.js");
michael@0 9 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 10
michael@0 11 let Change = {
michael@0 12 _dialog: null,
michael@0 13 _dialogType: null,
michael@0 14 _status: null,
michael@0 15 _statusIcon: null,
michael@0 16 _firstBox: null,
michael@0 17 _secondBox: null,
michael@0 18
michael@0 19 get _passphraseBox() {
michael@0 20 delete this._passphraseBox;
michael@0 21 return this._passphraseBox = document.getElementById("passphraseBox");
michael@0 22 },
michael@0 23
michael@0 24 get _currentPasswordInvalid() {
michael@0 25 return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
michael@0 26 },
michael@0 27
michael@0 28 get _updatingPassphrase() {
michael@0 29 return this._dialogType == "UpdatePassphrase";
michael@0 30 },
michael@0 31
michael@0 32 onLoad: function Change_onLoad() {
michael@0 33 /* Load labels */
michael@0 34 let introText = document.getElementById("introText");
michael@0 35 let introText2 = document.getElementById("introText2");
michael@0 36 let warningText = document.getElementById("warningText");
michael@0 37
michael@0 38 // load some other elements & info from the window
michael@0 39 this._dialog = document.getElementById("change-dialog");
michael@0 40 this._dialogType = window.arguments[0];
michael@0 41 this._duringSetup = window.arguments[1];
michael@0 42 this._status = document.getElementById("status");
michael@0 43 this._statusIcon = document.getElementById("statusIcon");
michael@0 44 this._statusRow = document.getElementById("statusRow");
michael@0 45 this._firstBox = document.getElementById("textBox1");
michael@0 46 this._secondBox = document.getElementById("textBox2");
michael@0 47
michael@0 48 this._dialog.getButton("finish").disabled = true;
michael@0 49 this._dialog.getButton("back").hidden = true;
michael@0 50
michael@0 51 this._stringBundle =
michael@0 52 Services.strings.createBundle("chrome://browser/locale/syncGenericChange.properties");
michael@0 53
michael@0 54 switch (this._dialogType) {
michael@0 55 case "UpdatePassphrase":
michael@0 56 case "ResetPassphrase":
michael@0 57 document.getElementById("textBox1Row").hidden = true;
michael@0 58 document.getElementById("textBox2Row").hidden = true;
michael@0 59 document.getElementById("passphraseLabel").value
michael@0 60 = this._str("new.recoverykey.label");
michael@0 61 document.getElementById("passphraseSpacer").hidden = false;
michael@0 62
michael@0 63 if (this._updatingPassphrase) {
michael@0 64 document.getElementById("passphraseHelpBox").hidden = false;
michael@0 65 document.title = this._str("new.recoverykey.title");
michael@0 66 introText.textContent = this._str("new.recoverykey.introText");
michael@0 67 this._dialog.getButton("finish").label
michael@0 68 = this._str("new.recoverykey.acceptButton");
michael@0 69 }
michael@0 70 else {
michael@0 71 document.getElementById("generatePassphraseButton").hidden = false;
michael@0 72 document.getElementById("passphraseBackupButtons").hidden = false;
michael@0 73 this._passphraseBox.setAttribute("readonly", "true");
michael@0 74 let pp = Weave.Service.identity.syncKey;
michael@0 75 if (Weave.Utils.isPassphrase(pp))
michael@0 76 pp = Weave.Utils.hyphenatePassphrase(pp);
michael@0 77 this._passphraseBox.value = pp;
michael@0 78 this._passphraseBox.focus();
michael@0 79 document.title = this._str("change.recoverykey.title");
michael@0 80 introText.textContent = this._str("change.synckey.introText2");
michael@0 81 warningText.textContent = this._str("change.recoverykey.warningText");
michael@0 82 this._dialog.getButton("finish").label
michael@0 83 = this._str("change.recoverykey.acceptButton");
michael@0 84 if (this._duringSetup) {
michael@0 85 this._dialog.getButton("finish").disabled = false;
michael@0 86 }
michael@0 87 }
michael@0 88 break;
michael@0 89 case "ChangePassword":
michael@0 90 document.getElementById("passphraseRow").hidden = true;
michael@0 91 let box1label = document.getElementById("textBox1Label");
michael@0 92 let box2label = document.getElementById("textBox2Label");
michael@0 93 box1label.value = this._str("new.password.label");
michael@0 94
michael@0 95 if (this._currentPasswordInvalid) {
michael@0 96 document.title = this._str("new.password.title");
michael@0 97 introText.textContent = this._str("new.password.introText");
michael@0 98 this._dialog.getButton("finish").label
michael@0 99 = this._str("new.password.acceptButton");
michael@0 100 document.getElementById("textBox2Row").hidden = true;
michael@0 101 }
michael@0 102 else {
michael@0 103 document.title = this._str("change.password.title");
michael@0 104 box2label.value = this._str("new.password.confirm");
michael@0 105 introText.textContent = this._str("change.password3.introText");
michael@0 106 warningText.textContent = this._str("change.password.warningText");
michael@0 107 this._dialog.getButton("finish").label
michael@0 108 = this._str("change.password.acceptButton");
michael@0 109 }
michael@0 110 break;
michael@0 111 }
michael@0 112 document.getElementById("change-page")
michael@0 113 .setAttribute("label", document.title);
michael@0 114 },
michael@0 115
michael@0 116 _clearStatus: function _clearStatus() {
michael@0 117 this._status.value = "";
michael@0 118 this._statusIcon.removeAttribute("status");
michael@0 119 },
michael@0 120
michael@0 121 _updateStatus: function Change__updateStatus(str, state) {
michael@0 122 this._updateStatusWithString(this._str(str), state);
michael@0 123 },
michael@0 124
michael@0 125 _updateStatusWithString: function Change__updateStatusWithString(string, state) {
michael@0 126 this._statusRow.hidden = false;
michael@0 127 this._status.value = string;
michael@0 128 this._statusIcon.setAttribute("status", state);
michael@0 129
michael@0 130 let error = state == "error";
michael@0 131 this._dialog.getButton("cancel").disabled = !error;
michael@0 132 this._dialog.getButton("finish").disabled = !error;
michael@0 133 document.getElementById("printSyncKeyButton").disabled = !error;
michael@0 134 document.getElementById("saveSyncKeyButton").disabled = !error;
michael@0 135
michael@0 136 if (state == "success")
michael@0 137 window.setTimeout(window.close, 1500);
michael@0 138 },
michael@0 139
michael@0 140 onDialogAccept: function() {
michael@0 141 switch (this._dialogType) {
michael@0 142 case "UpdatePassphrase":
michael@0 143 case "ResetPassphrase":
michael@0 144 return this.doChangePassphrase();
michael@0 145 break;
michael@0 146 case "ChangePassword":
michael@0 147 return this.doChangePassword();
michael@0 148 break;
michael@0 149 }
michael@0 150 },
michael@0 151
michael@0 152 doGeneratePassphrase: function () {
michael@0 153 let passphrase = Weave.Utils.generatePassphrase();
michael@0 154 this._passphraseBox.value = Weave.Utils.hyphenatePassphrase(passphrase);
michael@0 155 this._dialog.getButton("finish").disabled = false;
michael@0 156 },
michael@0 157
michael@0 158 doChangePassphrase: function Change_doChangePassphrase() {
michael@0 159 let pp = Weave.Utils.normalizePassphrase(this._passphraseBox.value);
michael@0 160 if (this._updatingPassphrase) {
michael@0 161 Weave.Service.identity.syncKey = pp;
michael@0 162 if (Weave.Service.login()) {
michael@0 163 this._updateStatus("change.recoverykey.success", "success");
michael@0 164 Weave.Service.persistLogin();
michael@0 165 Weave.Service.scheduler.delayedAutoConnect(0);
michael@0 166 }
michael@0 167 else {
michael@0 168 this._updateStatus("new.passphrase.status.incorrect", "error");
michael@0 169 }
michael@0 170 }
michael@0 171 else {
michael@0 172 this._updateStatus("change.recoverykey.label", "active");
michael@0 173
michael@0 174 if (Weave.Service.changePassphrase(pp))
michael@0 175 this._updateStatus("change.recoverykey.success", "success");
michael@0 176 else
michael@0 177 this._updateStatus("change.recoverykey.error", "error");
michael@0 178 }
michael@0 179
michael@0 180 return false;
michael@0 181 },
michael@0 182
michael@0 183 doChangePassword: function Change_doChangePassword() {
michael@0 184 if (this._currentPasswordInvalid) {
michael@0 185 Weave.Service.identity.basicPassword = this._firstBox.value;
michael@0 186 if (Weave.Service.login()) {
michael@0 187 this._updateStatus("change.password.status.success", "success");
michael@0 188 Weave.Service.persistLogin();
michael@0 189 }
michael@0 190 else {
michael@0 191 this._updateStatus("new.password.status.incorrect", "error");
michael@0 192 }
michael@0 193 }
michael@0 194 else {
michael@0 195 this._updateStatus("change.password.status.active", "active");
michael@0 196
michael@0 197 if (Weave.Service.changePassword(this._firstBox.value))
michael@0 198 this._updateStatus("change.password.status.success", "success");
michael@0 199 else
michael@0 200 this._updateStatus("change.password.status.error", "error");
michael@0 201 }
michael@0 202
michael@0 203 return false;
michael@0 204 },
michael@0 205
michael@0 206 validate: function (event) {
michael@0 207 let valid = false;
michael@0 208 let errorString = "";
michael@0 209
michael@0 210 if (this._dialogType == "ChangePassword") {
michael@0 211 if (this._currentPasswordInvalid)
michael@0 212 [valid, errorString] = gSyncUtils.validatePassword(this._firstBox);
michael@0 213 else
michael@0 214 [valid, errorString] = gSyncUtils.validatePassword(this._firstBox, this._secondBox);
michael@0 215 }
michael@0 216 else {
michael@0 217 if (!this._updatingPassphrase)
michael@0 218 return;
michael@0 219
michael@0 220 valid = this._passphraseBox.value != "";
michael@0 221 }
michael@0 222
michael@0 223 if (errorString == "")
michael@0 224 this._clearStatus();
michael@0 225 else
michael@0 226 this._updateStatusWithString(errorString, "error");
michael@0 227
michael@0 228 this._statusRow.hidden = valid;
michael@0 229 this._dialog.getButton("finish").disabled = !valid;
michael@0 230 },
michael@0 231
michael@0 232 _str: function Change__string(str) {
michael@0 233 return this._stringBundle.GetStringFromName(str);
michael@0 234 }
michael@0 235 };

mercurial