[Auto-Logout] Implement Vault Timeout Options (#1194)
* Update jslib31a2574
->28e3fff
* Initial commit for vault timeout * Updated timeout/action retrieval in idle.background * Cycle saved for idle check * Await async calls for lock/logout in idle bg * Updated lock vs log out conditional Co-authored-by: Vincent Salucci <vsalucci@bitwarden.com>
This commit is contained in:
parent
f18deddb59
commit
e510738a03
2
jslib
2
jslib
|
@ -1 +1 @@
|
|||
Subproject commit 31a257407be7f8f47624b0d021363aaf2cfda2d7
|
||||
Subproject commit 28e3fff739e64c2dd80d3d98717e2921895d16df
|
|
@ -321,8 +321,8 @@
|
|||
"invalidMasterPassword": {
|
||||
"message": "Invalid master password"
|
||||
},
|
||||
"lockOptions": {
|
||||
"message": "Lock Options"
|
||||
"vaultTimeout": {
|
||||
"message": "Vault Timeout"
|
||||
},
|
||||
"lockNow": {
|
||||
"message": "Lock Now"
|
||||
|
@ -1247,5 +1247,12 @@
|
|||
},
|
||||
"passwordGeneratorPolicyInEffect": {
|
||||
"message": "One or more organization policies are affecting your generator settings."
|
||||
},
|
||||
"vaultTimeoutAction": {
|
||||
"message": "Vault Timeout Action"
|
||||
},
|
||||
"lock": {
|
||||
"message": "Lock",
|
||||
"description": "Verb form: to make secure or inaccesible by"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import MainBackground from './main.background';
|
|||
|
||||
import { Analytics } from 'jslib/misc';
|
||||
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
export default class CommandsBackground {
|
||||
private isSafari: boolean;
|
||||
|
@ -15,7 +15,7 @@ export default class CommandsBackground {
|
|||
|
||||
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
|
||||
private platformUtilsService: PlatformUtilsService, private analytics: Analytics,
|
||||
private lockService: LockService) {
|
||||
private vaultTimeoutService: VaultTimeoutService) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.isEdge = this.platformUtilsService.isEdge();
|
||||
this.isVivaldi = this.platformUtilsService.isVivaldi();
|
||||
|
@ -69,7 +69,7 @@ export default class CommandsBackground {
|
|||
}
|
||||
|
||||
private async autoFillLogin(tab?: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ import { Analytics } from 'jslib/misc';
|
|||
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { EventService } from 'jslib/abstractions/event.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
import { EventType } from 'jslib/enums/eventType';
|
||||
|
||||
|
@ -18,7 +18,7 @@ export default class ContextMenusBackground {
|
|||
|
||||
constructor(private main: MainBackground, private cipherService: CipherService,
|
||||
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
|
||||
private platformUtilsService: PlatformUtilsService, private lockService: LockService,
|
||||
private platformUtilsService: PlatformUtilsService, private vaultTimeoutService: VaultTimeoutService,
|
||||
private eventService: EventService, private totpService: TotpService) {
|
||||
this.contextMenus = chrome.contextMenus;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ export default class ContextMenusBackground {
|
|||
return;
|
||||
}
|
||||
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { ConstantsService } from 'jslib/services/constants.service';
|
||||
|
||||
import {
|
||||
LockService,
|
||||
StorageService,
|
||||
VaultTimeoutService,
|
||||
} from 'jslib/abstractions';
|
||||
import { NotificationsService } from 'jslib/abstractions/notifications.service';
|
||||
|
||||
|
@ -13,7 +13,7 @@ export default class IdleBackground {
|
|||
private idleTimer: number = null;
|
||||
private idleState = 'active';
|
||||
|
||||
constructor(private lockService: LockService, private storageService: StorageService,
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService,
|
||||
private notificationsService: NotificationsService) {
|
||||
this.idle = chrome.idle || (browser != null ? browser.idle : null);
|
||||
}
|
||||
|
@ -39,10 +39,15 @@ export default class IdleBackground {
|
|||
|
||||
if (this.idle.onStateChanged) {
|
||||
this.idle.onStateChanged.addListener(async (newState: string) => {
|
||||
if (newState === 'locked') {
|
||||
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (lockOption === -2) {
|
||||
this.lockService.lock(true);
|
||||
if (newState === 'locked') { // If the screen is locked or the screensaver activates
|
||||
const timeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (timeout === -2) { // On System Lock vault timeout option
|
||||
const action = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
|
||||
if (action === 'lock') {
|
||||
await this.vaultTimeoutService.lock(true);
|
||||
} else {
|
||||
await this.vaultTimeoutService.logOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,13 +11,13 @@ import {
|
|||
CryptoService,
|
||||
EnvironmentService,
|
||||
FolderService,
|
||||
LockService,
|
||||
PasswordGenerationService,
|
||||
SettingsService,
|
||||
SyncService,
|
||||
TokenService,
|
||||
TotpService,
|
||||
UserService,
|
||||
VaultTimeoutService,
|
||||
} from 'jslib/services';
|
||||
import { EventService } from 'jslib/services/event.service';
|
||||
import { ExportService } from 'jslib/services/export.service';
|
||||
|
@ -37,7 +37,6 @@ import {
|
|||
EnvironmentService as EnvironmentServiceAbstraction,
|
||||
FolderService as FolderServiceAbstraction,
|
||||
I18nService as I18nServiceAbstraction,
|
||||
LockService as LockServiceAbstraction,
|
||||
MessagingService as MessagingServiceAbstraction,
|
||||
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
||||
PlatformUtilsService as PlatformUtilsServiceAbstraction,
|
||||
|
@ -47,6 +46,7 @@ import {
|
|||
TokenService as TokenServiceAbstraction,
|
||||
TotpService as TotpServiceAbstraction,
|
||||
UserService as UserServiceAbstraction,
|
||||
VaultTimeoutService as VaultTimeoutServiceAbstraction,
|
||||
} from 'jslib/abstractions';
|
||||
import { EventService as EventServiceAbstraction } from 'jslib/abstractions/event.service';
|
||||
import { ExportService as ExportServiceAbstraction } from 'jslib/abstractions/export.service';
|
||||
|
@ -94,7 +94,7 @@ export default class MainBackground {
|
|||
cipherService: CipherServiceAbstraction;
|
||||
folderService: FolderServiceAbstraction;
|
||||
collectionService: CollectionServiceAbstraction;
|
||||
lockService: LockServiceAbstraction;
|
||||
vaultTimeoutService: VaultTimeoutServiceAbstraction;
|
||||
syncService: SyncServiceAbstraction;
|
||||
passwordGenerationService: PasswordGenerationServiceAbstraction;
|
||||
totpService: TotpServiceAbstraction;
|
||||
|
@ -156,9 +156,9 @@ export default class MainBackground {
|
|||
this.i18nService);
|
||||
this.searchService = new SearchService(this.cipherService, this.platformUtilsService);
|
||||
this.policyService = new PolicyService(this.userService, this.storageService);
|
||||
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
|
||||
this.cryptoService, this.platformUtilsService, this.storageService, this.messagingService,
|
||||
this.searchService, this.userService, async () => {
|
||||
this.vaultTimeoutService = new VaultTimeoutService(this.cipherService, this.folderService,
|
||||
this.collectionService, this.cryptoService, this.platformUtilsService, this.storageService,
|
||||
this.messagingService, this.searchService, this.userService, async () => {
|
||||
if (this.notificationsService != null) {
|
||||
this.notificationsService.updateConnection(false);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ export default class MainBackground {
|
|||
this.systemService.startProcessReload();
|
||||
await this.systemService.clearPendingClipboard();
|
||||
}
|
||||
});
|
||||
}, async () => await this.logout(false));
|
||||
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
||||
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
||||
this.storageService, this.messagingService, this.policyService,
|
||||
|
@ -184,12 +184,12 @@ export default class MainBackground {
|
|||
this.auditService = new AuditService(cryptoFunctionService, this.apiService);
|
||||
this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService);
|
||||
this.notificationsService = new NotificationsService(this.userService, this.syncService, this.appIdService,
|
||||
this.apiService, this.lockService, () => this.logout(true));
|
||||
this.apiService, this.vaultTimeoutService, () => this.logout(true));
|
||||
this.environmentService = new EnvironmentService(this.apiService, this.storageService,
|
||||
this.notificationsService);
|
||||
this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService,
|
||||
this.storageService, this.appIdService);
|
||||
this.systemService = new SystemService(this.storageService, this.lockService,
|
||||
this.systemService = new SystemService(this.storageService, this.vaultTimeoutService,
|
||||
this.messagingService, this.platformUtilsService, () => {
|
||||
const forceWindowReload = this.platformUtilsService.isSafari() ||
|
||||
this.platformUtilsService.isFirefox() || this.platformUtilsService.isOpera();
|
||||
|
@ -205,18 +205,19 @@ export default class MainBackground {
|
|||
// Background
|
||||
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
||||
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
|
||||
this.analytics, this.notificationsService, this.systemService, this.lockService);
|
||||
this.analytics, this.notificationsService, this.systemService, this.vaultTimeoutService);
|
||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
||||
this.platformUtilsService, this.analytics, this.lockService);
|
||||
this.platformUtilsService, this.analytics, this.vaultTimeoutService);
|
||||
|
||||
if (!this.isSafari) {
|
||||
this.tabsBackground = new TabsBackground(this);
|
||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService,
|
||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.vaultTimeoutService,
|
||||
this.eventService, this.totpService);
|
||||
this.idleBackground = new IdleBackground(this.lockService, this.storageService, this.notificationsService);
|
||||
this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.storageService,
|
||||
this.notificationsService);
|
||||
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
|
||||
this.lockService);
|
||||
this.vaultTimeoutService);
|
||||
this.windowsBackground = new WindowsBackground(this);
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +227,7 @@ export default class MainBackground {
|
|||
this.analytics.ga('send', 'pageview', '/background.html');
|
||||
this.containerService.attachToWindow(window);
|
||||
|
||||
await (this.lockService as LockService).init(true);
|
||||
await (this.vaultTimeoutService as VaultTimeoutService).init(true);
|
||||
await (this.i18nService as I18nService).init();
|
||||
await (this.eventService as EventService).init(true);
|
||||
await this.runtimeBackground.init();
|
||||
|
@ -258,7 +259,7 @@ export default class MainBackground {
|
|||
}
|
||||
|
||||
const isAuthenticated = await this.userService.isAuthenticated();
|
||||
const locked = await this.lockService.isLocked();
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
|
||||
let suffix = '';
|
||||
if (!isAuthenticated) {
|
||||
|
@ -311,7 +312,7 @@ export default class MainBackground {
|
|||
this.collectionService.clear(userId),
|
||||
this.policyService.clear(userId),
|
||||
this.passwordGenerationService.clear(),
|
||||
this.lockService.clear(),
|
||||
this.vaultTimeoutService.clear(),
|
||||
]);
|
||||
|
||||
this.searchService.clearIndex();
|
||||
|
@ -330,7 +331,7 @@ export default class MainBackground {
|
|||
return;
|
||||
}
|
||||
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -378,8 +379,8 @@ export default class MainBackground {
|
|||
return;
|
||||
}
|
||||
|
||||
const currentLockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (currentLockOption == null) {
|
||||
const currentVaultTimeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (currentVaultTimeout == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -482,7 +483,7 @@ export default class MainBackground {
|
|||
this.actionSetBadgeBackgroundColor(this.sidebarAction);
|
||||
|
||||
this.menuOptionsLoaded = [];
|
||||
const locked = await this.lockService.isLocked();
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
if (!locked) {
|
||||
try {
|
||||
const ciphers = await this.cipherService.getAllDecryptedForUrl(url);
|
||||
|
|
|
@ -11,9 +11,9 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
|
|||
import { Analytics } from 'jslib/misc';
|
||||
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
import { SystemService } from 'jslib/abstractions/system.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
|
@ -37,7 +37,7 @@ export default class RuntimeBackground {
|
|||
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
|
||||
private storageService: StorageService, private i18nService: I18nService,
|
||||
private analytics: Analytics, private notificationsService: NotificationsService,
|
||||
private systemService: SystemService, private lockService: LockService) {
|
||||
private systemService: SystemService, private vaultTimeoutService: VaultTimeoutService) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.runtime = this.isSafari ? {} : chrome.runtime;
|
||||
|
||||
|
@ -127,7 +127,7 @@ export default class RuntimeBackground {
|
|||
await this.main.reseedStorage();
|
||||
break;
|
||||
case 'collectPageDetailsResponse':
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
switch (msg.sender) {
|
||||
|
@ -183,7 +183,7 @@ export default class RuntimeBackground {
|
|||
}
|
||||
|
||||
private async saveAddLogin(tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ export default class RuntimeBackground {
|
|||
}
|
||||
|
||||
private async saveChangePassword(tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ export default class RuntimeBackground {
|
|||
}
|
||||
|
||||
private async addLogin(loginInfo: any, tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ export default class RuntimeBackground {
|
|||
}
|
||||
|
||||
private async changedPassword(changeData: any, tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -400,10 +400,16 @@ export default class RuntimeBackground {
|
|||
}
|
||||
|
||||
private async setDefaultSettings() {
|
||||
// Default lock options to "on restart".
|
||||
const currentLockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (currentLockOption == null) {
|
||||
await this.storageService.save(ConstantsService.lockOptionKey, -1);
|
||||
// Default timeout option to "on restart".
|
||||
const currentVaultTimeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (currentVaultTimeout == null) {
|
||||
await this.storageService.save(ConstantsService.vaultTimeoutKey, -1);
|
||||
}
|
||||
|
||||
// Default action to "lock".
|
||||
const currentVaultTimeoutAction = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
|
||||
if (currentVaultTimeoutAction == null) {
|
||||
await this.storageService.save(ConstantsService.vaultTimeoutActionKey, 'lock');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
export default class WebRequestBackground {
|
||||
private pendingAuthRequests: any[] = [];
|
||||
|
@ -8,7 +8,7 @@ export default class WebRequestBackground {
|
|||
private isFirefox: boolean;
|
||||
|
||||
constructor(platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
||||
private lockService: LockService) {
|
||||
private vaultTimeoutService: VaultTimeoutService) {
|
||||
this.webRequest = (window as any).chrome.webRequest;
|
||||
this.isFirefox = platformUtilsService.isFirefox();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export default class WebRequestBackground {
|
|||
}
|
||||
|
||||
private async resolveAuthCredentials(domain: string, success: Function, error: Function) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
error();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ import { Router } from '@angular/router';
|
|||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { StateService } from 'jslib/abstractions/state.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component';
|
||||
|
||||
|
@ -21,10 +21,10 @@ export class LockComponent extends BaseLockComponent {
|
|||
constructor(router: Router, i18nService: I18nService,
|
||||
platformUtilsService: PlatformUtilsService, messagingService: MessagingService,
|
||||
userService: UserService, cryptoService: CryptoService,
|
||||
storageService: StorageService, lockService: LockService,
|
||||
storageService: StorageService, vaultTimeoutService: VaultTimeoutService,
|
||||
environmentService: EnvironmentService, stateService: StateService) {
|
||||
super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService,
|
||||
storageService, lockService, environmentService, stateService);
|
||||
storageService, vaultTimeoutService, environmentService, stateService);
|
||||
this.successRoute = '/tabs/current';
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@ import {
|
|||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
@Injectable()
|
||||
export class LaunchGuardService implements CanActivate {
|
||||
constructor(private lockService: LockService, private userService: UserService, private router: Router) { }
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) { }
|
||||
|
||||
async canActivate() {
|
||||
if (BrowserApi.getBackgroundPage() == null) {
|
||||
|
@ -28,7 +29,7 @@ export class LaunchGuardService implements CanActivate {
|
|||
return true;
|
||||
}
|
||||
|
||||
const locked = await this.lockService.isLocked();
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
if (locked) {
|
||||
this.router.navigate(['lock']);
|
||||
} else {
|
||||
|
|
|
@ -26,7 +26,6 @@ import { EventService } from 'jslib/abstractions/event.service';
|
|||
import { ExportService } from 'jslib/abstractions/export.service';
|
||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { NotificationsService } from 'jslib/abstractions/notifications.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
|
@ -40,6 +39,7 @@ import { SyncService } from 'jslib/abstractions/sync.service';
|
|||
import { TokenService } from 'jslib/abstractions/token.service';
|
||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
import { AutofillService } from '../../services/abstractions/autofill.service';
|
||||
import BrowserMessagingService from '../../services/browserMessaging.service';
|
||||
|
@ -146,11 +146,15 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer
|
|||
{ provide: SyncService, useFactory: getBgService<SyncService>('syncService'), deps: [] },
|
||||
{ provide: UserService, useFactory: getBgService<UserService>('userService'), deps: [] },
|
||||
{ provide: SettingsService, useFactory: getBgService<SettingsService>('settingsService'), deps: [] },
|
||||
{ provide: LockService, useFactory: getBgService<LockService>('lockService'), deps: [] },
|
||||
{ provide: StorageService, useFactory: getBgService<StorageService>('storageService'), deps: [] },
|
||||
{ provide: AppIdService, useFactory: getBgService<AppIdService>('appIdService'), deps: [] },
|
||||
{ provide: AutofillService, useFactory: getBgService<AutofillService>('autofillService'), deps: [] },
|
||||
{ provide: ExportService, useFactory: getBgService<ExportService>('exportService'), deps: [] },
|
||||
{
|
||||
provide: VaultTimeoutService,
|
||||
useFactory: getBgService<VaultTimeoutService>('vaultTimeoutService'),
|
||||
deps: [],
|
||||
},
|
||||
{
|
||||
provide: NotificationsService,
|
||||
useFactory: getBgService<NotificationsService>('notificationsService'),
|
||||
|
|
|
@ -25,10 +25,17 @@
|
|||
<div class="box-header">{{'security' | i18n}}</div>
|
||||
<div class="box-content single-line">
|
||||
<div class="box-content-row display-block" appBoxRow>
|
||||
<label for="lockOption">{{'lockOptions' | i18n}}</label>
|
||||
<select #lockOptionsSelect id="lockOption" name="LockOptions" [ngModel]="lockOption"
|
||||
(ngModelChange)="saveLockOption($event)">
|
||||
<option *ngFor="let o of lockOptions" [ngValue]="o.value">{{o.name}}</option>
|
||||
<label for="vaultTimeout">{{'vaultTimeout' | i18n}}</label>
|
||||
<select #vaultTimeoutSelect id="vaultTimeout" name="VaultTimeouts" [ngModel]="vaultTimeout"
|
||||
(ngModelChange)="saveVaultTimeout($event)">
|
||||
<option *ngFor="let o of vaultTimeouts" [ngValue]="o.value">{{o.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="box-content-row display-block" appBoxRow>
|
||||
<label for="vaultTimeoutAction">{{'vaultTimeoutAction' | i18n}}</label>
|
||||
<select id="vaultTimeoutAction" name="VaultTimeoutActions" [ngModel]="vaultTimeoutAction"
|
||||
(ngModelChange)="saveVaultTimeoutAction($event)">
|
||||
<option *ngFor="let o of vaultTimeoutActions" [ngValue]="o.value">{{o.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="box-content-row box-content-row-checkbox" appBoxRow>
|
||||
|
|
|
@ -18,11 +18,11 @@ import { ConstantsService } from 'jslib/services/constants.service';
|
|||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
const RateUrls = {
|
||||
[DeviceType.ChromeExtension]:
|
||||
|
@ -44,14 +44,16 @@ const RateUrls = {
|
|||
templateUrl: 'settings.component.html',
|
||||
})
|
||||
export class SettingsComponent implements OnInit {
|
||||
@ViewChild('lockOptionsSelect', { read: ElementRef }) lockOptionsSelectRef: ElementRef;
|
||||
lockOptions: any[];
|
||||
lockOption: number = null;
|
||||
@ViewChild('vaultTimeoutSelect', { read: ElementRef }) vaultTimeoutSelectRef: ElementRef;
|
||||
vaultTimeouts: any[];
|
||||
vaultTimeout: number = null;
|
||||
vaultTimeoutActions: any[];
|
||||
vaultTimeoutAction: string;
|
||||
pin: boolean = null;
|
||||
previousLockOption: number = null;
|
||||
previousVaultTimeout: number = null;
|
||||
|
||||
constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService,
|
||||
private analytics: Angulartics2, private lockService: LockService,
|
||||
private analytics: Angulartics2, private vaultTimeoutService: VaultTimeoutService,
|
||||
private storageService: StorageService, public messagingService: MessagingService,
|
||||
private router: Router, private environmentService: EnvironmentService,
|
||||
private cryptoService: CryptoService, private userService: UserService) {
|
||||
|
@ -61,7 +63,7 @@ export class SettingsComponent implements OnInit {
|
|||
const showOnLocked = !this.platformUtilsService.isFirefox() && !this.platformUtilsService.isEdge()
|
||||
&& !this.platformUtilsService.isSafari();
|
||||
|
||||
this.lockOptions = [
|
||||
this.vaultTimeouts = [
|
||||
{ name: this.i18nService.t('immediately'), value: 0 },
|
||||
{ name: this.i18nService.t('oneMinute'), value: 1 },
|
||||
{ name: this.i18nService.t('fiveMinutes'), value: 5 },
|
||||
|
@ -74,47 +76,61 @@ export class SettingsComponent implements OnInit {
|
|||
];
|
||||
|
||||
if (showOnLocked) {
|
||||
this.lockOptions.push({ name: this.i18nService.t('onLocked'), value: -2 });
|
||||
this.vaultTimeouts.push({ name: this.i18nService.t('onLocked'), value: -2 });
|
||||
}
|
||||
|
||||
this.lockOptions.push({ name: this.i18nService.t('onRestart'), value: -1 });
|
||||
this.lockOptions.push({ name: this.i18nService.t('never'), value: null });
|
||||
this.vaultTimeouts.push({ name: this.i18nService.t('onRestart'), value: -1 });
|
||||
this.vaultTimeouts.push({ name: this.i18nService.t('never'), value: null });
|
||||
|
||||
let option = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (option != null) {
|
||||
if (option === -2 && !showOnLocked) {
|
||||
option = -1;
|
||||
this.vaultTimeoutActions = [
|
||||
{ name: this.i18nService.t('lock'), value: 'lock' },
|
||||
{ name: this.i18nService.t('logOut'), value: 'logOut' },
|
||||
];
|
||||
|
||||
let timeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (timeout != null) {
|
||||
if (timeout === -2 && !showOnLocked) {
|
||||
timeout = -1;
|
||||
}
|
||||
this.lockOption = option;
|
||||
this.vaultTimeout = timeout;
|
||||
}
|
||||
this.previousLockOption = this.lockOption;
|
||||
this.previousVaultTimeout = this.vaultTimeout;
|
||||
const action = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
|
||||
this.vaultTimeoutAction = action == null ? 'lock' : action;
|
||||
|
||||
const pinSet = await this.lockService.isPinLockSet();
|
||||
const pinSet = await this.vaultTimeoutService.isPinLockSet();
|
||||
this.pin = pinSet[0] || pinSet[1];
|
||||
}
|
||||
|
||||
async saveLockOption(newValue: number) {
|
||||
async saveVaultTimeout(newValue: number) {
|
||||
if (newValue == null) {
|
||||
const confirmed = await this.platformUtilsService.showDialog(
|
||||
this.i18nService.t('neverLockWarning'), null,
|
||||
this.i18nService.t('yes'), this.i18nService.t('cancel'), 'warning');
|
||||
if (!confirmed) {
|
||||
this.lockOptions.forEach((option: any, i) => {
|
||||
if (option.value === this.lockOption) {
|
||||
this.lockOptionsSelectRef.nativeElement.value = i + ': ' + this.lockOption;
|
||||
this.vaultTimeouts.forEach((option: any, i) => {
|
||||
if (option.value === this.vaultTimeout) {
|
||||
this.vaultTimeoutSelectRef.nativeElement.value = i + ': ' + this.vaultTimeout;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.previousLockOption = this.lockOption;
|
||||
this.lockOption = newValue;
|
||||
await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null);
|
||||
if (this.previousLockOption == null) {
|
||||
this.previousVaultTimeout = this.vaultTimeout;
|
||||
this.vaultTimeout = newValue;
|
||||
await this.vaultTimeoutService.setVaultTimeoutOptions(this.vaultTimeout != null ? this.vaultTimeout : null,
|
||||
this.vaultTimeoutAction);
|
||||
if (this.previousVaultTimeout == null) {
|
||||
this.messagingService.send('bgReseedStorage');
|
||||
}
|
||||
}
|
||||
|
||||
async saveVaultTimeoutAction(newValue: string) {
|
||||
this.vaultTimeoutAction = newValue;
|
||||
await this.vaultTimeoutService.setVaultTimeoutOptions(this.vaultTimeout != null ? this.vaultTimeout : null,
|
||||
this.vaultTimeoutAction);
|
||||
}
|
||||
|
||||
async updatePin() {
|
||||
if (this.pin) {
|
||||
const div = document.createElement('div');
|
||||
|
@ -160,7 +176,7 @@ export class SettingsComponent implements OnInit {
|
|||
if (masterPassOnRestart) {
|
||||
const encPin = await this.cryptoService.encrypt(pin);
|
||||
await this.storageService.save(ConstantsService.protectedPin, encPin.encryptedString);
|
||||
this.lockService.pinProtectedKey = pinProtectedKey;
|
||||
this.vaultTimeoutService.pinProtectedKey = pinProtectedKey;
|
||||
} else {
|
||||
await this.storageService.save(ConstantsService.pinProtectedKey, pinProtectedKey.encryptedString);
|
||||
}
|
||||
|
@ -170,13 +186,13 @@ export class SettingsComponent implements OnInit {
|
|||
}
|
||||
if (!this.pin) {
|
||||
await this.cryptoService.clearPinProtectedKey();
|
||||
await this.lockService.clear();
|
||||
await this.vaultTimeoutService.clear();
|
||||
}
|
||||
}
|
||||
|
||||
async lock() {
|
||||
this.analytics.eventTrack.next({ action: 'Lock Now' });
|
||||
await this.lockService.lock(true);
|
||||
await this.vaultTimeoutService.lock(true);
|
||||
}
|
||||
|
||||
async logOut() {
|
||||
|
|
Loading…
Reference in New Issue