-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
"jquery": true, | ||
"predef": [ | ||
"_", | ||
"angular", | ||
"angular", | ||
"bs58", | ||
"BigNumber", | ||
"iso4217", | ||
"Modernizr", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ angular.module('stellarClient').controller('RecoveryV2Ctrl', function($scope, $s | |
|
||
return $q.when(params) | ||
.then(validate) | ||
.then(getServerRecoveryCode) | ||
.then(recover) | ||
.then(function (params) { | ||
$state.go('change_password_v2', { | ||
|
@@ -61,19 +62,63 @@ angular.module('stellarClient').controller('RecoveryV2Ctrl', function($scope, $s | |
return $q.reject(); | ||
} | ||
|
||
// Append suffix | ||
params.username = params.username+'@stellar.org'; | ||
|
||
return params; | ||
} | ||
|
||
function getServerRecoveryCode(params) { | ||
var deferred = $q.defer(); | ||
|
||
var data = { | ||
username: params.username, | ||
userRecoveryCode: params.recoveryCode | ||
}; | ||
|
||
$http.post(Options.API_SERVER + '/user/recover', data) | ||
.success(function(body) { | ||
if (body.data && body.data.serverRecoveryCode) { | ||
params.serverRecoveryCode = body.data.serverRecoveryCode; | ||
deferred.resolve(params); | ||
} else { | ||
$scope.recoveryError = 'An error occurred.'; | ||
deferred.reject(); | ||
} | ||
}) | ||
.error(function(body, status) { | ||
switch(status) { | ||
case 400: | ||
if (body.code === 'invalid') { | ||
$scope.recoveryError = 'Invalid username or recovery code.'; | ||
} else if (body.code === 'disabled') { | ||
$scope.recoveryError = 'Recovery has been disabled for this account.'; | ||
} | ||
break; | ||
case 0: | ||
$scope.recoveryError = 'Unable to contact the server.'; | ||
break; | ||
default: | ||
$scope.recoveryError = 'An error occurred.'; | ||
} | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
} | ||
|
||
function recover(params) { | ||
var deferred = $q.defer(); | ||
|
||
// Append domain | ||
params.username += '@stellar.org'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bartekn
Author
Contributor
|
||
|
||
var userPartBytes = bs58.decode(params.recoveryCode); | ||
var serverPartBytes = bs58.decode(params.serverRecoveryCode); | ||
var fullRecoveryCodeBytes = userPartBytes.concat(serverPartBytes); | ||
var fullRecoveryCode = bs58.encode(fullRecoveryCodeBytes); | ||
|
||
var data = { | ||
server: Options.WALLET_SERVER+'/v2', | ||
username: params.username, | ||
recoveryCode: params.recoveryCode | ||
recoveryCode: fullRecoveryCode | ||
}; | ||
|
||
if ($scope.totpRequired) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,133 @@ | ||
'use strict'; | ||
|
||
angular.module('stellarClient').controller('SettingsRecoveryCtrl', function($scope, session) { | ||
var wallet = session.get('wallet').walletV2; | ||
angular.module('stellarClient').controller('SettingsRecoveryCtrl', function($scope, $http, session, stellarApi, UserPrivateInfo, FlashMessages) { | ||
var wallet = session.get('wallet'); | ||
var params = { | ||
username: session.get('username'), | ||
updateToken: wallet.keychainData.updateToken | ||
}; | ||
|
||
var userRecoveryCode = null; | ||
var serverRecoveryCode = null; | ||
|
||
$scope.reset = function () { | ||
$scope.error = null; | ||
$scope.enabling = false; | ||
$scope.resetting = false; | ||
$scope.sendingRecoveryCode = false; | ||
$scope.code = null; | ||
|
||
stellarApi.User.getNewRecoveryCode(params) | ||
.then(function(response) { | ||
if (response.data.status === 'success') { | ||
$scope.resetting = true; | ||
userRecoveryCode = response.data.userRecoveryCode; | ||
serverRecoveryCode = response.data.serverRecoveryCode; | ||
} else { | ||
$scope.resetting = false; | ||
} | ||
}); | ||
}; | ||
$scope.reset(); | ||
$scope.$on('settings-refresh', $scope.reset); | ||
|
||
$scope.$on('settings-recovery-clicked', function($event, toggle) { | ||
if (toggle.on) { | ||
disableRecovery(); | ||
} else { | ||
enableRecovery(); | ||
} | ||
toggleRecovery(!toggle.on); | ||
}); | ||
|
||
function disableRecovery() { | ||
$scope.enabling = false; | ||
$scope.$emit('settings-recovery-toggled', false); | ||
function toggleRecovery(value) { | ||
$http.post(Options.API_SERVER+'/user/setrecover', _.extend(params, { | ||
recover: value | ||
})).success(function () { | ||
$scope.$emit('settings-recovery-toggled', value); | ||
}).error(function () { | ||
FlashMessages.add({ | ||
title: 'Server error', | ||
info: 'There was an error contacting server. Please try again later.', | ||
type: 'error' | ||
}); | ||
}); | ||
} | ||
|
||
var recoveryCode = null; | ||
$scope.recoveryCode = null; // Temp | ||
$scope.resetRecovery = function($event) { | ||
$event.preventDefault(); | ||
$scope.sendingRecoveryCode = true; | ||
|
||
function enableRecovery() { | ||
$scope.enabling = true; | ||
recoveryCode = StellarWallet.util.generateRandomRecoveryCode(); | ||
$scope.recoveryCode = recoveryCode; // temp | ||
} | ||
stellarApi.User.changeRecoveryToken(params) | ||
.success(function() { | ||
stellarApi.User.getNewRecoveryCode(params) | ||
.then(function(response) { | ||
if (response.data.status === 'success') { | ||
$scope.resetting = true; | ||
userRecoveryCode = response.data.userRecoveryCode; | ||
serverRecoveryCode = response.data.serverRecoveryCode; | ||
} | ||
}); | ||
}).error(function (response){ | ||
$scope.resetting = false; | ||
if (response.code === 'no_email') { | ||
FlashMessages.add({ | ||
title: 'No email added', | ||
info: 'Add and verify your email first. Recovery token will be sent to your email inbox.' | ||
}); | ||
} else { | ||
FlashMessages.add({ | ||
title: 'Recovery Error', | ||
info: 'There was error trying to generate recovery token. Please try again later.', | ||
type: 'error' | ||
}); | ||
} | ||
}).finally(function() { | ||
$scope.sendingRecoveryCode = false; | ||
}); | ||
}; | ||
|
||
$scope.confirmEnableRecovery = function($event) { | ||
$scope.confirmResetRecovery = function($event) { | ||
$event.preventDefault(); | ||
if ($scope.code === recoveryCode) { | ||
wallet.enableRecovery({ | ||
secretKey: session.get('wallet').keychainData.signingKeys.secretKey, | ||
recoveryCode: $scope.code | ||
}).then(function() { | ||
recoveryCode = null; | ||
$scope.code = null; | ||
$scope.recoveryCode = null; // Temp | ||
$scope.enabling = false; | ||
$scope.$emit('settings-recovery-toggled', true); | ||
if (session.isPersistent()) { | ||
session.get('wallet').saveLocal(); // We need to rewrite wallet object because lockVersion has changed | ||
} | ||
}).finally(function() { | ||
$scope.$apply(); | ||
}); // TODO handle errors | ||
} else { | ||
|
||
if ($scope.code !== userRecoveryCode) { | ||
$scope.error = 'Incorrect recovery code. Please try again.'; | ||
return; | ||
} | ||
|
||
var userPartBytes = bs58.decode($scope.code); | ||
var serverPartBytes = bs58.decode(serverRecoveryCode); | ||
var fullRecoveryCodeBytes = userPartBytes.concat(serverPartBytes); | ||
var fullRecoveryCode = bs58.encode(fullRecoveryCodeBytes); | ||
wallet.walletV2.enableRecovery({ | ||
recoveryCode: fullRecoveryCode, | ||
secretKey: wallet.keychainData.signingKeys.secretKey | ||
}).then(function() { | ||
return stellarApi.User.finishChangeRecoveryToken(_.extend(params, { | ||
userRecoveryCode: $scope.code | ||
})); | ||
}).then(function() { | ||
$scope.code = null; | ||
$scope.resetting = false; | ||
FlashMessages.add({ | ||
title: 'Success', | ||
info: 'Your recovery token has been reset!' | ||
}); | ||
if (session.isPersistent()) { | ||
session.get('wallet').saveLocal(); // We need to rewrite wallet object because lockVersion has changed | ||
} | ||
}).catch(StellarWallet.errors.ConnectionError, function(e) { | ||
$scope.error = 'Connection error. Please try again.'; | ||
}).catch(function(e) { | ||
$scope.error = 'Unknown error. Please try again.'; | ||
// TODO add logging | ||
}).finally(function() { | ||
$scope.$apply(); | ||
}); | ||
}; | ||
|
||
$scope.cancelResetRecovery = function($event) { | ||
$event.preventDefault(); | ||
|
||
stellarApi.User.cancelChangingRecoveryCode(params) | ||
.success(function() { | ||
$scope.resetting = false; | ||
}).error(function() { | ||
$scope.error = 'Cannot cancel changing recovery code now. Please try again.'; | ||
}); | ||
}; | ||
}); |
Pretty sure this is what's causing @stellar.org to be appended to the username in the UI. Could be the root source of confusion on https://stellartalk.org/topic/6979-i-have-a-problem/