2018-04-04 22:59:14 -04:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
|
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
|
|
import { CryptoService } from '../../abstractions/crypto.service';
|
|
|
|
|
import { I18nService } from '../../abstractions/i18n.service';
|
|
|
|
|
import { MessagingService } from '../../abstractions/messaging.service';
|
|
|
|
|
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
|
|
|
|
import { UserService } from '../../abstractions/user.service';
|
|
|
|
|
|
|
|
|
|
export class LockComponent {
|
|
|
|
|
masterPassword: string = '';
|
|
|
|
|
showPassword: boolean = false;
|
|
|
|
|
|
|
|
|
|
protected successRoute: string = 'vault';
|
|
|
|
|
|
|
|
|
|
constructor(protected router: Router, protected analytics: Angulartics2,
|
2018-10-02 23:09:19 -04:00
|
|
|
protected i18nService: I18nService,
|
2018-04-04 22:59:14 -04:00
|
|
|
protected platformUtilsService: PlatformUtilsService, protected messagingService: MessagingService,
|
|
|
|
|
protected userService: UserService, protected cryptoService: CryptoService) { }
|
|
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
|
if (this.masterPassword == null || this.masterPassword === '') {
|
2018-10-02 23:09:19 -04:00
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
2018-04-04 22:59:14 -04:00
|
|
|
this.i18nService.t('masterPassRequired'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const email = await this.userService.getEmail();
|
2018-08-14 15:12:10 -04:00
|
|
|
const kdf = await this.userService.getKdf();
|
|
|
|
|
const kdfIterations = await this.userService.getKdfIterations();
|
|
|
|
|
const key = await this.cryptoService.makeKey(this.masterPassword, email, kdf, kdfIterations);
|
2018-04-04 22:59:14 -04:00
|
|
|
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([this.successRoute]);
|
|
|
|
|
} else {
|
2018-10-02 23:09:19 -04:00
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
2018-04-04 22:59:14 -04:00
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
togglePassword() {
|
|
|
|
|
this.analytics.eventTrack.next({ action: 'Toggled Master Password on Unlock' });
|
|
|
|
|
this.showPassword = !this.showPassword;
|
|
|
|
|
document.getElementById('masterPassword').focus();
|
|
|
|
|
}
|
|
|
|
|
}
|