début add Member
This commit is contained in:
parent
8d5cd03d33
commit
5904f64103
|
@ -1,10 +1,10 @@
|
||||||
export interface Membre {
|
export interface Membre {
|
||||||
firstName: string;
|
nom: string;
|
||||||
lastName: string;
|
prenom: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
dateNaissance: Date;
|
dateNaissance: Date;
|
||||||
teamName: string;
|
|
||||||
profil: boolean;
|
profil: boolean;
|
||||||
|
roleList: string[];
|
||||||
passwordConfirm: string;
|
passwordConfirm: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,109 @@
|
||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
|
<app-side-bar></app-side-bar>
|
||||||
|
<div class="signup-form text-center">
|
||||||
|
<main class="form-signup">
|
||||||
|
<form (ngSubmit)="onSubmit()" [formGroup]="addMemberForm">
|
||||||
|
<h1>J'inscris un nouveau membre</h1>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputlastName"
|
||||||
|
placeholder=""
|
||||||
|
name="lastName"
|
||||||
|
formControlName="lastNameFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['lastNameFc'].touched && addMemberForm.controls['lastNameFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['lastNameFc'].touched && !addMemberForm.controls['lastNameFc'].valid}">
|
||||||
|
<label for="floatingInputlastName">Avatar</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputlastName"
|
||||||
|
placeholder=""
|
||||||
|
name="lastName"
|
||||||
|
formControlName="lastNameFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['lastNameFc'].touched && addMemberForm.controls['lastNameFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['lastNameFc'].touched && !addMemberForm.controls['lastNameFc'].valid}">
|
||||||
|
<label for="floatingInputlastName">Nom</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputfirstName"
|
||||||
|
placeholder=""
|
||||||
|
name="firstName"
|
||||||
|
formControlName="firstNameFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['firstNameFc'].touched && addMemberForm.controls['firstNameFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['firstNameFc'].touched && !addMemberForm.controls['firstNameFc'].valid}">
|
||||||
|
<label for="floatingInputfirstName">Prénom</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="date"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputdateNaissance"
|
||||||
|
placeholder=""
|
||||||
|
name="dateNaissance"
|
||||||
|
formControlName="dateNaissanceFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['dateNaissanceFc'].touched && addMemberForm.controls['dateNaissanceFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['dateNaissanceFc'].touched && !addMemberForm.controls['dateNaissanceFc'].valid}">
|
||||||
|
<label for="floatingInputfirstName">Date de naissance</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<select type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputprofil"
|
||||||
|
name="profil"
|
||||||
|
formControlName="profilFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['profilFc'].touched && addMemberForm.controls['profilFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['profilFc'].touched && !addMemberForm.controls['profilFc'].valid}">
|
||||||
|
<option>Adulte</option>
|
||||||
|
<option>Enfant</option>
|
||||||
|
</select>
|
||||||
|
<label for="floatingInputfirstName">Profil</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="email"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInput"
|
||||||
|
placeholder=""
|
||||||
|
name="email"
|
||||||
|
formControlName="emailFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['emailFc'].touched && addMemberForm.controls['emailFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['emailFc'].touched && !addMemberForm.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' : addMemberForm.controls['passwordFc'].touched && addMemberForm.controls['passwordFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['passwordFc'].touched && !addMemberForm.controls['passwordFc'].valid}">
|
||||||
|
<label for="floatingPassword">Mot de passe</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="passwordConfirm"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingpasswordConfirm"
|
||||||
|
placeholder=""
|
||||||
|
name="passwordConfirm"
|
||||||
|
formControlName="passwordConfirmFc"
|
||||||
|
[ngClass]="{'is-valid' : addMemberForm.controls['passwordConfirmFc'].touched && addMemberForm.controls['passwordConfirmFc'].valid,
|
||||||
|
'is-invalid': addMemberForm.controls['passwordConfirmFc'].touched && !addMemberForm.controls['passwordConfirmFc'].valid}">
|
||||||
|
<label for="floatingPassword">Confirmer mot de passe</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="w-100 btn btn-lg btn-success"
|
||||||
|
type="submit"
|
||||||
|
[disabled]="addMemberForm.invalid">Je confirme l'ajout de ce membre à ma team !</button>
|
||||||
|
<p>
|
||||||
|
Value : {{ addMemberForm.value | json }}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Form valid : {{ addMemberForm.valid }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
.login-form {
|
||||||
|
height: 100vh;
|
||||||
|
padding-top: 40px;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
|
@ -1,4 +1,8 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { Membre } from 'src/app/models/membre';
|
||||||
|
import { AuthService } from 'src/app/services/auth.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-page-add-member',
|
selector: 'app-page-add-member',
|
||||||
|
@ -7,9 +11,92 @@ import { Component, OnInit } from '@angular/core';
|
||||||
})
|
})
|
||||||
export class PageAddMemberComponent implements OnInit {
|
export class PageAddMemberComponent implements OnInit {
|
||||||
|
|
||||||
constructor() { }
|
public addMemberForm: FormGroup;
|
||||||
|
constructor(
|
||||||
|
private authService: AuthService,
|
||||||
|
private router: Router,
|
||||||
|
private fb: FormBuilder
|
||||||
|
) {
|
||||||
|
this.addMemberForm = new FormGroup({});
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
// *********************************pensser a changer group car déprécié********************************
|
||||||
|
this.addMemberForm = this.fb.group(
|
||||||
|
{
|
||||||
|
firstNameFc: new FormControl('', [Validators.required]),
|
||||||
|
lastNameFc: new FormControl('', [Validators.required]),
|
||||||
|
dateNaissanceFc: new FormControl('', [Validators.required]),
|
||||||
|
profilFc: new FormControl('', [Validators.required]),
|
||||||
|
emailFc: new FormControl('', [
|
||||||
|
Validators.email,
|
||||||
|
Validators.required,
|
||||||
|
Validators.pattern(/^([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}/gim),
|
||||||
|
]), // chercher une meilleure regex
|
||||||
|
passwordFc: new FormControl('', [
|
||||||
|
Validators.minLength(8),
|
||||||
|
Validators.required,
|
||||||
|
]),
|
||||||
|
passwordConfirmFc: new FormControl('', [
|
||||||
|
Validators.minLength(8),
|
||||||
|
Validators.required,
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
validator: this.ConfirmedValidator('passwordFc', 'passwordConfirmFc'),
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onSubmit(): void {
|
||||||
|
console.log('value : ', this.addMemberForm.value);
|
||||||
|
console.log('form : ', this.addMemberForm);
|
||||||
|
const firstNameValue = this.addMemberForm.value['firstNameFc'];
|
||||||
|
const lastNameValue = this.addMemberForm.value['lastNameFc'];
|
||||||
|
const emailValue = this.addMemberForm.value['emailFc'];
|
||||||
|
const passwordValue = this.addMemberForm.value['passwordFc'];
|
||||||
|
const dateNaissanceValue = this.addMemberForm.value['dateNaissanceFc'];
|
||||||
|
const teamNameValue = this.addMemberForm.value['teamNameFc'];
|
||||||
|
const profilValue = this.addMemberForm.value['profilFc'];
|
||||||
|
const passwordConfirmValue = this.addMemberForm.value['passwordConfirmFc'];
|
||||||
|
const teamValue = [''];
|
||||||
|
|
||||||
|
const membre: Membre = {
|
||||||
|
nom: firstNameValue,
|
||||||
|
prenom: lastNameValue,
|
||||||
|
email: emailValue,
|
||||||
|
password: passwordValue,
|
||||||
|
dateNaissance: dateNaissanceValue,
|
||||||
|
profil: profilValue,
|
||||||
|
passwordConfirm: passwordConfirmValue,
|
||||||
|
roleList: ["ROLE_PARENT"]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (membre.email !== '' && membre.password !== '') {
|
||||||
|
this.authService.signup(membre).subscribe((resp) => {
|
||||||
|
this.router.navigate(['account/signin']);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// affichage erreur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfirmedValidator(controlName: string, matchingControlName: string) {
|
||||||
|
return (formGroup: FormGroup) => {
|
||||||
|
const control = formGroup.controls[controlName];
|
||||||
|
const matchingControl = formGroup.controls[matchingControlName];
|
||||||
|
if (
|
||||||
|
matchingControl.errors &&
|
||||||
|
!matchingControl.errors['confirmedValidator']
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (control.value !== matchingControl.value) {
|
||||||
|
matchingControl.setErrors({ confirmedValidator: true });
|
||||||
|
} else {
|
||||||
|
matchingControl.setErrors(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export class PageSignupComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// *********************************pensser a changer group car déprécié********************************
|
// *********************************penser a changer group car déprécié********************************
|
||||||
this.signupForm = this.fb.group(
|
this.signupForm = this.fb.group(
|
||||||
{
|
{
|
||||||
firstNameFc: new FormControl('', [Validators.required]),
|
firstNameFc: new FormControl('', [Validators.required]),
|
||||||
|
@ -64,21 +64,22 @@ export class PageSignupComponent implements OnInit {
|
||||||
const teamNameValue = this.signupForm.value['teamNameFc'];
|
const teamNameValue = this.signupForm.value['teamNameFc'];
|
||||||
const profilValue = this.signupForm.value['profilFc'];
|
const profilValue = this.signupForm.value['profilFc'];
|
||||||
const passwordConfirmValue = this.signupForm.value['passwordConfirmFc'];
|
const passwordConfirmValue = this.signupForm.value['passwordConfirmFc'];
|
||||||
|
const teamValue = '';
|
||||||
|
|
||||||
const membre: Membre = {
|
const membre: Membre = {
|
||||||
firstName: firstNameValue,
|
nom: firstNameValue,
|
||||||
lastName: lastNameValue,
|
prenom: lastNameValue,
|
||||||
email: emailValue,
|
email: emailValue,
|
||||||
password: passwordValue,
|
password: passwordValue,
|
||||||
dateNaissance: dateNaissanceValue,
|
dateNaissance: dateNaissanceValue,
|
||||||
teamName: teamNameValue,
|
|
||||||
profil: profilValue,
|
profil: profilValue,
|
||||||
passwordConfirm: passwordConfirmValue,
|
passwordConfirm: passwordConfirmValue,
|
||||||
|
roleList: ["ROLE_PARENT"]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (membre.email !== '' && membre.password !== '') {
|
if (membre.email !== '' && membre.password !== '') {
|
||||||
this.authService.signup(membre).subscribe((resp) => {
|
this.authService.signup(membre).subscribe((resp) => {
|
||||||
this.router.navigate(['account/signin']);
|
this.router.navigate(['accueil']);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// affichage erreur
|
// affichage erreur
|
||||||
|
|
|
@ -20,7 +20,7 @@ export class AuthService {
|
||||||
signup(membre: Membre): Observable<any> {
|
signup(membre: Membre): Observable<any> {
|
||||||
console.log(membre);
|
console.log(membre);
|
||||||
|
|
||||||
return this.http.post(`${this.apiUrl}/creation-compte`, membre);
|
return this.http.post(`${this.apiUrl}/membres/sign-up`, membre);
|
||||||
}
|
}
|
||||||
|
|
||||||
signin(email: string, password: string): Observable<any> {
|
signin(email: string, password: string): Observable<any> {
|
||||||
|
@ -55,4 +55,11 @@ export class AuthService {
|
||||||
|
|
||||||
return this.http.post(`${this.apiUrl}/forgot-psw`, body);
|
return this.http.post(`${this.apiUrl}/forgot-psw`, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addMember(membre: Membre): Observable<any> {
|
||||||
|
console.log(membre);
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/tableau-de-bord`, membre);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
apiUrl: 'http://localhost:3306',
|
apiUrl: 'http://localhost:8088',
|
||||||
tokenKey: 'TOKEN-ORGANIZEE',
|
tokenKey: 'TOKEN-ORGANIZEE',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue