diff --git a/src/popup/app/app.js b/src/popup/app/app.js index adc69617bf6..34c4c36e54e 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -29,6 +29,7 @@ require('../less/popup.less'); import ComponentsModule from './components/components.module'; import ToolsModule from './tools/tools.module'; import ServicesModule from './services/services.module'; +import LockModule from './lock/lock.module'; // Model imports import { AttachmentData } from '../../models/data/attachmentData'; @@ -83,7 +84,7 @@ angular 'bit.vault', 'bit.settings', ToolsModule, - 'bit.lock' + LockModule ]); require('./config'); @@ -127,8 +128,6 @@ require('./settings/settingsEnvironmentController.js'); require('./tools/toolsPasswordGeneratorController.js'); require('./tools/toolsPasswordGeneratorHistoryController.js'); require('./tools/toolsExportController.js'); -require('./lock/lockModule.js'); -require('./lock/lockController.js'); // Bootstrap the angular application angular.element(function () { diff --git a/src/popup/app/config.js b/src/popup/app/config.js index 176c19f2fd5..dbf10c77f42 100644 --- a/src/popup/app/config.js +++ b/src/popup/app/config.js @@ -260,8 +260,7 @@ angular }) .state('lock', { url: '/lock', - templateUrl: 'app/lock/views/lock.html', - controller: 'lockController', + component: 'lock', data: { authorize: true }, params: { animation: null } }); diff --git a/src/popup/app/lock/views/lock.html b/src/popup/app/lock/lock.component.html similarity index 63% rename from src/popup/app/lock/views/lock.html rename to src/popup/app/lock/lock.component.html index 4a654cf5641..dc23dda603a 100644 --- a/src/popup/app/lock/views/lock.html +++ b/src/popup/app/lock/lock.component.html @@ -1,9 +1,9 @@ -
diff --git a/src/popup/app/lock/lock.component.ts b/src/popup/app/lock/lock.component.ts new file mode 100644 index 00000000000..aaf260382a0 --- /dev/null +++ b/src/popup/app/lock/lock.component.ts @@ -0,0 +1,53 @@ +import CryptoService from '../../../services/crypto.service'; +import UserService from '../../../services/user.service'; + +import * as template from './lock.component.html'; + +class LockController { + i18n: any; + + constructor(public $scope: any, public $state: any, public i18nService: any, + public cryptoService: CryptoService, public toastr: any, public userService: UserService, + public SweetAlert: any, public $timeout: any) { + this.i18n = i18nService; + + $timeout(() => { + document.getElementById('master-password').focus(); + }); + } + + logOut() { + this.SweetAlert.swal({ + title: this.i18nService.logOut, + text: this.i18nService.logOutConfirmation, + showCancelButton: true, + confirmButtonText: this.i18nService.yes, + cancelButtonText: this.i18nService.cancel, + }, (confirmed: boolean) => { + if (confirmed) { + chrome.runtime.sendMessage({ command: 'logout' }); + } + }); + } + + async submit() { + const email = await this.userService.getEmail(); + const key = this.cryptoService.makeKey(this.$scope.masterPassword, email); + const keyHash = await this.cryptoService.hashPassword(this.$scope.masterPassword, key); + const storedKeyHash = await this.cryptoService.getKeyHash(); + + if (storedKeyHash && keyHash && storedKeyHash === keyHash) { + await this.cryptoService.setKey(key); + chrome.runtime.sendMessage({ command: 'unlocked' }); + this.$state.go('tabs.current'); + } else { + this.toastr.error(this.i18nService.invalidMasterPassword, this.i18nService.errorsOccurred); + } + } +} + +export const LockComponent = { + bindings: {}, + controller: LockController, + template, +}; diff --git a/src/popup/app/lock/lock.module.ts b/src/popup/app/lock/lock.module.ts new file mode 100644 index 00000000000..a505ebaed3c --- /dev/null +++ b/src/popup/app/lock/lock.module.ts @@ -0,0 +1,9 @@ +import * as angular from 'angular'; +import { LockComponent } from './lock.component'; + +export default angular + .module('bit.lock', ['ngAnimate', 'toastr']) + + .component('lock', LockComponent) + + .name; diff --git a/src/popup/app/lock/lockController.js b/src/popup/app/lock/lockController.js deleted file mode 100644 index 157ae9decd8..00000000000 --- a/src/popup/app/lock/lockController.js +++ /dev/null @@ -1,46 +0,0 @@ -angular - .module('bit.lock') - - .controller('lockController', function ($scope, $state, $analytics, i18nService, cryptoService, toastr, - userService, SweetAlert, $timeout) { - $scope.i18n = i18nService; - - $timeout(function () { - $('#master-password').focus(); - }); - - $scope.logOut = function () { - SweetAlert.swal({ - title: i18nService.logOut, - text: i18nService.logOutConfirmation, - showCancelButton: true, - confirmButtonText: i18nService.yes, - cancelButtonText: i18nService.cancel - }, function (confirmed) { - if (confirmed) { - chrome.runtime.sendMessage({ command: 'logout' }); - } - }); - }; - - $scope.submit = function () { - userService.getEmail().then(function (email) { - var key = cryptoService.makeKey($scope.masterPassword, email); - var keyHash; - cryptoService.hashPassword($scope.masterPassword, key).then(function (theKeyHash) { - keyHash = theKeyHash; - return cryptoService.getKeyHash(); - }).then(function (storedKeyHash) { - if (storedKeyHash && keyHash && storedKeyHash === keyHash) { - cryptoService.setKey(key).then(function () { - chrome.runtime.sendMessage({ command: 'unlocked' }); - $state.go('tabs.current'); - }); - } - else { - toastr.error(i18nService.invalidMasterPassword, i18nService.errorsOccurred); - } - }); - }); - }; - }); diff --git a/src/popup/app/lock/lockModule.js b/src/popup/app/lock/lockModule.js deleted file mode 100644 index c4e0b817ba6..00000000000 --- a/src/popup/app/lock/lockModule.js +++ /dev/null @@ -1,2 +0,0 @@ -angular - .module('bit.lock', ['ngAnimate', 'toastr']);