+31
-7
@@ -4,11 +4,13 @@
|
||||
/* global angular */
|
||||
/* global $ */
|
||||
|
||||
angular.module('Application').controller('ProfileController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
|
||||
angular.module('Application').controller('ProfileController', ['$scope', '$location', 'Client', '$timeout', function ($scope, $location, Client, $timeout) {
|
||||
$scope.user = Client.getUserInfo();
|
||||
$scope.config = Client.getConfig();
|
||||
$scope.apps = Client.getInstalledApps();
|
||||
|
||||
console.log($scope.twoFactorAuthenticationEnableForm);
|
||||
|
||||
$scope.twoFactorAuthentication = {
|
||||
busy: false,
|
||||
error: null,
|
||||
@@ -16,6 +18,8 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
|
||||
totpToken: '',
|
||||
secret: '',
|
||||
qrcode: '',
|
||||
mandatory2FA: false,
|
||||
mandatory2FAHelp: false, // show the initial help text when mandatory 2fa forces modal popup
|
||||
|
||||
reset: function () {
|
||||
$scope.twoFactorAuthentication.busy = false;
|
||||
@@ -24,6 +28,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
|
||||
$scope.twoFactorAuthentication.totpToken = '';
|
||||
$scope.twoFactorAuthentication.secret = '';
|
||||
$scope.twoFactorAuthentication.qrcode = '';
|
||||
$scope.twoFactorAuthentication.mandatory2FAHelp = false;
|
||||
|
||||
$scope.twoFactorAuthenticationEnableForm.$setUntouched();
|
||||
$scope.twoFactorAuthenticationEnableForm.$setPristine();
|
||||
@@ -31,6 +36,25 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
|
||||
$scope.twoFactorAuthenticationDisableForm.$setPristine();
|
||||
},
|
||||
|
||||
getSecret: function () {
|
||||
$scope.twoFactorAuthentication.mandatory2FAHelp = false;
|
||||
|
||||
Client.setTwoFactorAuthenticationSecret(function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
$scope.twoFactorAuthentication.secret = result.secret;
|
||||
$scope.twoFactorAuthentication.qrcode = result.qrcode;
|
||||
});
|
||||
},
|
||||
|
||||
showMandatory2FA: function () {
|
||||
$scope.twoFactorAuthentication.reset();
|
||||
$scope.twoFactorAuthentication.mandatory2FA = true;
|
||||
$scope.twoFactorAuthentication.mandatory2FAHelp = true;
|
||||
|
||||
$('#twoFactorAuthenticationEnableModal').modal({ backdrop: 'static', keyboard: false }); // undimissable dialog
|
||||
},
|
||||
|
||||
show: function () {
|
||||
$scope.twoFactorAuthentication.reset();
|
||||
|
||||
@@ -39,12 +63,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
|
||||
} else {
|
||||
$('#twoFactorAuthenticationEnableModal').modal('show');
|
||||
|
||||
Client.setTwoFactorAuthenticationSecret(function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
$scope.twoFactorAuthentication.secret = result.secret;
|
||||
$scope.twoFactorAuthentication.qrcode = result.qrcode;
|
||||
});
|
||||
$scope.twoFactorAuthentication.getSecret();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -601,4 +620,9 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
|
||||
});
|
||||
|
||||
$('.modal-backdrop').remove();
|
||||
|
||||
if ($location.search().setup2fa) {
|
||||
// the form elements of the FormController won't appear in scope yet
|
||||
$timeout(function () { $scope.twoFactorAuthentication.showMandatory2FA(); }, 1000);
|
||||
}
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user