From b247a132709eb212fef4f77c4912dc0ec108f36b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 29 May 2019 14:39:49 +0200 Subject: Add success icon on registration --- client/src/app/core/core.module.ts | 3 +++ client/src/app/core/routing/redirect.service.ts | 9 +++++++- .../src/app/core/routing/unlogged-guard.service.ts | 25 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 client/src/app/core/routing/unlogged-guard.service.ts (limited to 'client/src/app/core') diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index d3e72afb4..06fa8fcf1 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts @@ -20,6 +20,7 @@ import { Notifier } from './notification' import { MessageService } from 'primeng/api' import { UserNotificationSocket } from '@app/core/notification/user-notification-socket.service' import { ServerConfigResolver } from './routing/server-config-resolver.service' +import { UnloggedGuard } from '@app/core/routing/unlogged-guard.service' @NgModule({ imports: [ @@ -58,6 +59,8 @@ import { ServerConfigResolver } from './routing/server-config-resolver.service' ThemeService, LoginGuard, UserRightGuard, + UnloggedGuard, + RedirectService, Notifier, MessageService, diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index e1db4097b..571822b76 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts @@ -42,7 +42,14 @@ export class RedirectService { } redirectToPreviousRoute () { - if (this.previousUrl) return this.router.navigateByUrl(this.previousUrl) + const exceptions = [ + '/verify-account' + ] + + if (this.previousUrl) { + const isException = exceptions.find(e => this.previousUrl.startsWith(e)) + if (!isException) return this.router.navigateByUrl(this.previousUrl) + } return this.redirectToHomepage() } diff --git a/client/src/app/core/routing/unlogged-guard.service.ts b/client/src/app/core/routing/unlogged-guard.service.ts new file mode 100644 index 000000000..3132a1a77 --- /dev/null +++ b/client/src/app/core/routing/unlogged-guard.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@angular/core' +import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' +import { AuthService } from '../auth/auth.service' +import { RedirectService } from './redirect.service' + +@Injectable() +export class UnloggedGuard implements CanActivate, CanActivateChild { + + constructor ( + private router: Router, + private auth: AuthService, + private redirectService: RedirectService + ) {} + + canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + if (this.auth.isLoggedIn() === false) return true + + this.redirectService.redirectToHomepage() + return false + } + + canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + return this.canActivate(route, state) + } +} -- cgit v1.2.3