diff options
Diffstat (limited to 'ufund-ui/src/app/app.component.ts')
-rw-r--r-- | ufund-ui/src/app/app.component.ts | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 7dc8ffb..2f98334 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,7 +1,10 @@ -import {Component, OnInit, Inject} from '@angular/core'; -import {UsersService} from './services/users.service'; +import {Component, OnInit, Inject, ViewContainerRef} from '@angular/core'; import {BehaviorSubject} from 'rxjs'; import { DOCUMENT } from '@angular/common'; +import {AuthService} from './services/auth.service'; +import {ToastsService} from './services/toasts.service'; +import {User} from './models/User'; +import {ActivatedRoute, Router} from '@angular/router'; @Component({ selector: 'app-root', @@ -11,24 +14,38 @@ import { DOCUMENT } from '@angular/common'; }) export class AppComponent implements OnInit { // title = 'ufund-ui'; - currentUser$: BehaviorSubject<string> = new BehaviorSubject<string>("Logged out."); + currentUser?: BehaviorSubject<User | null>; constructor( - private userService: UsersService, + private authService: AuthService, + private router: Router, + private route: ActivatedRoute, + protected toastService: ToastsService, + private viewContainerRef: ViewContainerRef, @Inject(DOCUMENT) private document: Document ) {} reloadPage() { this.document.defaultView?.location.reload(); - } + } ngOnInit() { - this.userService.getCurrentUserSubject().subscribe(r => { - this.currentUser$?.next(r - ? "Logged in as " + r.username - : "Logged out." - ) - }) + this.toastService.setRootViewContainerRef(this.viewContainerRef) + this.currentUser = this.authService.getCurrentUserSubject() + let data = localStorage.getItem("credential"); + if (data) { + let dataParsed = JSON.parse(data) + this.authService.restoreLogin(dataParsed.username, dataParsed.key) + console.log("Key found", dataParsed.key) + } + } + + login() { + this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); } + logout() { + localStorage.removeItem("credential") + location.reload() + } } |