diff options
Diffstat (limited to 'ufund-ui/src/app')
| -rw-r--r-- | ufund-ui/src/app/app.component.html | 4 | ||||
| -rw-r--r-- | ufund-ui/src/app/app.component.ts | 19 | ||||
| -rw-r--r-- | ufund-ui/src/app/components/login/login.component.html | 1 | 
3 files changed, 14 insertions, 10 deletions
diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index b41a225..89075e1 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -17,8 +17,8 @@          <a routerLink="/cupboard">Cupboard</a>          <a routerLink="/basket">Basket</a>  <!--        <span>{{currentUser$ | async}}</span>--> -        <button *ngIf="currentUser$.value != 'Logged out.'" onclick="location.href='/';"> Log Out</button> -        <button *ngIf="currentUser$.value == 'Logged out.'" routerLink="/login"> Log In</button> +        <button *ngIf="currentUser | async" (click)="logout()"> Log Out</button> +        <button *ngIf="!(currentUser | async)" (click)="login()"> Log In</button>      </div>  </div> diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 7d9afcd..8068659 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -3,6 +3,8 @@ import {BehaviorSubject, Observable} from 'rxjs';  import { DOCUMENT } from '@angular/common';  import {AuthService} from './services/auth.service';  import {ToastType} from './services/toasts.service'; +import {User} from './models/User'; +import {ActivatedRoute, Router} from '@angular/router';  interface ToastProps {      type: ToastType, message: string, action?: {label: string, onAction: () => void} @@ -16,12 +18,14 @@ interface ToastProps {  })  export class AppComponent implements OnInit {      // title = 'ufund-ui'; -    currentUser$: BehaviorSubject<string> = new BehaviorSubject<string>("Logged out."); +    currentUser?: BehaviorSubject<User | null>;      toast = new BehaviorSubject<ToastProps>({type: ToastType.INFO, message: "testToast"})      constructor(          private authService: AuthService, +        private router: Router, +        private route: ActivatedRoute,          @Inject(DOCUMENT) private document: Document      ) {} @@ -30,14 +34,15 @@ export class AppComponent implements OnInit {      }      ngOnInit() { -        this.authService.getCurrentUserSubject().subscribe(r => { -            this.currentUser$?.next(r -                ? "Logged in as " + r.username -                : "Logged out." -            ) -        }) +        this.currentUser = this.authService.getCurrentUserSubject()      } +    login() { +        this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); +    } +    logout() { +        location.reload() +    }  } diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index 743b1b3..e1c3e2a 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -1,5 +1,4 @@  <div id="box"> -    <span *ngIf="next" style="color: red">You must be logged in to view this page</span>      <h1>Login</h1>      <input placeholder="Username" type="text" #username>      <input placeholder="Password" type="password" #password>  | 
