From 6cfa4b90aa533afd27ac071a0c347c247776b98c Mon Sep 17 00:00:00 2001 From: Secteur Geek <oser.geek@gmail.com> Date: Fri, 29 Jan 2021 17:46:38 +0100 Subject: [PATCH] Testbranch (#66) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Oser to OSER (#55) * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * fix Oser to OSER * Validated signup file display (#57) * Modify inscription page (#32) * modify the order of blocks * Update dependencies and TravisCI build (#33) * Update dependencies via a clean npm install * Use Node.js 10 in Travis CI * Specify node==10.x for Heroku * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * adds untested frontend support for showing validated status of signup file * adds phone number validation for personnal data * checks for year field in registration to display correct status Co-authored-by: AurianeStrasser2 <32937502+AurianeStrasser2@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: Florimond Manca <florimond.manca@gmail.com> Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> * Personnal data fix (#58) * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * adds some options and fixes wrong scholarship in the personnal data form * adds info on phone number format (#61) * Modify inscription page (#32) * modify the order of blocks * Update dependencies and TravisCI build (#33) * Update dependencies via a clean npm install * Use Node.js 10 in Travis CI * Specify node==10.x for Heroku * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * Validated signup file display (#54) * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * adds untested frontend support for showing validated status of signup file * adds phone number validation for personnal data * checks for year field in registration to display correct status * adds some options and fixes wrong scholarship in the personnal data form * adds info on phone number format Co-authored-by: AurianeStrasser2 <32937502+AurianeStrasser2@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: Florimond Manca <florimond.manca@gmail.com> Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> * Update student-signup.component.html (#62) * Improve error message (#63) * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * improves phone number validation format * adds error message when email is already used and redirects after signup (#64) * adds support for personnal data * modifie le form pour inclure la nationalité * supprime le gg form * supprime le champ section et ajoute la liste des etablissements * adapts for user * adds validation and connects to students api for personnal data * adds classType field and rgpd info * corrects scholarships * removes signup file tab * minor presentation changes * deletes random console.log * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * changes upload component declarations * filters if the whole list is sent back * adds message after personnal data modifications * improves phone number validation format * adds message when email already used and redirects after signup * ajout champ confirmation email * supprime elements inutiles Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: AurianeStrasser2 <32937502+AurianeStrasser2@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: Florimond Manca <florimond.manca@gmail.com> Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: feli vigneau <feli.vigneau@student-cs.fr> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> --- .vscode/settings.json | 3 + src/app/signup/core/email.matcher.ts | 10 ++ src/app/signup/core/index.ts | 1 + .../student-signup.component.html | 13 +- .../student-signup.component.ts | 132 +++++++++--------- 5 files changed, 94 insertions(+), 65 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/app/signup/core/email.matcher.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f7d4a64 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\feliv\\anaconda3\\python.exe" +} \ No newline at end of file diff --git a/src/app/signup/core/email.matcher.ts b/src/app/signup/core/email.matcher.ts new file mode 100644 index 0000000..1b3bd76 --- /dev/null +++ b/src/app/signup/core/email.matcher.ts @@ -0,0 +1,10 @@ +import { FormControl, FormGroupDirective, NgForm } from '@angular/forms'; +import { ErrorStateMatcher } from '@angular/material'; + +// From: https://stackoverflow.com/a/51606362 +export class EmailErrorStateMatcher implements ErrorStateMatcher { + isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { + const invalidParent = !!(control && control.parent && control.parent.invalid && control.parent.dirty); + return (control && control.dirty && invalidParent); + } +} \ No newline at end of file diff --git a/src/app/signup/core/index.ts b/src/app/signup/core/index.ts index 29d5d82..0d1f186 100644 --- a/src/app/signup/core/index.ts +++ b/src/app/signup/core/index.ts @@ -3,3 +3,4 @@ export * from './registration.service'; export * from './personnalData.model'; export * from './personnalData.service'; export * from './password.matcher'; +export * from './email.matcher'; diff --git a/src/app/signup/student-signup/student-signup.component.html b/src/app/signup/student-signup/student-signup.component.html index 31e460d..8f622ce 100644 --- a/src/app/signup/student-signup/student-signup.component.html +++ b/src/app/signup/student-signup/student-signup.component.html @@ -26,6 +26,15 @@ </mat-hint> </mat-form-field> + <!-- Confirm Email --> + <mat-form-field class="full-width"> + <input matInput type="email" formControlName="emailConfirm" placeholder="Confirmer l'adresse email" + [errorStateMatcher]="emailMatcher"> + <mat-error *ngIf="formGroup.hasError('emailsDifferent')"> + Les adresses emails doivent être identiques. + </mat-error> + </mat-form-field> + <mat-form-field class="full-width"> <input matInput type="tel" formControlName="phoneNumber" placeholder="Numéro de téléphone" required> <mat-hint> @@ -37,7 +46,7 @@ <p> Il ne te reste plus qu'à choisir un mot de passe. :-) </p> - + <!-- Password --> <mat-form-field class="full-width"> <input matInput type="password" formControlName="password" placeholder="Mot de passe" required> @@ -46,7 +55,7 @@ <!-- Confirm password --> <mat-form-field class="full-width"> <input matInput type="password" formControlName="passwordConfirm" placeholder="Confirmer le mot de passe" - [errorStateMatcher]="matcher"> + [errorStateMatcher]="passwordMatcher"> <mat-error *ngIf="formGroup.hasError('passwordsDifferent')"> Les mots de passe doivent être identiques. </mat-error> diff --git a/src/app/signup/student-signup/student-signup.component.ts b/src/app/signup/student-signup/student-signup.component.ts index 398a968..5d127a5 100644 --- a/src/app/signup/student-signup/student-signup.component.ts +++ b/src/app/signup/student-signup/student-signup.component.ts @@ -4,7 +4,7 @@ import { Router } from '@angular/router'; import { MatSnackBar } from '@angular/material'; import { Observable } from 'rxjs'; import { tap, mergeMap } from 'rxjs/operators'; -import { Registration, RegistrationService, PasswordErrorStateMatcher,PersonnalData,PersonnalDataService } from '../core'; +import { Registration, RegistrationService, PasswordErrorStateMatcher, EmailErrorStateMatcher, PersonnalData, PersonnalDataService } from '../core'; import { AuthService } from 'app/core'; @@ -23,45 +23,46 @@ export class StudentSignupComponent implements OnInit { public showPersonnalDataForm = false; public zipPattern = new RegExp(/^\d{5}(?:\d{2})?$/) public possibleParentsStatus = [ - {id:"maried",name:"Mariés"}, - {id:"divorced",name:"Divorcés"}, - {id:"cohabitation",name:"En concubinage"}, - {id:"monoparental",name:"Famille monoparentale"} + { id: "maried", name: "Mariés" }, + { id: "divorced", name: "Divorcés" }, + { id: "cohabitation", name: "En concubinage" }, + { id: "monoparental", name: "Famille monoparentale" } ] public possibleParentsActivities = [ - {id:"farmer",name:"Agriculteur"}, - {id:"artisan",name:"Artisan, commerçant, chef d'entreprise"}, - {id:"executive",name:"Cadre, profession intellectuelle supérieure"}, - {id:"teacher",name:"Enseignant et assimilé"}, - {id:"intermediate",name:"Profession intermédiaire"}, - {id:"employee",name:"Employé"}, - {id:"worker",name:"Ouvrier"}, - {id:"retreated",name:"Retraité"}, - {id:"inactive",name:"Inactif"}, - {id:"other",name:"Autre"} + { id: "farmer", name: "Agriculteur" }, + { id: "artisan", name: "Artisan, commerçant, chef d'entreprise" }, + { id: "executive", name: "Cadre, profession intellectuelle supérieure" }, + { id: "teacher", name: "Enseignant et assimilé" }, + { id: "intermediate", name: "Profession intermédiaire" }, + { id: "employee", name: "Employé" }, + { id: "worker", name: "Ouvrier" }, + { id: "retreated", name: "Retraité" }, + { id: "inactive", name: "Inactif" }, + { id: "other", name: "Autre" } ] public possibleScholarships = [ - {id:"echelon1",name:"Oui, échelon 1"}, - {id:"echelon2",name:"Oui, échelon 2"}, - {id:"echelon3",name:"Oui, échelon 3"}, - {id:"echelon4",name:"Oui, échelon 4"}, - {id:"echelon5",name:"Oui, échelon 5"}, - {id:"echelon6",name:"Oui, échelon 6"}, - {id:"no",name:"Non"}, + { id: "echelon1", name: "Oui, échelon 1" }, + { id: "echelon2", name: "Oui, échelon 2" }, + { id: "echelon3", name: "Oui, échelon 3" }, + { id: "echelon4", name: "Oui, échelon 4" }, + { id: "echelon5", name: "Oui, échelon 5" }, + { id: "echelon6", name: "Oui, échelon 6" }, + { id: "no", name: "Non" }, ] - matcher = new PasswordErrorStateMatcher(); + passwordMatcher = new PasswordErrorStateMatcher(); + emailMatcher = new EmailErrorStateMatcher(); constructor( private registrationService: RegistrationService, - private personnalDataService : PersonnalDataService, + private personnalDataService: PersonnalDataService, private formBuilder: FormBuilder, private router: Router, private auth: AuthService, private snackBar: MatSnackBar, - + ) { } ngOnInit() { @@ -69,35 +70,36 @@ export class StudentSignupComponent implements OnInit { } createForm() { - + this.formGroup = this.formBuilder.group({ firstName: '', lastName: '', email: ['', Validators.email], + emailConfirm: '', phoneNumber: '', - gender:'', - adressNumber:'', - street:'', - zipCode:['',Validators.pattern(this.zipPattern)], - city:'', - personnalPhone:'', - parentsPhone:'', - parentsEmail:['',Validators.email], - school:'', - grade:'', - section:'', - specialTeaching:'', - scholarship:'', - fatherActivity:'', - motherActivity:'', - parentsStatus:'', - dependantsNumber:'', + gender: '', + adressNumber: '', + street: '', + zipCode: ['', Validators.pattern(this.zipPattern)], + city: '', + personnalPhone: '', + parentsPhone: '', + parentsEmail: ['', Validators.email], + school: '', + grade: '', + section: '', + specialTeaching: '', + scholarship: '', + fatherActivity: '', + motherActivity: '', + parentsStatus: '', + dependantsNumber: '', password: '', passwordConfirm: '', agree: [false, Validators.required], filledForm: false, acceptedConditions: false, - }, { validator: (group) => this.checkPasswords(group)},) + }, { validator:[(group) => this.checkPasswords(group), (group)=>this.checkEmails(group)] }) console.log(this.formGroup.value.agree) } @@ -106,16 +108,18 @@ export class StudentSignupComponent implements OnInit { const passwordConfirm = group.controls.passwordConfirm.value; return password === passwordConfirm ? null : { passwordsDifferent: true }; } - toggleShowPersonnalDataForm(){ - this.showPersonnalDataForm = !this.showPersonnalDataForm; + private checkEmails(group: FormGroup): null | any { + const email = group.controls.email.value; + const emailConfirm = group.controls.emailConfirm.value; + return email === emailConfirm ? null : { emailsDifferent: true }; } + + submit() { this.loading = true; - const {email,firstName,lastName,phoneNumber} = this.formGroup.value - //const {gender,adressNumber,street,zipCode,city,personnalPhone,parentsPhone,parentsEmail,school,grade,section,specialTeaching,scholarship,fatherActivity,motherActivity,parentsStatus,dependantsNumber} = this.formGroup.value; - const registration: Registration = {email,firstName,lastName,phoneNumber}; - // const personnalData: PersonnalData = {gender,adressNumber,street,zipCode,city,personnalPhone,parentsPhone,parentsEmail,school,grade,section,specialTeaching,scholarship,fatherActivity,motherActivity,parentsStatus,dependantsNumber}; - + const { email, firstName, lastName, phoneNumber } = this.formGroup.value + const registration: Registration = { email, firstName, lastName, phoneNumber }; + const password: string = this.formGroup.controls.password.value; this.registrationService.create(registration, password).pipe( mergeMap(() => this.auth.login(registration.email, password)), @@ -124,25 +128,27 @@ export class StudentSignupComponent implements OnInit { 'OK', { duration: 3000 }, )), - tap(()=> this.error = ""), + tap(() => this.error = ""), tap(() => this.loading = false), tap(() => { - setTimeout(()=>{ + setTimeout(() => { this.router.navigate(['./membres']) - - },3000)}) - + + }, 3000) + }) + ).subscribe( - () => {}, - (error) => { - + () => { }, + (error) => { + - this.loading=false - - if(error.error.email){ + this.loading = false + + if (error.error.email) { this.error = "Erreur, cet email est déjà utilisé !" } - } + } + ); // this.personnalDataService.create(personnalData).pipe( // tap(() => this.loading = false), -- GitLab