From 5db9e9531fa24b47579fdd408a74a66d2a38521b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 9 Jun 2018 22:40:53 -0400 Subject: [PATCH] route to previous url after unlock --- src/app/accounts/lock.component.ts | 10 ++++++++- src/app/app.component.ts | 5 ++++- src/app/app.module.ts | 2 +- src/app/services/router.service.ts | 25 +++++++++++++++++++++++ src/app/{ => services}/services.module.ts | 14 +++++++------ 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 src/app/services/router.service.ts rename src/app/{ => services}/services.module.ts (94%) diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 80727dc7..c5daf754 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -13,6 +13,8 @@ import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { RouterService } from '../services/router.service'; + import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; @Component({ @@ -23,7 +25,8 @@ export class LockComponent extends BaseLockComponent implements OnInit { constructor(router: Router, analytics: Angulartics2, toasterService: ToasterService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, messagingService: MessagingService, - userService: UserService, cryptoService: CryptoService) { + userService: UserService, cryptoService: CryptoService, + private routerService: RouterService) { super(router, analytics, toasterService, i18nService, platformUtilsService, messagingService, userService, cryptoService); } @@ -36,5 +39,10 @@ export class LockComponent extends BaseLockComponent implements OnInit { } else if (key != null) { this.router.navigate(['vault']); } + + const previousUrl = this.routerService.getPreviousUrl(); + if (previousUrl !== '/' && previousUrl.indexOf('lock') === -1) { + this.successRoute = previousUrl; + } } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c06fa5a0..bb587e59 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -40,6 +40,8 @@ import { UserService } from 'jslib/abstractions/user.service'; import { ConstantsService } from 'jslib/services/constants.service'; +import { RouterService } from './services/router.service'; + const BroadcasterSubscriptionId = 'AppComponent'; // Hack due to Angular 5.2 bug const swal: SweetAlert = _swal as any; @@ -67,7 +69,8 @@ export class AppComponent implements OnDestroy, OnInit { private toasterService: ToasterService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private ngZone: NgZone, private lockService: LockService, private storageService: StorageService, - private cryptoService: CryptoService, private collectionService: CollectionService) { } + private cryptoService: CryptoService, private collectionService: CollectionService, + private routerService: RouterService) { } ngOnInit() { this.ngZone.runOutsideAngular(() => { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6ea2a21c..68094f76 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -11,7 +11,7 @@ import { FormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { ServicesModule } from './services.module'; +import { ServicesModule } from './services/services.module'; import { AppComponent } from './app.component'; import { ModalComponent } from './modal.component'; diff --git a/src/app/services/router.service.ts b/src/app/services/router.service.ts new file mode 100644 index 00000000..24677639 --- /dev/null +++ b/src/app/services/router.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@angular/core'; +import { + NavigationEnd, + Router, +} from '@angular/router'; + +@Injectable() +export class RouterService { + private previousUrl: string = undefined; + private currentUrl: string = undefined; + + constructor(private router: Router) { + this.currentUrl = this.router.url; + router.events.subscribe((event) => { + if (event instanceof NavigationEnd) { + this.previousUrl = this.currentUrl; + this.currentUrl = event.url; + } + }); + } + + getPreviousUrl() { + return this.previousUrl; + } +} diff --git a/src/app/services.module.ts b/src/app/services/services.module.ts similarity index 94% rename from src/app/services.module.ts rename to src/app/services/services.module.ts index 2a5f3ed3..a26e4ae8 100644 --- a/src/app/services.module.ts +++ b/src/app/services/services.module.ts @@ -5,13 +5,14 @@ import { import { ToasterModule } from 'angular2-toaster'; -import { BroadcasterMessagingService } from '../services/broadcasterMessaging.service'; -import { HtmlStorageService } from '../services/htmlStorage.service'; -import { I18nService } from '../services/i18n.service'; -import { MemoryStorageService } from '../services/memoryStorage.service'; -import { WebPlatformUtilsService } from '../services/webPlatformUtils.service'; +import { BroadcasterMessagingService } from '../../services/broadcasterMessaging.service'; +import { HtmlStorageService } from '../../services/htmlStorage.service'; +import { I18nService } from '../../services/i18n.service'; +import { MemoryStorageService } from '../../services/memoryStorage.service'; +import { WebPlatformUtilsService } from '../../services/webPlatformUtils.service'; -import { UnauthGuardService } from './services/unauth-guard.service'; +import { RouterService } from './router.service'; +import { UnauthGuardService } from './unauth-guard.service'; import { AuthGuardService } from 'jslib/angular/services/auth-guard.service'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; @@ -138,6 +139,7 @@ export function initFactory(): Function { ValidationService, AuthGuardService, UnauthGuardService, + RouterService, { provide: AuditServiceAbstraction, useValue: auditService }, { provide: AuthServiceAbstraction, useValue: authService }, { provide: CipherServiceAbstraction, useValue: cipherService },