Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Update recovery data after changing password #1113

Merged
merged 2 commits into from
Dec 10, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ stellarClient.config(function($httpProvider, $stateProvider, $urlRouterProvider,
.state('change_password_v2', {
templateUrl: 'states/change_password_v2.html',
authenticate: false,
params: {'username': 0, 'masterKey': 0, 'totpRequired': false}
params: {'username': 0, 'masterKey': 0, 'recoveryCode': 0, 'totpRequired': false}
})
.state('settings', {
url: '/settings',
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/controllers/change-password-v2-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ angular.module('stellarClient').controller('ChangePasswordV2Ctrl', function($sco
return wallet.changePassword({
newPassword: $scope.data.password,
secretKey: keychainData.signingKeys.secretKey
}).then(function() {
return wallet;
});
}).then(function(wallet) {
var keychainData = JSON.parse(wallet.getKeychainData());
return wallet.enableRecovery({
recoveryCode: $stateParams.recoveryCode,
secretKey: keychainData.signingKeys.secretKey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is getting a little hard to read it might be a good time to organize some of this logic into helper methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to avoid the extra then "pass through" by isolating the paths that need access to wallet into one block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I reorganized this code to be easier to read.

});
}).then(function() {
FlashMessages.add({
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/controllers/recovery-v2-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ angular.module('stellarClient').controller('RecoveryV2Ctrl', function($scope, $s
$state.go('change_password_v2', {
username: params.username,
masterKey: params.masterKey,
recoveryCode: params.recoveryCode,
totpRequired: $scope.totpRequired
});
});
Expand Down Expand Up @@ -127,6 +128,7 @@ angular.module('stellarClient').controller('RecoveryV2Ctrl', function($scope, $s

StellarWallet.recover(data).then(function(masterKey) {
params.masterKey = masterKey;
params.recoveryCode = fullRecoveryCode;
deferred.resolve(params);
}).catch(StellarWallet.errors.Forbidden, function() {
$scope.usernameError = "Invalid username or recovery code.";
Expand Down