Ajout d'un membre
This commit is contained in:
		
							parent
							
								
									802fe74a29
								
							
						
					
					
						commit
						b771677562
					
				
					 16 changed files with 229 additions and 17 deletions
				
			
		|  | @ -83,7 +83,6 @@ export class AddRestauComponent implements OnInit { | ||||||
|       restaurant.adresse !== '') { |       restaurant.adresse !== '') { | ||||||
|       this.apiBackService.addRestaurant(restaurant).subscribe( |       this.apiBackService.addRestaurant(restaurant).subscribe( | ||||||
|         resp => |         resp => | ||||||
| 
 |  | ||||||
|           this.router.navigate(['restaurants']) |           this.router.navigate(['restaurants']) | ||||||
|       ); |       ); | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  | @ -5,11 +5,9 @@ | ||||||
|         <div> |         <div> | ||||||
|         {{restau.nom}} |         {{restau.nom}} | ||||||
|     </div> |     </div> | ||||||
|     <div> |  | ||||||
|         <button class="btn btn-danger" type="button" (click)="deleteRestau(restau.id)"><i class="bi bi-trash"></i></button> |  | ||||||
|     </div> |  | ||||||
|     <div> |     <div> | ||||||
|         <button class="btn btn-warn" type="button" (click)="modifRestau(restau.id)"><i class="bi bi-gear"></i></button> |         <button class="btn btn-warn" type="button" (click)="modifRestau(restau.id)"><i class="bi bi-gear"></i></button> | ||||||
|  |         <button class="btn btn-danger" type="button" (click)="deleteRestau(restau.id)"><i class="bi bi-trash"></i></button> | ||||||
|     </div> |     </div> | ||||||
|     </li> |     </li> | ||||||
| </ul> | </ul> | ||||||
|  | @ -7,12 +7,14 @@ import { RestoPageComponent } from './pages/resto-page/resto-page.component'; | ||||||
| import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component'; | import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component'; | ||||||
| import { FiltersPageComponent } from './pages/filters-page/filters-page.component'; | import { FiltersPageComponent } from './pages/filters-page/filters-page.component'; | ||||||
| import { SigninComponent } from './pages/signin/signin.component'; | import { SigninComponent } from './pages/signin/signin.component'; | ||||||
|  | import { SignupComponent } from './pages/signup/signup.component'; | ||||||
| import { AdminPageComponent } from './pages/admin-page/admin-page.component'; | import { AdminPageComponent } from './pages/admin-page/admin-page.component'; | ||||||
| import { AuthGuard } from './services/auth.guard'; | import { AuthGuard } from './services/auth.guard'; | ||||||
| 
 | 
 | ||||||
| const routes: Routes = [ | const routes: Routes = [ | ||||||
|     { path: '', redirectTo: 'signin', pathMatch: 'full' }, |     { path: '', redirectTo: 'signin', pathMatch: 'full' }, | ||||||
|     {path: 'signin', component: SigninComponent}, |     {path: 'signin', component: SigninComponent}, | ||||||
|  |     {path: 'signup', component: SignupComponent}, | ||||||
|     { path: 'home', component: HomePageComponent }, |     { path: 'home', component: HomePageComponent }, | ||||||
|     { path: 'categories', component: ListCategoriesComponent }, |     { path: 'categories', component: ListCategoriesComponent }, | ||||||
|     { path: 'favoris', component: FavorisUserComponent }, |     { path: 'favoris', component: FavorisUserComponent }, | ||||||
|  |  | ||||||
|  | @ -3,4 +3,4 @@ | ||||||
| <app-header-logo *ngIf="router.url != '/signin'"></app-header-logo> | <app-header-logo *ngIf="router.url != '/signin'"></app-header-logo> | ||||||
| <app-nav-bar *ngIf="router.url != '/signin'"></app-nav-bar> | <app-nav-bar *ngIf="router.url != '/signin'"></app-nav-bar> | ||||||
| <router-outlet></router-outlet> | <router-outlet></router-outlet> | ||||||
| <!-- <app-footer *ngIf="router.url != '/signin'"></app-footer> --> | <app-footer *ngIf="router.url != '/signin'"></app-footer> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| import { Component } from '@angular/core'; | import { Component } from '@angular/core'; | ||||||
| import { NavigationEnd, Router } from '@angular/router'; | import { NavigationEnd, Router } from '@angular/router'; | ||||||
| import { ApiBackService } from './services/api-back.service'; | import { ApiBackService } from './services/api-back.service'; | ||||||
|  | import { AuthGuard } from './services/auth.guard'; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'app-root', |   selector: 'app-root', | ||||||
|  | @ -11,7 +12,7 @@ export class AppComponent { | ||||||
|   title = 'simpleat'; |   title = 'simpleat'; | ||||||
|   dontShow: boolean = false; |   dontShow: boolean = false; | ||||||
| 
 | 
 | ||||||
|   constructor(public router:Router, private apiBackService : ApiBackService){ |   constructor(public router:Router, private apiBackService : ApiBackService, private authgard : AuthGuard){ | ||||||
|     this.router.events.subscribe(e=>{ |     this.router.events.subscribe(e=>{ | ||||||
|       //console.log(e);
 |       //console.log(e);
 | ||||||
|       if(e instanceof NavigationEnd){ |       if(e instanceof NavigationEnd){ | ||||||
|  | @ -26,6 +27,7 @@ export class AppComponent { | ||||||
|    |    | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|   ngOnInit(): void { } |   ngOnInit(): void {} | ||||||
|  |    } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -24,6 +24,7 @@ import { UpdateDelRestauComponent } from './admin-component/update-del-restau/up | ||||||
| import { HeaderLogoComponent } from './header/components/header-logo/header-logo.component'; | import { HeaderLogoComponent } from './header/components/header-logo/header-logo.component'; | ||||||
| import { AuthInterceptor } from './services/auth.interceptor'; | import { AuthInterceptor } from './services/auth.interceptor'; | ||||||
| import { FavorisUserComponent } from './pages/favoris-user/favoris-user.component'; | import { FavorisUserComponent } from './pages/favoris-user/favoris-user.component'; | ||||||
|  | import { SignupComponent } from './pages/signup/signup.component'; | ||||||
| 
 | 
 | ||||||
| @NgModule({ | @NgModule({ | ||||||
|   declarations: [ |   declarations: [ | ||||||
|  | @ -46,7 +47,8 @@ import { FavorisUserComponent } from './pages/favoris-user/favoris-user.componen | ||||||
|     AddRestauComponent, |     AddRestauComponent, | ||||||
|     UpdateDelRestauComponent, |     UpdateDelRestauComponent, | ||||||
|     HeaderLogoComponent, |     HeaderLogoComponent, | ||||||
|     FavorisUserComponent |     FavorisUserComponent, | ||||||
|  |     SignupComponent | ||||||
|   ], |   ], | ||||||
|   imports: [ |   imports: [ | ||||||
|     BrowserModule, |     BrowserModule, | ||||||
|  |  | ||||||
|  | @ -1,9 +1,16 @@ | ||||||
| <div class="container"> | <div class="container"> | ||||||
|     <div class="d-flex flex-row justify-content-around"><div> |     <div class="d-flex flex-wrap justify-content-around"> | ||||||
|  |         <div> | ||||||
|             <app-add-restau ></app-add-restau> |             <app-add-restau ></app-add-restau> | ||||||
|         </div> |         </div> | ||||||
|  | 
 | ||||||
|         <div class="search-bar"> |         <div class="search-bar"> | ||||||
|             <app-update-del-restau ></app-update-del-restau> |             <app-update-del-restau ></app-update-del-restau> | ||||||
|         </div> |         </div> | ||||||
|  | 
 | ||||||
|  |         <div> | ||||||
|  |             <app-signup></app-signup> | ||||||
|  |         </div> | ||||||
|     </div> |     </div> | ||||||
| </div> | </div> | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -1,3 +0,0 @@ | ||||||
| .search-bar{ |  | ||||||
|     width : 30%; |  | ||||||
| } |  | ||||||
							
								
								
									
										5
									
								
								src/app/pages/models/roleList.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/app/pages/models/roleList.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | export enum RoleList { | ||||||
|  |     ROLE_ADMIN = 'ROLE_ADMIN', | ||||||
|  |     ROLE_CREATOR = 'ROLE_CREATOR', | ||||||
|  |     ROLE_READER = 'ROLE_READER' | ||||||
|  | } | ||||||
|  | @ -1,3 +1,5 @@ | ||||||
|  | import { RoleList } from "./roleList"; | ||||||
|  | 
 | ||||||
| export interface User {    | export interface User {    | ||||||
|     id?:number; |     id?:number; | ||||||
|     prenom: string; |     prenom: string; | ||||||
|  | @ -5,4 +7,5 @@ export interface User { | ||||||
|     email: string; |     email: string; | ||||||
|     password?: string; |     password?: string; | ||||||
|     preference ?: object; |     preference ?: object; | ||||||
|  |     roleList ?: string[]; | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										71
									
								
								src/app/pages/signup/signup.component.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								src/app/pages/signup/signup.component.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,71 @@ | ||||||
|  | <div class="signup-form text-center"> | ||||||
|  |     <main class="form-signup"> | ||||||
|  |         <form  (ngSubmit)="onSubmit()" [formGroup]="signupForm"> | ||||||
|  |             <h1>Inscription d'un membre</h1> | ||||||
|  |             <div class="form-floating"> | ||||||
|  |                 <input type="text"  | ||||||
|  |                         class="form-control"  | ||||||
|  |                         id="floatingInputfirstName"  | ||||||
|  |                         placeholder=""  | ||||||
|  |                         name="firstName"  | ||||||
|  |                         formControlName="firstNameFc" | ||||||
|  |                         [ngClass]="{'is-valid' : signupForm.controls['firstNameFc'].touched && signupForm.controls['firstNameFc'].valid,  | ||||||
|  |                                     'is-invalid':  signupForm.controls['firstNameFc'].touched && !signupForm.controls['firstNameFc'].valid}"> | ||||||
|  |                 <label for="floatingInputfirstName">Prénom</label> | ||||||
|  |             </div> | ||||||
|  |             <div class="form-floating"> | ||||||
|  |                 <input type="text"  | ||||||
|  |                         class="form-control"  | ||||||
|  |                         id="floatingInputlastName"  | ||||||
|  |                         placeholder=""  | ||||||
|  |                         name="lastName"  | ||||||
|  |                         formControlName="lastNameFc" | ||||||
|  |                         [ngClass]="{'is-valid' : signupForm.controls['lastNameFc'].touched && signupForm.controls['lastNameFc'].valid,  | ||||||
|  |                                     'is-invalid':  signupForm.controls['lastNameFc'].touched && !signupForm.controls['lastNameFc'].valid}"> | ||||||
|  |                 <label for="floatingInputlastName">Nom</label> | ||||||
|  |             </div> | ||||||
|  |             <div class="form-floating"> | ||||||
|  |                 <input type="email"  | ||||||
|  |                         class="form-control"  | ||||||
|  |                         id="floatingInput"  | ||||||
|  |                         placeholder=""  | ||||||
|  |                         name="email"  | ||||||
|  |                         formControlName="emailFc" | ||||||
|  |                         [ngClass]="{'is-valid' : signupForm.controls['emailFc'].touched && signupForm.controls['emailFc'].valid,  | ||||||
|  |                                     'is-invalid':  signupForm.controls['emailFc'].touched && !signupForm.controls['emailFc'].valid}"> | ||||||
|  |                 <label for="floatingInput">Adresse email **</label> | ||||||
|  |             </div> | ||||||
|  |             <div class="form-floating"> | ||||||
|  |                 <input type="password"  | ||||||
|  |                         class="form-control"  | ||||||
|  |                         id="floatingPassword"  | ||||||
|  |                         placeholder=""  | ||||||
|  |                         name="password"  | ||||||
|  |                         formControlName="passwordFc" | ||||||
|  |                         [ngClass]="{'is-valid' : signupForm.controls['passwordFc'].touched && signupForm.controls['passwordFc'].valid,  | ||||||
|  |                                     'is-invalid':  signupForm.controls['passwordFc'].touched && !signupForm.controls['passwordFc'].valid}"> | ||||||
|  |                 <label for="floatingPassword">Mot de passe **</label> | ||||||
|  |             </div> | ||||||
|  | 
 | ||||||
|  |             <div class="form-floating"> | ||||||
|  |             <select class="form-select" id="roleList" formControlName="roleFc"> | ||||||
|  |                 <option *ngFor="let c of roleList | keyvalue" value={{c.value}}>{{c.value}}</option> | ||||||
|  |             </select> | ||||||
|  |             <label for="roleList">Selectionner un rôle **</label> | ||||||
|  |             </div> | ||||||
|  | 
 | ||||||
|  |             <div *ngIf="alertMessage" class="alert alert-danger"> | ||||||
|  |                 <p class="alert-link">{{alertMessage}}</p> | ||||||
|  |             </div> | ||||||
|  |              | ||||||
|  |             <div *ngIf="successMessage" class="alert alert-success"> | ||||||
|  |                 <p class="alert-link">{{successMessage}}</p> | ||||||
|  |             </div> | ||||||
|  | 
 | ||||||
|  |             <button class="w-100 btn btn-lg btn-success"  | ||||||
|  |                     type="submit"  | ||||||
|  |                     [disabled]="signupForm.invalid">Inscription</button> | ||||||
|  | 
 | ||||||
|  |         </form> | ||||||
|  |     </main> | ||||||
|  | </div> | ||||||
							
								
								
									
										31
									
								
								src/app/pages/signup/signup.component.scss
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/app/pages/signup/signup.component.scss
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,31 @@ | ||||||
|  | .signup-form { | ||||||
|  |     height: 100vh; | ||||||
|  |     padding-top: 40px; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .form-signup { | ||||||
|  |     width: 100%; | ||||||
|  |     max-width: 330px; | ||||||
|  |     padding: 15px; | ||||||
|  |     margin: auto; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .form-signup .checkbox { | ||||||
|  |     font-weight: 400; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .form-signup .form-floating:focus-within { | ||||||
|  |     z-index: 2; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .form-signup input[type="email"] { | ||||||
|  |     margin-bottom: -1px; | ||||||
|  |     border-bottom-right-radius: 0; | ||||||
|  |     border-bottom-left-radius: 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .form-signup input[type="password"] { | ||||||
|  |     margin-bottom: 10px; | ||||||
|  |     border-top-left-radius: 0; | ||||||
|  |     border-top-right-radius: 0; | ||||||
|  | } | ||||||
							
								
								
									
										25
									
								
								src/app/pages/signup/signup.component.spec.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/app/pages/signup/signup.component.spec.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | ||||||
|  | import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||
|  | 
 | ||||||
|  | import { SignupComponent } from './signup.component'; | ||||||
|  | 
 | ||||||
|  | describe('SignupComponent', () => { | ||||||
|  |   let component: SignupComponent; | ||||||
|  |   let fixture: ComponentFixture<SignupComponent>; | ||||||
|  | 
 | ||||||
|  |   beforeEach(async () => { | ||||||
|  |     await TestBed.configureTestingModule({ | ||||||
|  |       declarations: [ SignupComponent ] | ||||||
|  |     }) | ||||||
|  |     .compileComponents(); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   beforeEach(() => { | ||||||
|  |     fixture = TestBed.createComponent(SignupComponent); | ||||||
|  |     component = fixture.componentInstance; | ||||||
|  |     fixture.detectChanges(); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('should create', () => { | ||||||
|  |     expect(component).toBeTruthy(); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										69
									
								
								src/app/pages/signup/signup.component.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								src/app/pages/signup/signup.component.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,69 @@ | ||||||
|  | import { Component, OnInit } from '@angular/core'; | ||||||
|  | import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||||||
|  | import { Router } from '@angular/router'; | ||||||
|  | import { AuthService } from 'src/app/services/auth.service'; | ||||||
|  | import { RoleList } from '../models/roleList'; | ||||||
|  | import { User } from '../models/user'; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-signup', | ||||||
|  |   templateUrl: './signup.component.html', | ||||||
|  |   styleUrls: ['./signup.component.scss'] | ||||||
|  | }) | ||||||
|  | export class SignupComponent implements OnInit { | ||||||
|  |   public signupForm: FormGroup; | ||||||
|  |   public roleList: typeof RoleList; | ||||||
|  |   public alertMessage?: string; | ||||||
|  |   public successMessage?: string; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   constructor(private authService: AuthService, private router: Router) {  | ||||||
|  |     this.signupForm = new FormGroup({}); | ||||||
|  |     this.roleList = RoleList; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   ngOnInit(): void { | ||||||
|  |     // FormGroupe => Group de champs de saisie (notre objet)
 | ||||||
|  |     // FormControl => Les champs de saisie (nos propriétés)
 | ||||||
|  |     this.signupForm = new FormGroup({ | ||||||
|  |       firstNameFc : new FormControl(''), | ||||||
|  |       lastNameFc : new FormControl(''), | ||||||
|  |       emailFc : new FormControl('', [Validators.email, Validators.required, Validators.pattern(/^([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}/igm)]), // chercher une meilleure regex
 | ||||||
|  |       passwordFc : new FormControl('', [Validators.minLength(8), Validators.required]), | ||||||
|  |       roleFc : new FormControl('') | ||||||
|  |     }) | ||||||
|  | 
 | ||||||
|  |     console.log(this.roleList); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public onSubmit(): void { | ||||||
|  |    | ||||||
|  |     if(confirm("Êtes-vous sur d'ajouter ce membre ?")){ | ||||||
|  | 
 | ||||||
|  |     const firstNameValue = this.signupForm.value['firstNameFc']; | ||||||
|  |     const lastNameValue = this.signupForm.value['lastNameFc']; | ||||||
|  |     const emailValue = this.signupForm.value['emailFc']; | ||||||
|  |     const passwordValue = this.signupForm.value['passwordFc']; | ||||||
|  |     const roleValue = this.signupForm.value['roleFc']; | ||||||
|  |      | ||||||
|  |     const user: User = { | ||||||
|  |       prenom: firstNameValue, | ||||||
|  |       nom: lastNameValue, | ||||||
|  |       email: emailValue, | ||||||
|  |       password: passwordValue, | ||||||
|  |       roleList : [roleValue] | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if(user.email !== '' && user.password !== '') { | ||||||
|  |       this.authService.signup(user).subscribe( | ||||||
|  |         resp => { | ||||||
|  |           this.successMessage = "Membre ajouté !"; | ||||||
|  |         } | ||||||
|  |       ) | ||||||
|  |     } else { | ||||||
|  |       this.alertMessage = "Erreur d'ajout !"; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  | } | ||||||
|  | @ -31,6 +31,7 @@ export class AuthGuard implements CanActivate { | ||||||
|           const dateExp = new Date(decodedToken.exp * 1000); |           const dateExp = new Date(decodedToken.exp * 1000); | ||||||
|           if(new Date() >= dateExp) { |           if(new Date() >= dateExp) { | ||||||
|             // le token a expiré, je n'autorise pas l'accès
 |             // le token a expiré, je n'autorise pas l'accès
 | ||||||
|  |             this.tokenService.destroyToken(this.tokenKey); | ||||||
|             this.router.navigate(['signin']); |             this.router.navigate(['signin']); | ||||||
|             return false; |             return false; | ||||||
|           } |           } | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ | ||||||
| 
 | 
 | ||||||
| export const environment = { | export const environment = { | ||||||
|   production: false, |   production: false, | ||||||
|   apiUrl: "http://localhost:8081", |   apiUrl: "http://localhost:8080", | ||||||
|   tokenKey: "TOKEN-SIMPLEAT" |   tokenKey: "TOKEN-SIMPLEAT" | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Romain Verger
						Romain Verger