2018-02-10 04:47:53 +01:00
|
|
|
import * as template from './lock.component.html';
|
|
|
|
|
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-lock',
|
|
|
|
template: template,
|
|
|
|
})
|
|
|
|
export class LockComponent {
|
|
|
|
masterPassword: string = '';
|
2018-02-24 19:48:55 +01:00
|
|
|
showPassword: boolean = false;
|
2018-02-10 04:47:53 +01:00
|
|
|
|
|
|
|
constructor(private router: Router, private analytics: Angulartics2,
|
|
|
|
private toasterService: ToasterService, private i18nService: I18nService,
|
|
|
|
private platformUtilsService: PlatformUtilsService, private messagingService: MessagingService,
|
|
|
|
private userService: UserService, private cryptoService: CryptoService) { }
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (this.masterPassword == null || this.masterPassword === '') {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('masterPassRequired'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const email = await this.userService.getEmail();
|
|
|
|
const key = this.cryptoService.makeKey(this.masterPassword, email);
|
|
|
|
const keyHash = await this.cryptoService.hashPassword(this.masterPassword, key);
|
|
|
|
const storedKeyHash = await this.cryptoService.getKeyHash();
|
|
|
|
|
|
|
|
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
|
|
|
|
await this.cryptoService.setKey(key);
|
|
|
|
this.messagingService.send('unlocked');
|
|
|
|
this.router.navigate(['vault']);
|
|
|
|
} else {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('invalidMasterPassword'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async logOut() {
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('logOutConfirmation'),
|
|
|
|
this.i18nService.t('logOut'), this.i18nService.t('logOut'), this.i18nService.t('cancel'));
|
|
|
|
if (confirmed) {
|
|
|
|
this.messagingService.send('logout');
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 19:48:55 +01:00
|
|
|
|
|
|
|
togglePassword() {
|
|
|
|
this.analytics.eventTrack.next({ action: 'Toggled Master Password on Unlock' });
|
|
|
|
this.showPassword = !this.showPassword;
|
|
|
|
document.getElementById('masterPassword').focus();
|
|
|
|
}
|
2018-02-10 04:47:53 +01:00
|
|
|
}
|