2015-12-09 04:35:05 +01:00
|
|
|
angular
|
|
|
|
.module('bit.accounts')
|
|
|
|
|
2016-03-09 03:20:21 +01:00
|
|
|
.controller('accountsRegisterController', function ($scope, $location, apiService, cryptoService, validationService) {
|
|
|
|
var params = $location.search();
|
|
|
|
|
2015-12-09 04:35:05 +01:00
|
|
|
$scope.success = false;
|
2016-03-09 03:20:21 +01:00
|
|
|
$scope.model = {
|
|
|
|
email: params.email
|
|
|
|
};
|
2015-12-09 04:35:05 +01:00
|
|
|
|
|
|
|
$scope.registerPromise = null;
|
2016-03-09 03:20:21 +01:00
|
|
|
$scope.register = function (form) {
|
|
|
|
if ($scope.model.masterPassword != $scope.model.confirmMasterPassword) {
|
|
|
|
validationService.addError(form, 'ConfirmMasterPassword', 'Master password confirmation does not match.', true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var key = cryptoService.makeKey($scope.model.masterPassword, $scope.model.email);
|
|
|
|
var request = {
|
|
|
|
name: $scope.model.name,
|
|
|
|
email: $scope.model.email,
|
|
|
|
masterPasswordHash: cryptoService.hashPassword($scope.model.masterPassword, key),
|
|
|
|
masterPasswordHint: $scope.model.masterPasswordHint
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.registerPromise = apiService.accounts.register(request, function () {
|
2015-12-09 04:35:05 +01:00
|
|
|
$scope.success = true;
|
|
|
|
}).$promise;
|
|
|
|
};
|
|
|
|
});
|