article image @@ -10,7 +9,7 @@ beaucoup d'aspects du manga comme la mémoire humaine, la spontanéité des uns qui vient en opposition avec l'hypocrisie des autres et plein d'autres thèmes ! Disclaimer : Tout comme mon post sur "Persona 3 Reload - Episode Aigis", je spoil l'intégralité de l'oeuvre.

- +
Guams diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index f174386..1a218f0 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,12 +1,11 @@ import {Component, OnDestroy} from '@angular/core'; import {AvatarModule} from 'primeng/avatar'; -import {Button, ButtonDirective} from 'primeng/button'; +import {Button} from 'primeng/button'; import {AuthorService} from '../services/author.service'; import {Author} from '../model/author'; import {JsonPipe} from '@angular/common'; import {Subscription} from 'rxjs'; -import {PostService} from '../services/post.service'; -import {Header, MessageService} from 'primeng/api'; +import {MessageService} from 'primeng/api'; import {HeaderComponent} from '../header/header.component'; import {ToastModule} from 'primeng/toast'; import {CookieService} from 'ngx-cookie-service'; @@ -21,9 +20,6 @@ import {CookieService} from 'ngx-cookie-service'; ToastModule, JsonPipe ], - providers: [ - MessageService, - ], templateUrl: './home.component.html', styleUrl: './home.component.css' }) @@ -34,17 +30,13 @@ export class HomeComponent implements OnDestroy { constructor( private authorService: AuthorService, - private postService: PostService, private messageService: MessageService, private cookieService: CookieService) { if (this.cookieService.get('author')) { this.actualAuthor = JSON.parse(this.cookieService.get('author')); - if (this.cookieService.get("just-authenticated")) { - this.successMessage('Connecté avec succès', `Heureux de vous revoir ${this.actualAuthor?.name}`); - } } - this.subs.push(authorService.list() + this.subs.push(this.authorService.list() .subscribe({ next: (authors: Author[]) => this.authors = authors, error: (err) => console.error(err.message), @@ -56,7 +48,7 @@ export class HomeComponent implements OnDestroy { severity: 'success', summary: summary, detail: detail, - life: 1500, + life: 3000, closable: false }); } diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index e05192d..3e62198 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -1,4 +1,3 @@ - diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 2347e41..0f18c88 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -1,4 +1,4 @@ -import {Component, CUSTOM_ELEMENTS_SCHEMA, OnDestroy} from '@angular/core'; +import {ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, OnDestroy} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {InputTextModule} from 'primeng/inputtext'; import {Button} from 'primeng/button'; @@ -24,10 +24,7 @@ import {Router} from '@angular/router'; HeaderComponent ], templateUrl: './login.component.html', - styleUrl: './login.component.css', - providers: [ - MessageService, - ] + styleUrl: './login.component.css' }) export class LoginComponent implements OnDestroy { name: string = ""; @@ -46,13 +43,18 @@ export class LoginComponent implements OnDestroy { this.subs.push ( this.authorService.login(this.name, this.password).pipe( - switchMap((tokenObj: any) => this.authorService.me(tokenObj.token))) + switchMap((tokenObj: any) => { + this.cookieService.set("token", tokenObj.token); + return this.authorService.me(tokenObj.token) + })) .subscribe({ next: (author: Author) => { this.cookieService.set("author", JSON.stringify(author)); this.cookieService.set("just-authenticated", "true"); this.getAuthorCookie(); - this.router.navigate(['/']); + this.router.navigate(['/']).then(() => { + this.successMessage('Connecté avec succès', 'Heureux de vous revoir ' + this.actualAuthor?.name) + }); }, error: (err) => this.failureMessage('Erreur de connexion', err.message) }) @@ -67,12 +69,22 @@ export class LoginComponent implements OnDestroy { this.actualAuthor = JSON.parse(this.cookieService.get("author")); } + successMessage(summary: string, detail: string): void { + this.messageService.add({ + severity: 'success', + summary: summary, + detail: detail, + life: 3000, + closable: false + }); + } + failureMessage(summary: string, detail: string): void { this.messageService.add({ severity: 'error', summary: summary, detail: detail, - life: 1500, + life: 3000, closable: false }); } diff --git a/src/app/logout/logout.component.ts b/src/app/logout/logout.component.ts index 2dff5a0..ed0cfaf 100644 --- a/src/app/logout/logout.component.ts +++ b/src/app/logout/logout.component.ts @@ -2,6 +2,7 @@ import {Component, OnInit} from '@angular/core'; import {CookieService} from 'ngx-cookie-service'; import {HeaderComponent} from '../header/header.component'; import {Router} from '@angular/router'; +import {MessageService} from 'primeng/api'; @Component({ selector: 'app-logout', @@ -15,10 +16,21 @@ import {Router} from '@angular/router'; export class LogoutComponent implements OnInit{ constructor(private cookiesService: CookieService, + private messageService: MessageService, private router: Router) { } ngOnInit(): void { this.cookiesService.deleteAll(); - this.router.navigate(['/']); + this.router.navigate(['/']).then(() => this.successMessage('Déconnexion', 'Vous avez été deconnecté avec succès')); + } + + successMessage(summary: string, detail: string): void { + this.messageService.add({ + severity: 'success', + summary: summary, + detail: detail, + life: 3000, + closable: false + }); } } diff --git a/src/app/not-found/not-found.component.css b/src/app/not-found/not-found.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/not-found/not-found.component.html b/src/app/not-found/not-found.component.html new file mode 100644 index 0000000..836949a --- /dev/null +++ b/src/app/not-found/not-found.component.html @@ -0,0 +1,3 @@ +

Erreur 404

+

Il semblerait que vous vous soyez trompé !

+Revenir à la page d'accueil diff --git a/src/app/not-found/not-found.component.ts b/src/app/not-found/not-found.component.ts new file mode 100644 index 0000000..d76bf37 --- /dev/null +++ b/src/app/not-found/not-found.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; +import {RouterLink} from '@angular/router'; + +@Component({ + selector: 'app-not-found', + standalone: true, + imports: [ + RouterLink + ], + templateUrl: './not-found.component.html', + styleUrl: './not-found.component.css' +}) +export class NotFoundComponent { + +} diff --git a/src/app/profile/profile.component.css b/src/app/profile/profile.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html new file mode 100644 index 0000000..97b986d --- /dev/null +++ b/src/app/profile/profile.component.html @@ -0,0 +1,14 @@ + +{{ concernedAuthor | json }} + + + +

+ + + @if (concernedAuthor?.id === actualAuthor?.id) { + + + } +

+
diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts new file mode 100644 index 0000000..823b21a --- /dev/null +++ b/src/app/profile/profile.component.ts @@ -0,0 +1,47 @@ +import {Component, OnDestroy} from '@angular/core'; +import {HeaderComponent} from '../header/header.component'; +import {ActivatedRoute, Router} from '@angular/router'; +import {CookieService} from 'ngx-cookie-service'; +import {Author} from '../model/author'; +import {Subscription} from 'rxjs'; +import {AuthorService} from '../services/author.service'; +import {JsonPipe} from '@angular/common'; +import {AvatarModule} from 'primeng/avatar'; +import {CardModule} from 'primeng/card'; +import {Button} from 'primeng/button'; + +@Component({ + selector: 'app-profile', + standalone: true, + imports: [ + HeaderComponent, + JsonPipe, + AvatarModule, + CardModule, + Button + ], + templateUrl: './profile.component.html', + styleUrl: './profile.component.css' +}) +export class ProfileComponent implements OnDestroy{ + actualAuthor: Author | undefined; + concernedAuthor: Author | undefined; + subs: Subscription[] = []; + constructor(private route: ActivatedRoute, + private authorService: AuthorService, + private cookieService: CookieService) { + this.route.paramMap.subscribe(params => { + this.subs.push(this.authorService.getAuthor(params.get('authorId')).subscribe(author => { + this.concernedAuthor = author; + })); + }) + if (this.cookieService.get('author')) { + this.actualAuthor = JSON.parse(this.cookieService.get("author")); + } + } + + ngOnDestroy(): void { + this.subs.forEach(sub => sub.unsubscribe()); + } + +} diff --git a/src/app/services/author.service.ts b/src/app/services/author.service.ts index bb5c67c..217f190 100644 --- a/src/app/services/author.service.ts +++ b/src/app/services/author.service.ts @@ -20,7 +20,14 @@ export class AuthorService { me(token: string): Observable { const headers = new HttpHeaders().set("Authorization", "Bearer " + token); - console.log(headers) return this.httpClient.get("http://localhost:8080/api/authors/me", {'headers': headers}); } + + getAuthor(id: string | null): Observable { + if (id) { + return this.httpClient.get("http://localhost:8080/api/authors/" + id); + } else { + throw new Error("Not Found"); + } + } }