aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Angular
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Angular')
-rw-r--r--src/DevHive.Angular/src/app/components/feed/feed.component.ts11
-rw-r--r--src/DevHive.Angular/src/app/components/login/login.component.ts21
2 files changed, 22 insertions, 10 deletions
diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.ts b/src/DevHive.Angular/src/app/components/feed/feed.component.ts
index fa2575f..fcf0af4 100644
--- a/src/DevHive.Angular/src/app/components/feed/feed.component.ts
+++ b/src/DevHive.Angular/src/app/components/feed/feed.component.ts
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
+import { Router } from '@angular/router';
import { FeedService } from 'src/app/services/feed.service';
import { PostComponent } from '../post/post.component';
@@ -12,7 +13,7 @@ export class FeedComponent implements OnInit {
private _title = 'Feed';
public posts: PostComponent[];
- constructor(private titleService: Title, private service: FeedService) {
+ constructor(private titleService: Title, private service: FeedService, private router: Router) {
this.titleService.setTitle(this._title);
}
@@ -22,6 +23,12 @@ export class FeedComponent implements OnInit {
new PostComponent(),
new PostComponent(),
new PostComponent(),
- ]
+ ];
+
+ if (sessionStorage.getItem('UserCred')) { /* TODO: improve token validation */
+ /* Make use of the JWT, will be implemented later */
+ } else {
+ this.router.navigate(['/login']);
+ }
}
}
diff --git a/src/DevHive.Angular/src/app/components/login/login.component.ts b/src/DevHive.Angular/src/app/components/login/login.component.ts
index fb90837..2048c73 100644
--- a/src/DevHive.Angular/src/app/components/login/login.component.ts
+++ b/src/DevHive.Angular/src/app/components/login/login.component.ts
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
+import { Router } from '@angular/router';
import { Title } from '@angular/platform-browser';
@Component({
@@ -12,7 +13,7 @@ export class LoginComponent implements OnInit {
private _title = 'Login';
- constructor(private titleService: Title, private fb: FormBuilder) {
+ constructor(private titleService: Title, private fb: FormBuilder, private router: Router) {
titleService.setTitle(this._title);
}
@@ -29,16 +30,20 @@ export class LoginComponent implements OnInit {
});
}
- onSubmit(): void {
- fetch('http://localhost:5000/api/User/login', {
+ async onSubmit(): Promise<void> {
+ const response = await fetch('http://localhost:5000/api/User/login', {
method: 'POST',
- body: `{
- "UserName": "${this.loginUserFormGroup.get('username')?.value}",
- "Password": "${this.loginUserFormGroup.get('password')?.value}"
- }`,
+ body: JSON.stringify({
+ UserName: this.loginUserFormGroup.get('username')?.value,
+ Password: this.loginUserFormGroup.get('password')?.value
+ }),
headers: {
'Content-Type': 'application/json'
}
- }).then(response => response.json()).then(data => { console.log(data); });
+ });
+ const userCred: string = await response.json();
+
+ sessionStorage.setItem('UserCred', JSON.stringify(userCred));
+ this.router.navigate(['/']);
}
}