diff --git a/public/favicon.ico b/public/favicon.ico deleted file mode 100644 index 57614f9..0000000 Binary files a/public/favicon.ico and /dev/null differ diff --git a/public/icon.jpg b/public/icon.jpg new file mode 100644 index 0000000..7da39e5 Binary files /dev/null and b/public/icon.jpg differ diff --git a/src/app/app.component.html b/src/app/app.component.html index cf8e555..d12ecd3 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -3,7 +3,8 @@ Votre session a expiré ! Il va falloir se reconnecter. - + } diff --git a/src/app/components/footer/footer.component.css b/src/app/components/footer/footer.component.css deleted file mode 100644 index 09205da..0000000 --- a/src/app/components/footer/footer.component.css +++ /dev/null @@ -1,25 +0,0 @@ -.footer { - background-color: #1c1c1c; - color: #f1f1f1; - padding: 20px; - text-align: center; - font-size: 14px; -} - -.footer-creator, -.footer-banner, -.footer-follow, -.footer-links, -.footer-copyright { - margin: 5px 0; -} - -.footer-link { - color: #1e90ff; - text-decoration: none; - margin: 0 10px; -} - -.footer-link:hover { - text-decoration: underline; -} diff --git a/src/app/components/footer/footer.component.html b/src/app/components/footer/footer.component.html deleted file mode 100644 index 0cbf7aa..0000000 --- a/src/app/components/footer/footer.component.html +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/src/app/components/footer/footer.component.ts b/src/app/components/footer/footer.component.ts deleted file mode 100644 index e2d1a44..0000000 --- a/src/app/components/footer/footer.component.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - selector: 'app-footer', - standalone: true, - imports: [], - templateUrl: './footer.component.html', - styleUrl: './footer.component.css' -}) -export class FooterComponent { - -} diff --git a/src/app/components/post-form/post-form.component.ts b/src/app/components/post-form/post-form.component.ts index f839b54..c3573bc 100644 --- a/src/app/components/post-form/post-form.component.ts +++ b/src/app/components/post-form/post-form.component.ts @@ -112,7 +112,6 @@ export class PostFormComponent implements OnDestroy { ).subscribe({ next: (_) => { this.successMessage('Succès', 'Post mis à jour avec succès') - console.log(this.body); }, error: (err) => this.failureMessage('Erreur', err.message) }) @@ -130,7 +129,6 @@ export class PostFormComponent implements OnDestroy { ).subscribe({ next: () => { this.router.navigate(['/']).then(() => { - console.log(this.body); this.successMessage('Succès', 'Post créé avec succès') }); }, diff --git a/src/app/components/post-home/post-home.component.html b/src/app/components/post-home/post-home.component.html index ef426b9..c5613d0 100644 --- a/src/app/components/post-home/post-home.component.html +++ b/src/app/components/post-home/post-home.component.html @@ -7,11 +7,11 @@ {{ description }} - @if (authorProfilePicture !== "") { + @if (authorProfilePicture) { } @else { - + } {{ username }} diff --git a/src/app/components/register-form/register-form.component.html b/src/app/components/register-form/register-form.component.html index 7b922c4..6f9a137 100644 --- a/src/app/components/register-form/register-form.component.html +++ b/src/app/components/register-form/register-form.component.html @@ -8,7 +8,7 @@ Confirmez le mot de passe Rôle de l'utilisateur - diff --git a/src/app/components/register-form/register-form.component.ts b/src/app/components/register-form/register-form.component.ts index d00b576..6a62d22 100644 --- a/src/app/components/register-form/register-form.component.ts +++ b/src/app/components/register-form/register-form.component.ts @@ -1,5 +1,4 @@ -import {Component, Input, OnDestroy, OnInit} from '@angular/core'; -import {HeaderComponent} from '../header/header.component'; +import {Component, EventEmitter, Input, OnDestroy, Output} from '@angular/core'; import {Subscription} from 'rxjs'; import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms'; import {InputTextModule} from 'primeng/inputtext'; @@ -8,12 +7,13 @@ import {Button} from 'primeng/button'; import {AuthorService} from '../../services/author.service'; import {Router} from '@angular/router'; import {MessageService} from 'primeng/api'; +import {Author} from '../../models/author'; +import {AuthService} from '../../auth.service'; @Component({ selector: 'app-register-form', standalone: true, imports: [ - HeaderComponent, ReactiveFormsModule, InputTextModule, SelectButtonModule, @@ -25,6 +25,7 @@ import {MessageService} from 'primeng/api'; }) export class RegisterFormComponent implements OnDestroy { @Input() username: string = ""; + @Output() createdAuthor: EventEmitter = new EventEmitter(); @Input() password: string = ""; @Input() passwordConfirm: string = ""; @Input() role: string = "READER" @@ -35,17 +36,22 @@ export class RegisterFormComponent implements OnDestroy { ]; subs: Subscription[] = []; form: FormGroup; + actualAuthor: Author | undefined; constructor(private formBuilder: FormBuilder, private authorService: AuthorService, private router: Router, - private messageService: MessageService + private messageService: MessageService, + private authService: AuthService, ) { + if (!(this.authService.isSessionExpired()) && this.authService.isAuthenticated()) { + this.actualAuthor = this.authService.getAuthenticatedAuthor(); + } this.form = this.formBuilder.group({ username: ['', [Validators.required, Validators.maxLength(255)]], password: ['', [Validators.required, Validators.maxLength(50)]], passwordConfirm: ['', [Validators.required, Validators.maxLength(50)]], - role: [{value: 'READER', disabled: !this.adminForm}, [Validators.required, Validators.maxLength(10)]], + role: [{value: 'READER'}, [Validators.required, Validators.maxLength(10)]], }); } @@ -71,8 +77,20 @@ export class RegisterFormComponent implements OnDestroy { onSubmit() { if (this.form.valid && this.password === this.passwordConfirm) { - if (this.adminForm) { - this.authorService.createAccountAdmin(this.username, this.password, this.role); //TODO à finir + if (this.adminForm && this.actualAuthor) { + this.authorService.createAccountAdmin( + this.username, + this.password, + this.role, + this.authService.getAuthenticatedAuthorToken()).subscribe({ + next: (author: Author) => { + this.successMessage('Succès', `Auteur ${author.name} créé avec succès`); + this.createdAuthor.emit(author); + }, + error: (err) => { + this.failureMessage("Erreur", err.message); + } + }); } else { this.subs.push(this.authorService.createAccount(this.username, this.password).subscribe({ next: () => this.router.navigate(['/login']).then(() => this.successMessage('Succès', 'Utilisateur créé avec succès')), @@ -80,6 +98,8 @@ export class RegisterFormComponent implements OnDestroy { })); } + } else { + this.failureMessage('Erreur', 'Le formulaire n\'est pas complet ou les mot de passes ne correspondent pas'); } } diff --git a/src/app/pages/admin-authors/admin-authors.component.css b/src/app/pages/admin-authors/admin-authors.component.css index e69de29..f8a66a1 100644 --- a/src/app/pages/admin-authors/admin-authors.component.css +++ b/src/app/pages/admin-authors/admin-authors.component.css @@ -0,0 +1,7 @@ +.add-button { + display: flex; + justify-content: flex-end; + margin-top: 2rem; + margin-right: 2rem; + margin-bottom: 2rem; +} diff --git a/src/app/pages/admin-authors/admin-authors.component.html b/src/app/pages/admin-authors/admin-authors.component.html index 30f5b53..846d948 100644 --- a/src/app/pages/admin-authors/admin-authors.component.html +++ b/src/app/pages/admin-authors/admin-authors.component.html @@ -1,2 +1,61 @@ -admin-authors works! + + + + + + + + + + + + ID + Nom + Photo de profil + Role + + + + + + + {{ author.id }} + {{ author.name }} + + @if (author.profilePicture) { + + } @else { + + } + + {{ author.role }} + + + + + + + + + + + + + + + + + + + diff --git a/src/app/pages/admin-authors/admin-authors.component.ts b/src/app/pages/admin-authors/admin-authors.component.ts index e57e830..8ef8ec8 100644 --- a/src/app/pages/admin-authors/admin-authors.component.ts +++ b/src/app/pages/admin-authors/admin-authors.component.ts @@ -1,15 +1,88 @@ -import { Component } from '@angular/core'; +import {Component, OnDestroy} from '@angular/core'; import {HeaderComponent} from '../../components/header/header.component'; +import {TableModule} from 'primeng/table'; +import {AuthService} from '../../auth.service'; +import {AuthorService} from '../../services/author.service'; +import {Author} from '../../models/author'; +import {Subscription} from 'rxjs'; +import {MessageService} from 'primeng/api'; +import {AvatarModule} from 'primeng/avatar'; +import {Button} from 'primeng/button'; +import {DialogModule} from 'primeng/dialog'; +import {RegisterFormComponent} from '../../components/register-form/register-form.component'; @Component({ selector: 'app-admin-authors', standalone: true, imports: [ - HeaderComponent + HeaderComponent, + TableModule, + AvatarModule, + Button, + DialogModule, + RegisterFormComponent, ], templateUrl: './admin-authors.component.html', styleUrl: './admin-authors.component.css' }) -export class AdminAuthorsComponent { +export class AdminAuthorsComponent implements OnDestroy{ + authors: Author[] = []; + createAuthorDialogVisibility: boolean = false; + updateDialogVisibility: boolean[] = []; + deleteDialogVisibility: boolean[] = []; + subs: Subscription[] = []; + constructor(private authService: AuthService, + private authorService: AuthorService, + private messageService: MessageService) { + this.authorService.list().subscribe({ + next: (authors: Author[]) => { + this.authors = authors; + }, + error: (error: Error) => { + this.failureMessage("Erreur", error.message) + } + }) + } + + closeCreateAuthorDialog(author: Author): void { + this.authors.push(author); + this.createAuthorDialogVisibility = false; + } + + successMessage(summary: string, detail: string): void { + this.messageService.add({ + severity: 'success', + summary: summary, + detail: detail, + life: 3000, + closable: false + }); + } + + deleteAuthor(authorId: string, rowIndex: number): void { + + } + + openDialog(dialogBooleanTab: boolean[], index: number) { + dialogBooleanTab[index] = true; + } + + closeDialog(dialogBooleanTab: boolean[], index: number) { + dialogBooleanTab[index] = false; + } + + failureMessage(summary: string, detail: string): void { + this.messageService.add({ + severity: 'error', + summary: summary, + detail: detail, + life: 3000, + closable: false + }); + } + + ngOnDestroy(): void { + this.subs.forEach(sub => sub.unsubscribe()); + } } diff --git a/src/app/pages/home/home.component.html b/src/app/pages/home/home.component.html index 62715d8..b009070 100644 --- a/src/app/pages/home/home.component.html +++ b/src/app/pages/home/home.component.html @@ -16,4 +16,3 @@ Aucun post n'a été créé pour l'instant } - diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index dc183e8..7d72096 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -7,7 +7,6 @@ import {ToastModule} from 'primeng/toast'; import {PostService} from '../../services/post.service'; import {PostHomeComponent} from '../../components/post-home/post-home.component'; import {AuthorWithPost} from '../../models/author-with-post'; -import {FooterComponent} from '../../components/footer/footer.component'; import {AuthService} from '../../auth.service'; @Component({ @@ -18,7 +17,6 @@ import {AuthService} from '../../auth.service'; HeaderComponent, ToastModule, PostHomeComponent, - FooterComponent ], templateUrl: './home.component.html', styleUrl: './home.component.css' diff --git a/src/app/pages/login/login.component.html b/src/app/pages/login/login.component.html index 5211dd8..5cf79e8 100644 --- a/src/app/pages/login/login.component.html +++ b/src/app/pages/login/login.component.html @@ -17,4 +17,3 @@ /> - diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index f67d88f..6dc34bf 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -10,7 +10,6 @@ import {Subscription, switchMap} from 'rxjs'; import {CookieService} from 'ngx-cookie-service'; import {HeaderComponent} from '../../components/header/header.component'; import {Router} from '@angular/router'; -import {FooterComponent} from '../../components/footer/footer.component'; import {ConfigurationService} from '../../configuration.service'; import {DateTime} from 'luxon'; @@ -23,7 +22,6 @@ import {DateTime} from 'luxon'; Button, ToastModule, HeaderComponent, - FooterComponent ], templateUrl: './login.component.html', styleUrl: './login.component.css' diff --git a/src/app/pages/logout/logout.component.ts b/src/app/pages/logout/logout.component.ts index 19f422e..3d9fb28 100644 --- a/src/app/pages/logout/logout.component.ts +++ b/src/app/pages/logout/logout.component.ts @@ -21,8 +21,7 @@ export class LogoutComponent implements OnInit{ private router: Router, private configurationService: ConfigurationService,) { } ngOnInit(): void { - console.log(this.cookieService.getAll()) - const routes: string[] = ['/', '/login', '/register', '/logout', '/profile', '/post', '/new-post'] + const routes: string[] = ['/', '/login', '/register', '/logout', '/profile', '/post', '/new-post', '/admin'] Object.keys(this.cookieService.getAll()).forEach(key => { routes.forEach(route => { this.cookieService.delete(key, route, this.configurationService.getServerAddress()); diff --git a/src/app/pages/my-posts/my-posts.component.html b/src/app/pages/my-posts/my-posts.component.html index 9dc84d1..cde8d1f 100644 --- a/src/app/pages/my-posts/my-posts.component.html +++ b/src/app/pages/my-posts/my-posts.component.html @@ -66,4 +66,3 @@ - diff --git a/src/app/pages/my-posts/my-posts.component.ts b/src/app/pages/my-posts/my-posts.component.ts index 41e3091..94932cc 100644 --- a/src/app/pages/my-posts/my-posts.component.ts +++ b/src/app/pages/my-posts/my-posts.component.ts @@ -13,7 +13,6 @@ import {InputTextModule} from 'primeng/inputtext'; import {PostHomeComponent} from '../../components/post-home/post-home.component'; import {PostService} from '../../services/post.service'; import {PostFormComponent} from "../../components/post-form/post-form.component"; -import {FooterComponent} from '../../components/footer/footer.component'; import {AuthService} from '../../auth.service'; @Component({ @@ -28,7 +27,6 @@ import {AuthService} from '../../auth.service'; InputTextModule, PostHomeComponent, PostFormComponent, - FooterComponent ], templateUrl: './my-posts.component.html', styleUrl: './my-posts.component.css' diff --git a/src/app/pages/new-post/new-post.component.html b/src/app/pages/new-post/new-post.component.html index 5f9de72..affd9f4 100644 --- a/src/app/pages/new-post/new-post.component.html +++ b/src/app/pages/new-post/new-post.component.html @@ -1,3 +1,2 @@ - diff --git a/src/app/pages/new-post/new-post.component.ts b/src/app/pages/new-post/new-post.component.ts index 9f46dd2..e33a27a 100644 --- a/src/app/pages/new-post/new-post.component.ts +++ b/src/app/pages/new-post/new-post.component.ts @@ -12,7 +12,6 @@ import {AuthorService} from '../../services/author.service'; import {Author} from '../../models/author'; import {Router} from '@angular/router'; import {PostFormComponent} from '../../components/post-form/post-form.component'; -import {FooterComponent} from '../../components/footer/footer.component'; import {AuthService} from '../../auth.service'; @Component({ @@ -26,7 +25,6 @@ import {AuthService} from '../../auth.service'; FileUploadModule, EditorModule, PostFormComponent, - FooterComponent ], templateUrl: './new-post.component.html', styleUrl: './new-post.component.css' diff --git a/src/app/pages/post/post.component.html b/src/app/pages/post/post.component.html index 73b3f87..b1e6cf0 100644 --- a/src/app/pages/post/post.component.html +++ b/src/app/pages/post/post.component.html @@ -70,7 +70,6 @@ {{ comment.content }} } - } @else { Loading... } diff --git a/src/app/pages/post/post.component.ts b/src/app/pages/post/post.component.ts index 81fa62a..51610ab 100644 --- a/src/app/pages/post/post.component.ts +++ b/src/app/pages/post/post.component.ts @@ -13,7 +13,6 @@ import {CardModule} from 'primeng/card'; import {SafeHtmlPipe} from '../../pipes/safe-html-pipe'; import {Author} from '../../models/author'; import {CommentFormComponent} from '../../components/comment-form/comment-form.component'; -import {FooterComponent} from '../../components/footer/footer.component'; import {Button} from 'primeng/button'; import {DialogModule} from 'primeng/dialog'; import {AuthService} from '../../auth.service'; @@ -28,7 +27,6 @@ import {AuthService} from '../../auth.service'; CardModule, SafeHtmlPipe, CommentFormComponent, - FooterComponent, Button, DialogModule ], diff --git a/src/app/pages/profile/profile.component.html b/src/app/pages/profile/profile.component.html index ecdbf9d..cd066c9 100644 --- a/src/app/pages/profile/profile.component.html +++ b/src/app/pages/profile/profile.component.html @@ -32,4 +32,3 @@ } @else { Loading... } - diff --git a/src/app/pages/profile/profile.component.ts b/src/app/pages/profile/profile.component.ts index de4ac47..ad47caf 100644 --- a/src/app/pages/profile/profile.component.ts +++ b/src/app/pages/profile/profile.component.ts @@ -9,7 +9,6 @@ import {CardModule} from 'primeng/card'; import {Button} from 'primeng/button'; import {DialogModule} from 'primeng/dialog'; import {UpdateProfileFormComponent} from '../../components/update-profile-form/update-profile-form.component'; -import {FooterComponent} from '../../components/footer/footer.component'; import {AuthService} from '../../auth.service'; @Component({ @@ -22,7 +21,6 @@ import {AuthService} from '../../auth.service'; Button, DialogModule, UpdateProfileFormComponent, - FooterComponent ], templateUrl: './profile.component.html', styleUrl: './profile.component.css' diff --git a/src/app/pages/register/register.component.html b/src/app/pages/register/register.component.html index 341629b..fd6a941 100644 --- a/src/app/pages/register/register.component.html +++ b/src/app/pages/register/register.component.html @@ -1,3 +1,2 @@ - diff --git a/src/app/pages/register/register.component.ts b/src/app/pages/register/register.component.ts index 513f745..eac01c6 100644 --- a/src/app/pages/register/register.component.ts +++ b/src/app/pages/register/register.component.ts @@ -1,8 +1,6 @@ import { Component } from '@angular/core'; import {HeaderComponent} from '../../components/header/header.component'; import {RegisterFormComponent} from '../../components/register-form/register-form.component'; -import {Footer} from "primeng/api"; -import {FooterComponent} from '../../components/footer/footer.component'; @Component({ selector: 'app-register', @@ -10,8 +8,6 @@ import {FooterComponent} from '../../components/footer/footer.component'; imports: [ HeaderComponent, RegisterFormComponent, - Footer, - FooterComponent ], templateUrl: './register.component.html', styleUrl: './register.component.css' diff --git a/src/app/services/author.service.ts b/src/app/services/author.service.ts index b152a32..a594b7f 100644 --- a/src/app/services/author.service.ts +++ b/src/app/services/author.service.ts @@ -83,7 +83,12 @@ export class AuthorService { return this.httpClient.post(`${this.apiUrl}/register`, {name: username, password: password}) } - createAccountAdmin(username: string, password: string, role: string): Observable { - return this.httpClient.post(`${this.apiUrl}/register`, {name: username, password: password, role: role}) + createAccountAdmin(username: string, password: string, role: string, token: string): Observable { + const httpOptions = { + headers: new HttpHeaders({ + 'Authorization': `Bearer ${token}` + }) + } + return this.httpClient.post(`${this.apiUrl}/register/admin`, {name: username, password: password, role: role}, httpOptions); } } diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index a519adf..40e11f4 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -64,7 +64,6 @@ export class PostService { 'Authorization': `Bearer ${token}` }) }; - console.log(image); return this.httpClient.put(`${this.apiUrl}/${id}/illustration`, formData, httpOptions); } else { throw new Error('Image doesn\'t exist'); diff --git a/src/index.html b/src/index.html index f216df2..ac9c996 100644 --- a/src/index.html +++ b/src/index.html @@ -5,9 +5,19 @@ A BON ENTENDEUR - + +
admin-authors works!
{{ comment.content }}