mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
11 changed files with 105 additions and 49 deletions
@ -0,0 +1,15 @@ |
|||
import { NgModule } from '@angular/core'; |
|||
import { RouterModule, Routes } from '@angular/router'; |
|||
import { AuthGuard } from '@ghostfolio/client/core/auth.guard'; |
|||
|
|||
import { DemoPageComponent } from './demo-page.component'; |
|||
|
|||
const routes: Routes = [ |
|||
{ path: '', component: DemoPageComponent, canActivate: [AuthGuard] } |
|||
]; |
|||
|
|||
@NgModule({ |
|||
imports: [RouterModule.forChild(routes)], |
|||
exports: [RouterModule] |
|||
}) |
|||
export class DemoPageRoutingModule {} |
@ -0,0 +1,44 @@ |
|||
import { Component, OnDestroy } from '@angular/core'; |
|||
import { Router } from '@angular/router'; |
|||
import { DataService } from '@ghostfolio/client/services/data.service'; |
|||
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service'; |
|||
import { InfoItem } from '@ghostfolio/common/interfaces'; |
|||
import { Subject } from 'rxjs'; |
|||
|
|||
@Component({ |
|||
host: { class: 'page' }, |
|||
selector: 'gf-demo-page', |
|||
templateUrl: './demo-page.html' |
|||
}) |
|||
export class DemoPageComponent implements OnDestroy { |
|||
public info: InfoItem; |
|||
|
|||
private unsubscribeSubject = new Subject<void>(); |
|||
|
|||
public constructor( |
|||
private dataService: DataService, |
|||
private router: Router, |
|||
private tokenStorageService: TokenStorageService |
|||
) { |
|||
this.info = this.dataService.fetchInfo(); |
|||
} |
|||
|
|||
public ngOnInit() { |
|||
const hasToken = this.tokenStorageService.getToken()?.length > 0; |
|||
|
|||
if (hasToken) { |
|||
alert( |
|||
'As you are already logged in, you cannot access the demo account.' |
|||
); |
|||
} else { |
|||
this.tokenStorageService.saveToken(this.info.demoAuthToken, true); |
|||
} |
|||
|
|||
this.router.navigate(['/']); |
|||
} |
|||
|
|||
public ngOnDestroy() { |
|||
this.unsubscribeSubject.next(); |
|||
this.unsubscribeSubject.complete(); |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
import { CommonModule } from '@angular/common'; |
|||
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; |
|||
|
|||
import { DemoPageRoutingModule } from './demo-page-routing.module'; |
|||
import { DemoPageComponent } from './demo-page.component'; |
|||
|
|||
@NgModule({ |
|||
declarations: [DemoPageComponent], |
|||
imports: [CommonModule, DemoPageRoutingModule], |
|||
schemas: [CUSTOM_ELEMENTS_SCHEMA] |
|||
}) |
|||
export class DemoPageModule {} |
Loading…
Reference in new issue