1
0
mirror of https://github.com/bitwarden/web synced 2026-01-01 16:13:15 +00:00
Files
web/src/app/settings/settingsTwoStepDuoController.js
2017-07-08 23:41:02 -04:00

78 lines
2.5 KiB
JavaScript

angular
.module('bit.settings')
.controller('settingsTwoStepDuoController', function ($scope, apiService, $uibModalInstance, cryptoService,
toastr, $analytics, constants) {
$analytics.eventTrack('settingsTwoStepDuoController', { category: 'Modal' });
var _masterPasswordHash;
$scope.updateModel = {
token: null,
host: null,
ikey: null,
skey: null
};
$scope.auth = function (model) {
$scope.authPromise = cryptoService.hashPassword(model.masterPassword).then(function (hash) {
_masterPasswordHash = hash;
return apiService.twoFactor.getDuo({}, {
masterPasswordHash: _masterPasswordHash
}).$promise;
}).then(function (apiResponse) {
processResult(apiResponse);
$scope.authed = true;
});
};
$scope.submit = function (model) {
if ($scope.enabled) {
disable();
return;
}
update(model);
};
function disable() {
if (!confirm('Are you sure you want to disable the Duo provider?')) {
return;
}
$scope.submitPromise = apiService.twoFactor.disable({}, {
masterPasswordHash: _masterPasswordHash,
type: constants.twoFactorProvider.duo
}, function (response) {
$analytics.eventTrack('Disabled Two-step Duo');
toastr.success('Duo has been disabled.');
$scope.enabled = response.Enabled;
$scope.close();
}).$promise;
}
function update(model) {
$scope.submitPromise = apiService.twoFactor.putDuo({}, {
integrationKey: model.ikey,
secretKey: model.skey,
host: model.host,
masterPasswordHash: _masterPasswordHash
}, function (response) {
$analytics.eventTrack('Enabled Two-step Duo');
processResult(response);
}).$promise;
}
function processResult(response) {
$scope.enabled = response.Enabled;
$scope.updateModel = {
ikey: response.IntegrationKey,
skey: response.SecretKey,
host: response.Host
};
}
$scope.close = function () {
$uibModalInstance.close($scope.enabled);
};
});