|
|
|
@ -45,6 +45,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
|
|
|
|
|
parSelect: string;
|
|
|
|
|
selectPar: boolean;
|
|
|
|
|
parrainAffListTemp = [];
|
|
|
|
|
databaseRef: any;
|
|
|
|
|
|
|
|
|
|
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
|
|
|
|
|
private router: Router, private authService: AuthService,
|
|
|
|
@ -60,7 +61,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
|
|
|
|
|
this.cartePar = new CarteParrainage();
|
|
|
|
|
this.parrainAffList = null;
|
|
|
|
|
this.user = afAuth.authState;
|
|
|
|
|
|
|
|
|
|
this.databaseRef = firebase.database().ref();
|
|
|
|
|
this.user.subscribe(
|
|
|
|
|
(auth) => {
|
|
|
|
|
if (auth) {
|
|
|
|
@ -148,27 +149,31 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
registerNewParrain() {
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
this.parrain.status = 'Parrain';
|
|
|
|
|
this.parrain.secretCode = this.getRandomArbitrary(1111, 9999).toString();
|
|
|
|
|
this.parrain.password = this.getRandomArbitrary(111111, 999999).toString();
|
|
|
|
|
// this.authService.signUp(this.parrain);
|
|
|
|
|
|
|
|
|
|
firebase.auth().createUserWithEmailAndPassword(this.parrain.email, this.parrain.password).then(userCreate => {
|
|
|
|
|
this.cartePar.parrainID = userCreate.uid;
|
|
|
|
|
this.authService.setUserInfo(userCreate, this.parrain);
|
|
|
|
|
// this.authService.signIn(this.commercant.email, this.commercant.password);
|
|
|
|
|
|
|
|
|
|
firebase.auth().signInWithEmailAndPassword(this.commercant.email, this.commercant.password).then(user => {
|
|
|
|
|
if (user) {
|
|
|
|
|
console.log('salut le ' + user.displayName + ' ' + user.email + ' has signed!');
|
|
|
|
|
user.displayName = this.commercant.status;
|
|
|
|
|
}else {
|
|
|
|
|
console.log('error!!');
|
|
|
|
|
}
|
|
|
|
|
const imagePath = 'profilImage/' + userCreate.uid + '/userPic.jpg';
|
|
|
|
|
const userRef = this.databaseRef.child('Parrain').child(userCreate.uid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userCreate.updateProfile({
|
|
|
|
|
displayName: this.parrain.status,
|
|
|
|
|
photoURL: imagePath
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.cartePar.parrainID = userCreate.uid;
|
|
|
|
|
this.parrain.uid = userCreate.uid;
|
|
|
|
|
|
|
|
|
|
userRef.set(this.parrain);
|
|
|
|
|
this.creerCartePar();
|
|
|
|
|
firebase.auth().signOut();
|
|
|
|
|
firebase.auth().signInWithEmailAndPassword(this.commercant.email, this.commercant.password);
|
|
|
|
|
});
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
getRandomArbitrary(min, max) {
|
|
|
|
|
return Math.trunc(Math.random() * (max - min) + min);
|
|
|
|
|