diff --git a/src/app/global/mainController.js b/src/app/global/mainController.js index 6feefa38a7..3bddb0beba 100644 --- a/src/app/global/mainController.js +++ b/src/app/global/mainController.js @@ -1,7 +1,8 @@ angular .module('bit.global') - .controller('mainController', function ($scope, $state, authService, appSettings, toastr, $window, $document) { + .controller('mainController', function ($scope, $state, authService, appSettings, toastr, $window, $document, + cryptoService, $uibModal) { var vm = this; vm.bodyClass = ''; vm.usingControlSidebar = vm.openControlSidebar = false; @@ -30,6 +31,7 @@ angular }); $scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { + vm.usingEncKey = !!cryptoService.getEncKey(); vm.searchVaultText = null; if (toState.data.bodyClass) { @@ -68,6 +70,18 @@ angular $scope.$broadcast('organizationGroupsAdd'); }; + $scope.updateKey = function () { + $uibModal.open({ + animation: true, + templateUrl: 'app/settings/views/settingsUpdateKey.html', + controller: 'settingsUpdateKeyController' + }); + }; + + $scope.verifyEmail = function () { + // TODO: send email api + }; + // Append dropdown menu somewhere else var bodyScrollbarWidth, appendedDropdownMenu, diff --git a/src/app/services/authService.js b/src/app/services/authService.js index 95bcf68a33..f7bf3ac124 100644 --- a/src/app/services/authService.js +++ b/src/app/services/authService.js @@ -119,11 +119,12 @@ angular return _setDeferred.promise; } - var decodedToken = jwtHelper.decodeToken(token); apiService.accounts.getProfile({}, function (profile) { _userProfile = { - id: decodedToken.name, - email: decodedToken.email, + id: profile.Id, + email: profile.Email, + emailVerified: profile.EmailVerified, + premium: profile.Premium, extended: { name: profile.Name, twoFactorEnabled: profile.TwoFactorEnabled, diff --git a/src/app/settings/settingsUpdateKeyController.js b/src/app/settings/settingsUpdateKeyController.js new file mode 100644 index 0000000000..9492d20366 --- /dev/null +++ b/src/app/settings/settingsUpdateKeyController.js @@ -0,0 +1,37 @@ +angular + .module('bit.settings') + + .controller('settingsUpdateKeyController', function ($scope, $state, apiService, $uibModalInstance, + cryptoService, authService, cipherService, validationService, toastr, $analytics) { + $analytics.eventTrack('settingsUpdateKeyController', { category: 'Modal' }); + + $scope.save = function (form) { + var encKey = cryptoService.getEncKey(); + if (encKey) { + validationService.addError(form, 'MasterPasswordHash', + 'You do not need to update. You are already using the new encryption key.', true); + return; + } + + $scope.processing = true; + var mpHash = cryptoService.hashPassword($scope.masterPassword); + $scope.savePromise = cipherService.updateKey(mpHash, function () { + $uibModalInstance.dismiss('cancel'); + authService.logOut(); + $analytics.eventTrack('Key Updated'); + return $state.go('frontend.login.info'); + }).then(function () { + toastr.success('Please log back in. If you are using other bitwarden applications, ' + + 'log out and back in to those as well.', 'Key Updated', { timeOut: 10000 }); + }, processError); + }; + + function processError() { + $uibModalInstance.dismiss('cancel'); + toastr.error('Something went wrong.', 'Oh No!'); + } + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/settings/views/settingsUpdateKey.html b/src/app/settings/views/settingsUpdateKey.html new file mode 100644 index 0000000000..7e6fca0892 --- /dev/null +++ b/src/app/settings/views/settingsUpdateKey.html @@ -0,0 +1,53 @@ +
+
+ Please wait. We are now generating a new encryption key and reencrypting all of your data. Do not close this window. + You will be automatically logged out when this process has finished. +
+