1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/settings/settingsTwoStepController.js

116 lines
4.2 KiB
JavaScript
Raw Normal View History

2017-06-19 21:29:33 +02:00
angular
.module('bit.settings')
.controller('settingsTwoStepController', function ($scope, apiService, authService, toastr, $analytics, constants,
2017-06-20 04:26:57 +02:00
$filter, $uibModal) {
2017-06-19 21:29:33 +02:00
$scope.providers = [
{
type: constants.twoFactorProvider.authenticator,
name: 'Authenticator App',
description: 'Use auth app.',
enabled: false,
free: true
},
{
type: constants.twoFactorProvider.yubikey,
name: 'YubiKey OTP',
description: '',
enabled: false
},
{
type: constants.twoFactorProvider.duo,
name: 'Duo',
description: '',
enabled: false
},
{
type: constants.twoFactorProvider.u2f,
name: 'FIDO U2F Security Key',
description: '',
enabled: false
},
{
type: constants.twoFactorProvider.email,
name: 'Email',
description: '',
enabled: false
}
];
apiService.twoFactor.list({}, function (response) {
for (var i = 0; i < response.Data.length; i++) {
if (!response.Data[i].Enabled) {
continue;
}
var provider = $filter('filter')($scope.providers, { type: response.Data[i].Type });
if (provider.length) {
provider[0].enabled = true;
}
}
});
authService.getUserProfile().then(function (profile) {
_profile = profile;
});
2017-06-20 04:26:57 +02:00
$scope.edit = function (provider) {
if (provider.type === constants.twoFactorProvider.authenticator) {
var authenticatorModal = $uibModal.open({
animation: true,
templateUrl: 'app/settings/views/settingsTwoStepAuthenticator.html',
controller: 'settingsTwoStepAuthenticatorController',
resolve: {
enabled: function () { return provider.enabled; }
}
});
2017-06-21 21:17:44 +02:00
authenticatorModal.result.then(function (enabled) {
provider.enabled = enabled;
2017-06-20 15:21:53 +02:00
});
}
else if(provider.type === constants.twoFactorProvider.email) {
var emailModal = $uibModal.open({
animation: true,
templateUrl: 'app/settings/views/settingsTwoStepEmail.html',
controller: 'settingsTwoStepEmailController',
resolve: {
enabled: function () { return provider.enabled; }
}
});
2017-06-21 21:17:44 +02:00
emailModal.result.then(function (enabled) {
provider.enabled = enabled;
2017-06-20 20:00:55 +02:00
});
}
else if (provider.type === constants.twoFactorProvider.yubikey) {
var yubiModal = $uibModal.open({
animation: true,
templateUrl: 'app/settings/views/settingsTwoStepYubi.html',
controller: 'settingsTwoStepYubiController',
resolve: {
enabled: function () { return provider.enabled; }
}
});
2017-06-21 21:17:44 +02:00
yubiModal.result.then(function (enabled) {
provider.enabled = enabled;
});
}
else if (provider.type === constants.twoFactorProvider.duo) {
var yubiModal = $uibModal.open({
animation: true,
templateUrl: 'app/settings/views/settingsTwoStepDuo.html',
controller: 'settingsTwoStepDuoController',
resolve: {
enabled: function () { return provider.enabled; }
}
});
2017-06-20 20:00:55 +02:00
2017-06-21 21:17:44 +02:00
yubiModal.result.then(function (enabled) {
provider.enabled = enabled;
2017-06-20 04:26:57 +02:00
});
}
};
2017-06-19 21:29:33 +02:00
});