From 3fa52129039a8c50842834cceee38dda47eb2f65 Mon Sep 17 00:00:00 2001 From: Anant Narayanan Date: Tue, 21 Jul 2009 20:59:02 -0700 Subject: [PATCH] Make change password work (bug 505570) --- .../locales/en-US/generic-change.properties | 28 +++++++++++++++++ services/sync/modules/service.js | 31 +++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 services/sync/locales/en-US/generic-change.properties diff --git a/services/sync/locales/en-US/generic-change.properties b/services/sync/locales/en-US/generic-change.properties new file mode 100644 index 000000000000..d20e80e3afe1 --- /dev/null +++ b/services/sync/locales/en-US/generic-change.properties @@ -0,0 +1,28 @@ +noPassword.alert = You must enter a password. +noPassphrase.alert = You must enter a passphrase. +passwordNoMatch.alert = Your passwords do not match. Try again! +passphraseNoMatch.alert = Your passphrases do not match. Try again! + +change.password.title = Change your Password +change.password.status.active = Changing your password... +change.password.status.success = Your password has been changed. +change.password.status.error = There was an error changing your password. +change.password.status.passwordSameAsPassphrase = The password cannot be the same as the passphrase. +change.password.status.passwordSameAsUsername = The password cannot be the same as the username. +change.password.status.passwordsDoNotMatch = The passwords you entered do not match. +change.password.status.badOldPassword = Your current password is incorrect. + +change.passphrase.title = Change your Passphrase +change.passphrase.label = Changing passphrase, please wait... +change.passphrase.error = There was an error while changing your passphrase! +change.passphrase.success = Your passphrase was successfully changed! + +reset.passphrase.title = Reset your Passphrase +reset.passphrase.label = Resetting passphrase, please wait... +reset.passphrase.error = There was an error while resetting your passphrase! +reset.passphrase.success = Your passphrase was successfully reset! + +new.passphrase.label = Enter your new passphrase +new.passphrase.confirm = Confirm your new passphrase +new.password.label = Enter your new password +new.password.confirm = Confirm your new password \ No newline at end of file diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 4d9e8539cdf4..ece8b171ab09 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -183,10 +183,16 @@ WeaveSvc.prototype = { }, get password() { return ID.get('WeaveID').password; }, - set password(value) { ID.get('WeaveID').password = value; }, + set password(value) { + ID.get('WeaveID').setTempPassword(null); + ID.get('WeaveID').password = value; + }, get passphrase() { return ID.get('WeaveCryptoID').password; }, - set passphrase(value) { ID.get('WeaveCryptoID').password = value; }, + set passphrase(value) { + ID.get('WeaveCryptoID').setTempPassword(null); + ID.get('WeaveCryptoID').password = value; + }, // chrome-provided callbacks for when the service needs a password/passphrase set onGetPassword(value) { @@ -536,6 +542,27 @@ WeaveSvc.prototype = { return true; }))(), + changePassword: function WeaveSvc_changePassword(newpass) + this._catch(this._notify("changepwd", "", function() { + function enc(x) encodeURIComponent(x); + let message = "uid=" + enc(this.username) + "&password=" + + enc(this.password) + "&new=" + enc(newpass); + let url = Svc.Prefs.get('tmpServerURL') + '0.3/api/register/chpwd'; + let res = new Weave.Resource(url); + res.authenticator = new Weave.NoOpAuthenticator(); + res.setHeader("Content-Type", "application/x-www-form-urlencoded", + "Content-Length", message.length); + + let resp = res.post(message); + if (res.lastChannel.responseStatus != 200) { + this._log.info("Password change failed: " + resp); + throw "Could not change password"; + } + + this.password = newpass; + return true; + }))(), + resetPassphrase: function WeaveSvc_resetPassphrase(newphrase) this._catch(this._notify("resetpph", "", function() { /* Make remote commands ready so we have a list of clients beforehand */