mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
Rewrite lock module to TypeScript. (#354)
This commit is contained in:
committed by
Kyle Spearrin
parent
e250d9b658
commit
8ae178aff3
@@ -29,6 +29,7 @@ require('../less/popup.less');
|
|||||||
import ComponentsModule from './components/components.module';
|
import ComponentsModule from './components/components.module';
|
||||||
import ToolsModule from './tools/tools.module';
|
import ToolsModule from './tools/tools.module';
|
||||||
import ServicesModule from './services/services.module';
|
import ServicesModule from './services/services.module';
|
||||||
|
import LockModule from './lock/lock.module';
|
||||||
|
|
||||||
// Model imports
|
// Model imports
|
||||||
import { AttachmentData } from '../../models/data/attachmentData';
|
import { AttachmentData } from '../../models/data/attachmentData';
|
||||||
@@ -83,7 +84,7 @@ angular
|
|||||||
'bit.vault',
|
'bit.vault',
|
||||||
'bit.settings',
|
'bit.settings',
|
||||||
ToolsModule,
|
ToolsModule,
|
||||||
'bit.lock'
|
LockModule
|
||||||
]);
|
]);
|
||||||
|
|
||||||
require('./config');
|
require('./config');
|
||||||
@@ -127,8 +128,6 @@ require('./settings/settingsEnvironmentController.js');
|
|||||||
require('./tools/toolsPasswordGeneratorController.js');
|
require('./tools/toolsPasswordGeneratorController.js');
|
||||||
require('./tools/toolsPasswordGeneratorHistoryController.js');
|
require('./tools/toolsPasswordGeneratorHistoryController.js');
|
||||||
require('./tools/toolsExportController.js');
|
require('./tools/toolsExportController.js');
|
||||||
require('./lock/lockModule.js');
|
|
||||||
require('./lock/lockController.js');
|
|
||||||
|
|
||||||
// Bootstrap the angular application
|
// Bootstrap the angular application
|
||||||
angular.element(function () {
|
angular.element(function () {
|
||||||
|
|||||||
@@ -260,8 +260,7 @@ angular
|
|||||||
})
|
})
|
||||||
.state('lock', {
|
.state('lock', {
|
||||||
url: '/lock',
|
url: '/lock',
|
||||||
templateUrl: 'app/lock/views/lock.html',
|
component: 'lock',
|
||||||
controller: 'lockController',
|
|
||||||
data: { authorize: true },
|
data: { authorize: true },
|
||||||
params: { animation: null }
|
params: { animation: null }
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<form name="theForm" ng-submit="submit()" bit-form="submitPromise">
|
<form name="theForm" ng-submit="$ctrl.submit()" bit-form="submitPromise">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<button type="submit" class="btn btn-link">{{i18n.submit}}</button>
|
<button type="submit" class="btn btn-link">{{$ctrl.i18n.submit}}</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="title">{{i18n.verifyMasterPassword}}</div>
|
<div class="title">{{$ctrl.i18n.verifyMasterPassword}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="list">
|
<div class="list">
|
||||||
@@ -11,15 +11,15 @@
|
|||||||
<div class="list-section-items">
|
<div class="list-section-items">
|
||||||
<div class="list-section-item list-section-item-icon-input">
|
<div class="list-section-item list-section-item-icon-input">
|
||||||
<i class="fa fa-lock fa-lg fa-fw"></i>
|
<i class="fa fa-lock fa-lg fa-fw"></i>
|
||||||
<label for="master-password" class="sr-only">{{i18n.masterPass}}</label>
|
<label for="master-password" class="sr-only">{{$ctrl.i18n.masterPass}}</label>
|
||||||
<input id="master-password" type="password" name="MasterPassword" placeholder="{{i18n.masterPass}}"
|
<input id="master-password" type="password" name="MasterPassword" placeholder="{{$ctrl.i18n.masterPass}}"
|
||||||
ng-model="masterPassword">
|
ng-model="masterPassword">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-center text-accent">
|
<p class="text-center text-accent">
|
||||||
<a ng-click="logOut()" href="">{{i18n.logOut}}</a>
|
<a ng-click="$ctrl.logOut()" href="">{{$ctrl.i18n.logOut}}</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
53
src/popup/app/lock/lock.component.ts
Normal file
53
src/popup/app/lock/lock.component.ts
Normal file
@@ -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,
|
||||||
|
};
|
||||||
9
src/popup/app/lock/lock.module.ts
Normal file
9
src/popup/app/lock/lock.module.ts
Normal file
@@ -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;
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
angular
|
|
||||||
.module('bit.lock', ['ngAnimate', 'toastr']);
|
|
||||||
Reference in New Issue
Block a user