| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- import { Router } from '@angular/router';
- import { Component, OnInit } from '@angular/core';
- import { FormControl, FormGroupDirective, NgForm, Validators, FormGroup, FormBuilder } from '@angular/forms';
- import { HttpClient, HttpHeaders } from '@angular/common/http';
- import { ErrorStateMatcher } from '@angular/material/core';
- import { DomSanitizer } from "@angular/platform-browser";
- import { MatIconRegistry } from '@angular/material/icon';
- import { AuthService } from 'src/app/services/auth.service'
- import { MustMatch } from '../shared/validator/confirm-password.validator';
- const googleLogoURL = "../assets/img/social/google+.svg";
- const facebookLogoURL = "../assets/img/social/facebook.svg";
- declare const gapi: any;
- @Component({
- selector: 'app-register',
- templateUrl: './register.component.html',
- styleUrls: ['./register.component.scss']
- })
- export class RegisterComponent implements OnInit {
- http: any;
- customErrors: any;
- constructor(public router: Router, private authService : AuthService, private formBuilder: FormBuilder, private matIconRegistry: MatIconRegistry, private domSanitizer: DomSanitizer)
- { this.matIconRegistry.addSvgIcon("googleLogo", this.domSanitizer.bypassSecurityTrustResourceUrl(googleLogoURL)),
- this.matIconRegistry.addSvgIcon("facebookLogo", this.domSanitizer.bypassSecurityTrustResourceUrl(facebookLogoURL))
- const currentYear = new Date().getFullYear();
- this.maxDate = new Date(currentYear - 10, 11, 31);}
- maxDate: Date;
- formGroup: FormGroup;
- submitted = false;
- loading = false;
- hide =true;
-
- ngOnInit(): void {
- this.createForm();
- }
- createForm() {
- let emailregex: RegExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
- let caracereregex : RegExp = /^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð ,.'-]+$/;
- let adressregex : RegExp = /^[A-z0-9À-ž\s ,.'-]+$/;
- let phonenumberregex : RegExp = /^(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/;
- let dateregex : RegExp = /^((31(?!\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\b|t)t?|Nov)(ember)?)))|((30|29)(?!\ Feb(ruary)?))|(29(?=\ Feb(ruary)?\ (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\b|t)t?|Nov|Dec)(ember)?)\ ((1[6-9]|[2-9]\d)\d{2})$/;
- this.formGroup = this.formBuilder.group({
- lastname: [null, [Validators.required, Validators.pattern(caracereregex)]],
- firstname: [null, [Validators.required, Validators.pattern(caracereregex)]],
- phonenumber: [null,[Validators.required, Validators.pattern(phonenumberregex)]],
- birthday: [null,[Validators.required]],
- terms: [false, Validators.requiredTrue],
- adress: [null,[Validators.required, Validators.pattern(adressregex)]],
- email: [null, [Validators.required, Validators.pattern(emailregex)]],
- password: [null, [Validators.required, this.checkPassword]],
- confirmPassword:[null, Validators.required]
- }, {
- validator: MustMatch('password', 'confirmPassword')
- });
- }
- checkPasswords(group: FormGroup) { // here we have the 'passwords' group
- let pass = group.controls.password.value;
- let confirmPass = group.controls.confirmPassword.value;
- return pass === confirmPass ? null : { notSame : true }
- }
- getErrorLastname() {
- return this.formGroup.get('lastname').hasError('required') ? 'Nom requis' :
- this.formGroup.get('lastname').hasError('pattern') ? 'Nom non valide' : 'Nom non valide';
- }
- getErrorFirstname() {
- return this.formGroup.get('firstname').hasError('required') ? 'Prénom requis' :
- this.formGroup.get('firstname').hasError('pattern') ? 'Prénom non valide' : 'Prénom non valide';
- }
- getErrorPhonenumber() {
- return this.formGroup.get('phonenumber').hasError('required') ? 'Numéro de téléphone requis' :
- this.formGroup.get('phonenumber').hasError('pattern') ? 'Numéro de téléphone non valide' : '';
- }
- getErrorAdress() {
- return this.formGroup.get('adress').hasError('required') ? 'adresse requise' :
- this.formGroup.get('adress').hasError('pattern') ? 'Prénom non valide' : 'Prénom non valide';
- }
- getErrorDate() {
- return this.formGroup.get('birthday').hasError('required') ? 'Date de naissance requise' :
- this.formGroup.get('birthday').hasError('pattern') ? 'Date de naissance non valide' : '';
- }
- getErrorTerms(){
- return this.formGroup.get('terms').hasError('required') ? 'Please accept the terms' :
- this.formGroup.get('terms').hasError('pattern') ? 'terms not accepted' : '';
- }
- getErrorConfirmPassword() {
- return this.formGroup.get('confirmPassword').hasError('required') ? 'Confirmation mot de passe requise' :
- this.formGroup.hasError('MustMatch') ?
- '' : 'Les mots de passe saisis ne sont pas identiques';
- }
- checkPassword(control) {
- let enteredPassword = control.value
- let passwordCheck = /^(?=.*[A-Z])(?=.*[a-z])(?=.{8,})/;
- return (!passwordCheck.test(enteredPassword) && enteredPassword) ? { 'requirements': true } : null;
- }
- getErrorEmail() {
- return this.formGroup.get('email').hasError('required') ? 'Adresse email requise' :
- this.formGroup.get('email').hasError('pattern') ? 'Adresse email non valide' : '';
- }
- getErrorPassword() {
- return this.formGroup.get('password').hasError('required') ? 'Mot de passe requis' :
- this.formGroup.get('password').hasError('requirements') ?
- 'Le mot de passe doit comporter au moins 8 caractères, une lettre majuscule, une lettre majuscule' : '';
- }
- get f() { return this.formGroup.controls; }
- // openSnackBar(message : string) {
- // this.snackBar.open(message, 'action', {
- // duration: 5000,
- // });
- // }
- //google signIn
-
- signInWithGoogle(): void {
- this.authService.signInWithGoogle().subscribe(
- _user => {
- // Redirection après l'authentification réussie avec Google
-
- this.router.navigate(['/auth']);
- },
- error => {
- console.log(error);
- // Gérer l'erreur
- }
- );
- }
-
-
-
-
-
-
-
-
-
-
- // this.authService.signGoogle().subscribe(
- // data=> {
- // console.log(data);
- // this.router.navigate(['/auth']);
- // },
- // error=> {
- // console.log(error);
- // });
-
- signUp(): void{
- this.submitted = true;
- if (this.formGroup.invalid) {
- return;
- }
- this.loading = true;
- this.authService.signUP(this.formGroup.value).subscribe(
- data => {
- console.log(data)
- this.loading = false;
- this.router.navigate(['/auth']);
- setTimeout(() => {
- document.location.reload()
- },2000)
- },
- err => {
- this.loading = false;
- console.log(err.error.message)
- this.authService.openSnackBar(err.error.message)
- });
- console.log(this.formGroup.value)
-
- }
- }
|