@ -70,7 +70,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
carteExitDeja : boolean ;
carteEnvoieOK : boolean ;
carteEnvoieEncours : boolean ;
echecRegisterPar : boolean ;
cartePars : any ;
filteredCartePars : any ;
@ -82,6 +82,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this . user = afAuth . authState ;
this . carteExitDeja = false ;
this . carteEnvoieOK = false ;
this . echecRegisterPar = false ;
this . carteEnvoieEncours = false ;
this . filteredCartePars = { } ;
this . radioParrain = '' ;
@ -251,71 +252,92 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this . parrain . password = this . getRandomArbitrary ( 111111 , 999999 ) . toString ( ) ;
// this.authService.signUp(this.parrain);
parrainTemp = this . parrain ;
this . secondaryApp . auth ( ) . createUserWithEmailAndPassword ( parrainTemp . email , parrainTemp . password ) . then ( function ( userCreate ) {
console . log ( 'User ' + userCreate . uid + ' created successfully!' ) ;
// I don't know if the next statement is necessary
const imagePath = 'profilImage/' + userCreate . uid + '/userPic.jpg' ;
const dbRef = firebase . database ( ) . ref ( ) ;
const userRef = dbRef . child ( 'Parrain' ) . child ( userCreate . uid ) ;
userCreate . updateProfile ( {
displayName : parrainTemp.status ,
photoURL : imagePath ,
emailVerified : true
} ) ;
try {
parrainTemp . uid = userCreate . uid ;
parrainTemp . emailVerified = userCreate . emailVerified ;
userRef . set ( parrainTemp ) ;
console . log ( 'crer par: ' + parrainTemp . firstname ) ;
// this.cartePar.parrainCarte = parrainTemp;
var ilExist = false ;
var parrainExistListTemp = this . afDb . list ( '/Parrain/' , {
query : {
orderByChild : 'email' ,
equalTo : this.parrain.email
}
}
) . subscribe ( tab = > {
if ( tab . length === 0 ) {
console . log ( 'iiii' ) ;
this . secondaryApp . auth ( ) . createUserWithEmailAndPassword ( parrainTemp . email , parrainTemp . password )
. catch ( e = > {
console . log ( 'lololo ' + e ) ;
this . carteEnvoieOK = false ;
} )
. then ( function ( userCreate ) {
console . log ( 'User ' + userCreate . uid + ' created successfully!' ) ;
// I don't know if the next statement is necessary
const imagePath = 'profilImage/' + userCreate . uid + '/userPic.jpg' ;
const dbRef = firebase . database ( ) . ref ( ) ;
const userRef = dbRef . child ( 'Parrain' ) . child ( userCreate . uid ) ;
userCreate . updateProfile ( {
displayName : parrainTemp.status ,
photoURL : imagePath ,
emailVerified : true
} ) ;
try {
parrainTemp . uid = userCreate . uid ;
parrainTemp . emailVerified = userCreate . emailVerified ;
userRef . set ( parrainTemp ) ;
console . log ( 'crer par: ' + parrainTemp . firstname ) ;
// this.cartePar.parrainCarte = parrainTemp;
this . secondaryApp . auth ( ) . sendPasswordResetEmail ( userCreate . email ) ;
userCreate . sendEmailVerification ( ) ;
console . log ( 'avant logout firebase.auth().currentUser.uid: ' ) ;
this . secondaryApp . auth ( ) . signOut ( ) ;
console . log ( 'avant logout firebase.auth().currentUser.uid: ' ) ;
this . secondaryApp . auth ( ) . sendPasswordResetEmail ( userCreate . email ) ;
userCreate . sendEmailVerification ( ) ;
} catch ( e ) {
// No content response..
console . log ( 'error dans envoyer carte !' ) ;
console . log ( e ) ;
// this.goToOpComm();
// this.router.navigate(['/']);
}
//fin
// this.secondaryApp.auth().signOut();
} ) ;
console . log ( 'avant logout firebase.auth().currentUser.uid: ' ) ;
this . secondaryApp . auth ( ) . signOut ( ) ;
console . log ( 'avant logout firebase.auth().currentUser.uid: ' ) ;
} catch ( e ) {
// No content response..
console . log ( 'error dans envoyer carte !' ) ;
console . log ( e ) ;
// this.goToOpComm();
// this.router.navigate(['/']);
}
//fin
// this.secondaryApp.auth().signOut();
} ) ;
const parNewlistTemp = this . afDb . list ( '/Parrain/' , {
query : {
orderByChild : 'email' ,
equalTo : parrainTemp.email
}
}
) ;
parNewlistTemp . forEach ( par = > {
par . forEach ( elementParTemp = > {
if ( elementParTemp !== undefined ) {
if ( elementParTemp . uid !== '' ) {
this . getIdParrain ( elementParTemp . uid ) ;
this . creerCartePar ( ) ;
this . carteEnvoieEncours = true ;
this . carteEnvoieOK = true ;
setTimeout ( ( ) = > {
this . carteEnvoieEncours = false ;
this . goToOpComm ( ) ;
this . toastrService . success ( 'Envoie de la carte à ' + elementParTemp . familyname
+ ' ' + elementParTemp . firstname ) ;
} ,
3000 ) ;
const parNewlistTemp = this . afDb . list ( '/Parrain/' , {
query : {
orderByChild : 'email' ,
equalTo : parrainTemp.email
}
}
}
} ) ;
) ;
parNewlistTemp . forEach ( par = > {
par . forEach ( elementParTemp = > {
if ( elementParTemp !== undefined ) {
if ( elementParTemp . uid !== '' ) {
this . getIdParrain ( elementParTemp . uid ) ;
this . creerCartePar ( ) ;
this . carteEnvoieEncours = true ;
this . carteEnvoieOK = true ;
setTimeout ( ( ) = > {
this . carteEnvoieEncours = false ;
this . goToOpComm ( ) ;
this . toastrService . success ( 'Envoie de la carte à ' + elementParTemp . familyname
+ ' ' + elementParTemp . firstname ) ;
} ,
3000 ) ;
}
}
} ) ;
} ) ;
} else {
this . echecRegisterPar = true ;
console . log ( 'il est la' ) ;
}
} ) ;
}
@ -378,8 +400,11 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
getRandomArbitrary ( min , max ) {
return Math . trunc ( Math . random ( ) * ( max - min ) + min ) ;
}
initParSelect ( ) {
initParSelect () {
this . parSelect = '' ;
this . parrain = new Parrain ;
this . birthdayTemp = new Date ;
this . echecRegisterPar = false ;
}
getIdParrain ( parUid ) {