diff options
author | benal01 <bja4245@rit.edu> | 2025-04-01 09:34:36 -0400 |
---|---|---|
committer | benal01 <bja4245@rit.edu> | 2025-04-01 09:34:36 -0400 |
commit | 7ed26c5ee7171a502f6f8527fc55de2bb77eab3b (patch) | |
tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/app.component.ts | |
parent | ef46ddd082bb91d0262363536d46fe3eb4da47be (diff) | |
parent | d8330f1ac85b26d08ca4df5ce3875078d7b4f47f (diff) | |
download | JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.gz JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.bz2 JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.zip |
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b-jellysolutions
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() + } } |