From ea6317e3a2869a0f5f10be908de739c625b123e5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 9 Jun 2018 13:59:09 -0400 Subject: [PATCH] lock screen. cleanup modals on navigate --- src/app/accounts/hint.component.html | 2 +- src/app/accounts/lock.component.html | 34 ++++++++++++++++++++++++++++ src/app/accounts/lock.component.ts | 27 ++++++++++++++++++++++ src/app/app-routing.module.ts | 2 ++ src/app/app.component.ts | 24 +++++++++++++++++++- src/app/app.module.ts | 2 ++ src/locales/en/messages.json | 9 ++++++++ 7 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/app/accounts/lock.component.html create mode 100644 src/app/accounts/lock.component.ts diff --git a/src/app/accounts/hint.component.html b/src/app/accounts/hint.component.html index 090942791e..0e7fab7d6f 100644 --- a/src/app/accounts/hint.component.html +++ b/src/app/accounts/hint.component.html @@ -4,10 +4,10 @@

{{'passwordHint' | i18n}}

-

{{'enterEmailToGetHint' | i18n}}

+ {{'enterEmailToGetHint' | i18n}}

diff --git a/src/app/accounts/lock.component.html b/src/app/accounts/lock.component.html new file mode 100644 index 0000000000..5329357624 --- /dev/null +++ b/src/app/accounts/lock.component.html @@ -0,0 +1,34 @@ +
+
+
+

+ +

+

{{'yourVaultIsLocked' | i18n}}

+
+
+
+ +
+ + +
+
+
+
+ + +
+
+
+
+
+
diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts new file mode 100644 index 0000000000..39fced9b16 --- /dev/null +++ b/src/app/accounts/lock.component.ts @@ -0,0 +1,27 @@ +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'; + +import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; + +@Component({ + selector: 'app-lock', + templateUrl: 'lock.component.html', +}) +export class LockComponent extends BaseLockComponent { + constructor(router: Router, analytics: Angulartics2, + toasterService: ToasterService, i18nService: I18nService, + platformUtilsService: PlatformUtilsService, messagingService: MessagingService, + userService: UserService, cryptoService: CryptoService) { + super(router, analytics, toasterService, i18nService, platformUtilsService, + messagingService, userService, cryptoService); + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b7f8923f84..02db826a97 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -9,6 +9,7 @@ import { OrganizationLayoutComponent } from './layouts/organization-layout.compo import { UserLayoutComponent } from './layouts/user-layout.component'; import { HintComponent } from './accounts/hint.component'; +import { LockComponent } from './accounts/lock.component'; import { LoginComponent } from './accounts/login.component'; import { RegisterComponent } from './accounts/register.component'; import { TwoFactorComponent } from './accounts/two-factor.component'; @@ -32,6 +33,7 @@ const routes: Routes = [ { path: '2fa', component: TwoFactorComponent }, { path: 'register', component: RegisterComponent }, { path: 'hint', component: HintComponent }, + { path: 'lock', component: LockComponent }, ], }, { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b806a07ef8..599e00d60e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,3 +1,7 @@ +import * as jq from 'jquery'; +import * as _swal from 'sweetalert'; +import { SweetAlert } from 'sweetalert/typings/core'; + import { ToasterConfig, ToasterContainerComponent, @@ -11,7 +15,10 @@ import { OnDestroy, OnInit, } from '@angular/core'; -import { Router } from '@angular/router'; +import { + NavigationEnd, + Router, +} from '@angular/router'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; @@ -34,6 +41,8 @@ import { UserService } from 'jslib/abstractions/user.service'; import { ConstantsService } from 'jslib/services/constants.service'; const BroadcasterSubscriptionId = 'AppComponent'; +// Hack due to Angular 5.2 bug +const swal: SweetAlert = _swal as any; @Component({ selector: 'app-root', @@ -94,6 +103,19 @@ export class AppComponent implements OnDestroy, OnInit { } }); }); + + this.router.events.subscribe((event) => { + if (event instanceof NavigationEnd) { + const modals = Array.from(document.querySelectorAll('.modal')); + for (const modal of modals) { + (jq(modal) as any).modal('hide'); + } + + if (document.querySelector('.swal-modal') != null) { + swal.close(undefined); + } + } + }); } ngOnDestroy() { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e473ba94da..6ea2a21c78 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,6 +23,7 @@ import { OrganizationLayoutComponent } from './layouts/organization-layout.compo import { UserLayoutComponent } from './layouts/user-layout.component'; import { HintComponent } from './accounts/hint.component'; +import { LockComponent } from './accounts/lock.component'; import { LoginComponent } from './accounts/login.component'; import { RegisterComponent } from './accounts/register.component'; import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component'; @@ -83,6 +84,7 @@ import { Folder } from 'jslib/models/domain'; IconComponent, I18nPipe, InputVerbatimDirective, + LockComponent, LoginComponent, ModalComponent, NavbarComponent, diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 48aa172deb..3d495d825c 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -532,5 +532,14 @@ }, "emailAddress": { "message": "Email Address" + }, + "yourVaultIsLocked": { + "message": "Your vault is locked. Verify your master password to continue." + }, + "unlock": { + "message": "Unlock" + }, + "invalidMasterPassword": { + "message": "Invalid master password" } }