diff options
Diffstat (limited to 'ufund-ui/src/app')
| -rw-r--r-- | ufund-ui/src/app/app.component.ts | 14 | ||||
| -rw-r--r-- | ufund-ui/src/app/components/login/login.component.ts | 2 | ||||
| -rw-r--r-- | ufund-ui/src/app/services/auth.service.ts | 14 | 
3 files changed, 26 insertions, 4 deletions
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 8068659..34256f3 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,5 +1,5 @@ -import {Component, OnInit, Inject, ViewChild} from '@angular/core'; -import {BehaviorSubject, Observable} from 'rxjs'; +import {Component, OnInit, Inject} from '@angular/core'; +import {BehaviorSubject} from 'rxjs';  import { DOCUMENT } from '@angular/common';  import {AuthService} from './services/auth.service';  import {ToastType} from './services/toasts.service'; @@ -34,7 +34,17 @@ export class AppComponent implements OnInit {      }      ngOnInit() { +        console.log("AAAAAAAAAAAAAAAA")          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) +        } else { +            console.log("key missing") +            console.log(data) +        }      }      login() { diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index f6a2996..4dcaedd 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -35,6 +35,8 @@ export class LoginComponent implements OnInit {          this.authService.login(username, password).then(() => {              this.router.navigate([next]); +            let key = this.authService.getApiKey() +            localStorage.setItem("credential", JSON.stringify({username: username, key: key}))          }).catch(ex => {              this.statusText.next("Unable to login: " + friendlyHttpStatus[ex.status])              console.log(ex) diff --git a/ufund-ui/src/app/services/auth.service.ts b/ufund-ui/src/app/services/auth.service.ts index 6bc7145..b75c931 100644 --- a/ufund-ui/src/app/services/auth.service.ts +++ b/ufund-ui/src/app/services/auth.service.ts @@ -1,7 +1,8 @@ -import {Injectable} from '@angular/core'; +import {Injectable, Injector} from '@angular/core';  import {BehaviorSubject, firstValueFrom} from 'rxjs';  import {User} from '../models/User';  import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {UsersService} from './users.service';  @Injectable({      providedIn: 'root' @@ -24,7 +25,9 @@ export class AuthService {      });      constructor( -        private http: HttpClient +        private http: HttpClient, +        // private userService: UsersService +        private injector: Injector      ) {}      async login(username: string, password: string) { @@ -42,6 +45,13 @@ export class AuthService {          // this.currentUser.subscribe(r => console.log("currentUser: "+r.username))      } +    async restoreLogin(username: string, key: string) { + +        const userService = this.injector.get(UsersService); +        this.apiKey = key; +        this.currentUser.next(await firstValueFrom(userService.getUser(username))) +    } +      getCurrentUserSubject() {          return this.currentUser;      }  | 
