diff --git a/src/app/admin-component/add-restau/add-restau.component.ts b/src/app/admin-component/add-restau/add-restau.component.ts index 586719a..d98ccbd 100644 --- a/src/app/admin-component/add-restau/add-restau.component.ts +++ b/src/app/admin-component/add-restau/add-restau.component.ts @@ -83,7 +83,6 @@ export class AddRestauComponent implements OnInit { restaurant.adresse !== '') { this.apiBackService.addRestaurant(restaurant).subscribe( resp => - this.router.navigate(['restaurants']) ); } else { diff --git a/src/app/admin-component/update-del-restau/update-del-restau.component.html b/src/app/admin-component/update-del-restau/update-del-restau.component.html index d18c0d9..4a65ea7 100644 --- a/src/app/admin-component/update-del-restau/update-del-restau.component.html +++ b/src/app/admin-component/update-del-restau/update-del-restau.component.html @@ -5,11 +5,9 @@
{{restau.nom}}
-
- -
+
\ No newline at end of file diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 644c2ab..c4fde3d 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -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 { FiltersPageComponent } from './pages/filters-page/filters-page.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 { AuthGuard } from './services/auth.guard'; const routes: Routes = [ { path: '', redirectTo: 'signin', pathMatch: 'full' }, {path: 'signin', component: SigninComponent}, + {path: 'signup', component: SignupComponent}, { path: 'home', component: HomePageComponent }, { path: 'categories', component: ListCategoriesComponent }, { path: 'favoris', component: FavorisUserComponent }, diff --git a/src/app/app.component.html b/src/app/app.component.html index 19dd0a6..0aa81f4 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -3,4 +3,4 @@ - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index be5ed0d..18917ec 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; import { ApiBackService } from './services/api-back.service'; +import { AuthGuard } from './services/auth.guard'; @Component({ selector: 'app-root', @@ -11,7 +12,7 @@ export class AppComponent { title = 'simpleat'; 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=>{ //console.log(e); if(e instanceof NavigationEnd){ @@ -26,6 +27,7 @@ export class AppComponent { } - ngOnInit(): void { } + ngOnInit(): void {} + } + -} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6d701ea..895593a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -24,6 +24,7 @@ import { UpdateDelRestauComponent } from './admin-component/update-del-restau/up import { HeaderLogoComponent } from './header/components/header-logo/header-logo.component'; import { AuthInterceptor } from './services/auth.interceptor'; import { FavorisUserComponent } from './pages/favoris-user/favoris-user.component'; +import { SignupComponent } from './pages/signup/signup.component'; @NgModule({ declarations: [ @@ -46,7 +47,8 @@ import { FavorisUserComponent } from './pages/favoris-user/favoris-user.componen AddRestauComponent, UpdateDelRestauComponent, HeaderLogoComponent, - FavorisUserComponent + FavorisUserComponent, + SignupComponent ], imports: [ BrowserModule, diff --git a/src/app/pages/admin-page/admin-page.component.html b/src/app/pages/admin-page/admin-page.component.html index fd8ef34..32d34ce 100644 --- a/src/app/pages/admin-page/admin-page.component.html +++ b/src/app/pages/admin-page/admin-page.component.html @@ -1,9 +1,16 @@
-
- -
+
+
+ +
+ + +
+ +
-
\ No newline at end of file +
+ diff --git a/src/app/pages/admin-page/admin-page.component.scss b/src/app/pages/admin-page/admin-page.component.scss index 8e1cebc..e69de29 100644 --- a/src/app/pages/admin-page/admin-page.component.scss +++ b/src/app/pages/admin-page/admin-page.component.scss @@ -1,3 +0,0 @@ -.search-bar{ - width : 30%; -} \ No newline at end of file diff --git a/src/app/pages/models/roleList.ts b/src/app/pages/models/roleList.ts new file mode 100644 index 0000000..4103504 --- /dev/null +++ b/src/app/pages/models/roleList.ts @@ -0,0 +1,5 @@ +export enum RoleList { + ROLE_ADMIN = 'ROLE_ADMIN', + ROLE_CREATOR = 'ROLE_CREATOR', + ROLE_READER = 'ROLE_READER' +} \ No newline at end of file diff --git a/src/app/pages/models/user.ts b/src/app/pages/models/user.ts index 340925f..9e2e971 100644 --- a/src/app/pages/models/user.ts +++ b/src/app/pages/models/user.ts @@ -1,3 +1,5 @@ +import { RoleList } from "./roleList"; + export interface User { id?:number; prenom: string; @@ -5,4 +7,5 @@ export interface User { email: string; password?: string; preference ?: object; + roleList ?: string[]; } diff --git a/src/app/pages/signup/signup.component.html b/src/app/pages/signup/signup.component.html new file mode 100644 index 0000000..0fd818a --- /dev/null +++ b/src/app/pages/signup/signup.component.html @@ -0,0 +1,71 @@ +
+
+
+

Inscription d'un membre

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ + + +
+
+
\ No newline at end of file diff --git a/src/app/pages/signup/signup.component.scss b/src/app/pages/signup/signup.component.scss new file mode 100644 index 0000000..d1c5dd4 --- /dev/null +++ b/src/app/pages/signup/signup.component.scss @@ -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; +} \ No newline at end of file diff --git a/src/app/pages/signup/signup.component.spec.ts b/src/app/pages/signup/signup.component.spec.ts new file mode 100644 index 0000000..2c39790 --- /dev/null +++ b/src/app/pages/signup/signup.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SignupComponent } from './signup.component'; + +describe('SignupComponent', () => { + let component: SignupComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ SignupComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(SignupComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/signup/signup.component.ts b/src/app/pages/signup/signup.component.ts new file mode 100644 index 0000000..6f9d703 --- /dev/null +++ b/src/app/pages/signup/signup.component.ts @@ -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 !"; + } + } + } + +} diff --git a/src/app/services/auth.guard.ts b/src/app/services/auth.guard.ts index 6510e1a..01e2700 100644 --- a/src/app/services/auth.guard.ts +++ b/src/app/services/auth.guard.ts @@ -31,6 +31,7 @@ export class AuthGuard implements CanActivate { const dateExp = new Date(decodedToken.exp * 1000); if(new Date() >= dateExp) { // le token a expiré, je n'autorise pas l'accès + this.tokenService.destroyToken(this.tokenKey); this.router.navigate(['signin']); return false; } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 04827d4..2d9b681 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - apiUrl: "http://localhost:8081", + apiUrl: "http://localhost:8080", tokenKey: "TOKEN-SIMPLEAT" };