aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src')
-rw-r--r--ufund-ui/src/app/app.component.html4
-rw-r--r--ufund-ui/src/app/app.component.ts21
-rw-r--r--ufund-ui/src/app/app.module.ts6
-rw-r--r--ufund-ui/src/app/components/dashboard/dashboard.component.html2
-rw-r--r--ufund-ui/src/app/components/dashboard/dashboard.component.ts2
-rw-r--r--ufund-ui/src/app/components/login/login.component.html8
-rw-r--r--ufund-ui/src/app/components/login/login.component.ts18
-rw-r--r--ufund-ui/src/app/models/Need.ts2
-rw-r--r--ufund-ui/src/app/models/User.ts2
-rw-r--r--ufund-ui/src/app/services/cupboard.service.ts3
-rw-r--r--ufund-ui/src/app/services/users.service.ts40
11 files changed, 88 insertions, 20 deletions
diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html
index cfebc2b..6b9338c 100644
--- a/ufund-ui/src/app/app.component.html
+++ b/ufund-ui/src/app/app.component.html
@@ -1,4 +1,6 @@
-<h1>jelly solutions:</h1>
+<h1>jelly solutions</h1>
+<span>{{currentUser$ | async}}</span>
+<hr>
<router-outlet />
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts
index 2dbf33c..a85d04b 100644
--- a/ufund-ui/src/app/app.component.ts
+++ b/ufund-ui/src/app/app.component.ts
@@ -1,4 +1,7 @@
-import { Component } from '@angular/core';
+import {Component, OnInit} from '@angular/core';
+import {UsersService} from './services/users.service';
+import {BehaviorSubject, Observable, Subject} from 'rxjs';
+import {User} from './models/User';
@Component({
selector: 'app-root',
@@ -6,6 +9,18 @@ import { Component } from '@angular/core';
standalone: false,
styleUrl: './app.component.css'
})
-export class AppComponent {
- title = 'ufund-ui';
+export class AppComponent implements OnInit {
+ // title = 'ufund-ui';
+ currentUser$: BehaviorSubject<string> = new BehaviorSubject<string>("Logged out.");
+
+ constructor(
+ private userService: UsersService
+ ) {}
+
+ ngOnInit() {
+ this.userService.getCurrentUser().subscribe(r => {
+ this.currentUser$?.next("Logged in as " + r.username)
+ })
+ }
+
}
diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts
index d818841..9203e3b 100644
--- a/ufund-ui/src/app/app.module.ts
+++ b/ufund-ui/src/app/app.module.ts
@@ -9,6 +9,8 @@ import {FundingBasketComponent} from './components/funding-basket/funding-basket
import {CupboardComponent} from './components/cupboard/cupboard.component';
import {NeedListComponent} from './components/need-list/need-list.component';
import {HttpClientModule} from '@angular/common/http';
+import {FormsModule} from '@angular/forms';
+import {RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router';
@NgModule({
declarations: [
@@ -22,6 +24,10 @@ import {HttpClientModule} from '@angular/common/http';
imports: [
BrowserModule,
AppRoutingModule,
+ FormsModule,
+ RouterLink,
+ RouterLinkActive,
+ RouterOutlet,
HttpClientModule,
],
providers: [],
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html
index 9c5fce9..f41ccef 100644
--- a/ufund-ui/src/app/components/dashboard/dashboard.component.html
+++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html
@@ -1 +1,3 @@
<p>dashboard works!</p>
+<a routerLink="/cupboard">Go to the Cupboard</a>
+<a routerLink="/basket">Go to my basket</a>
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts
index 6da4013..dd323c4 100644
--- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts
+++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts
@@ -7,5 +7,5 @@ import { Component } from '@angular/core';
styleUrl: './dashboard.component.css'
})
export class DashboardComponent {
-
+ constructor() {}
}
diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html
index 41427ae..178ddbf 100644
--- a/ufund-ui/src/app/components/login/login.component.html
+++ b/ufund-ui/src/app/components/login/login.component.html
@@ -1,5 +1,5 @@
<p>Login:</p>
-<input placeholder="Username" type="text">
-<input placeholder="Password" type="password">
-<button>Login</button>
-<button>Create Account...</button>
+<input placeholder="Username" type="text" #username>
+<input placeholder="Password" type="password" #password>
+<button type="button" (click)="login(username.value, password.value)">Login</button>
+<button type="button">Create Account...</button>
diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts
index efb8a58..50dd018 100644
--- a/ufund-ui/src/app/components/login/login.component.ts
+++ b/ufund-ui/src/app/components/login/login.component.ts
@@ -1,4 +1,6 @@
-import { Component } from '@angular/core';
+import { Component } from '@angular/core'
+import {UsersService} from '../../services/users.service';
+import {Router} from '@angular/router';
@Component({
selector: 'app-login',
@@ -7,5 +9,19 @@ import { Component } from '@angular/core';
styleUrl: './login.component.css'
})
export class LoginComponent {
+ constructor(
+ protected usersService: UsersService,
+ private router: Router
+ ) {}
+ login(username: string | null, password: string | null) {
+ console.log(`attempting to log in with ${username} ${password}`)
+ if (!username || !password) {
+ return;
+ }
+
+ this.usersService.login(username, password).then(() => {
+ this.router.navigate(['/dashboard']);
+ })
+ }
}
diff --git a/ufund-ui/src/app/models/Need.ts b/ufund-ui/src/app/models/Need.ts
index c0425ec..9e97fd4 100644
--- a/ufund-ui/src/app/models/Need.ts
+++ b/ufund-ui/src/app/models/Need.ts
@@ -1,7 +1,7 @@
export interface Need {
name: string,
id: number,
- filterAttributes: String[],
+ filterAttributes: string[],
type: GoalType;
maxGoal: number;
current: number;
diff --git a/ufund-ui/src/app/models/User.ts b/ufund-ui/src/app/models/User.ts
index 46fe4a1..9149fe7 100644
--- a/ufund-ui/src/app/models/User.ts
+++ b/ufund-ui/src/app/models/User.ts
@@ -2,5 +2,5 @@ import {Need} from './Need';
export interface User {
username: string;
- cupboard: Need[];
+ basket: Need[];
}
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts
index c123841..4a2b4b0 100644
--- a/ufund-ui/src/app/services/cupboard.service.ts
+++ b/ufund-ui/src/app/services/cupboard.service.ts
@@ -18,8 +18,7 @@ export class CupboardService {
) {}
createNeed(need: Need): Observable<boolean> {
- return this.http.post<boolean>(
- this.url, need, this.httpOptions)
+ return this.http.post<boolean>(this.url, need, this.httpOptions)
}
getNeeds(): Observable<Need[]> {
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts
index 571c004..28cc266 100644
--- a/ufund-ui/src/app/services/users.service.ts
+++ b/ufund-ui/src/app/services/users.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
-import {Observable} from 'rxjs';
+import {firstValueFrom, Observable, of, Subject} from 'rxjs';
import {User} from '../models/User';
@Injectable({
@@ -8,11 +8,24 @@ import {User} from '../models/User';
})
export class UsersService {
- private currentUserID? : number
+ private currentUser : Subject<User> = new Subject();
+ private apiKey: string = "";
private url = "http://localhost:8080/users"
+ private authUrl = "http://localhost:8080/auth"
private httpOptions = {
- headers: new HttpHeaders({'Content-Type': 'application/json'})
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.apiKey
+ })
+ };
+ private httpOptions2 = {
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.apiKey
+ }),
+ responseType: "text" as "json" // don't ask me how or why this works, bc i have no clue...
+ // see the relevant angular bug report https://github.com/angular/angular/issues/18586
};
constructor(
@@ -23,7 +36,7 @@ export class UsersService {
return this.http.post<User>(this.url, data, this.httpOptions)
}
- getUser(id: number): Observable<User> {
+ getUser(id: string): Observable<User> {
return this.http.get<User>(`${this.url}/${id}`, this.httpOptions)
}
@@ -35,7 +48,22 @@ export class UsersService {
return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions)
}
- getCurrentUser(): Observable<User> | undefined {
- return this.currentUserID ? this.getUser(this.currentUserID) : undefined
+ getCurrentUser() {
+ return this.currentUser;
+ }
+
+ async login(username: string, password: string) {
+ let res = this.http.post<string>(this.authUrl, {username: username, password: password}, this.httpOptions2);
+ this.apiKey = await firstValueFrom(res);
+ console.log("apikey: "+this.apiKey)
+ let res2 = this.http.get<User>(`${this.url}/${username}`, {
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.apiKey
+ })
+ })
+ let currentU = await firstValueFrom(res2);
+ this.currentUser.next(currentU);
+ // this.currentUser.subscribe(r => console.log("currentUser: "+r.username))
}
}