Erreur email exist ou exist pas

thierry
Tmadkaud 7 years ago
parent 9d61daea7b
commit 06134e1f3a

@ -65,7 +65,6 @@ export class DemandeOpCommercialComponent implements OnInit, OnDestroy {
}
}).map((array) => array.reverse()) as FirebaseListObservable<any[]>;
}
console.log(auth.uid);
}
);
}

@ -105,7 +105,6 @@ export class ListeOpCommercialComponent implements OnInit, OnDestroy {
}
console.log(auth.uid);
}
);
}

@ -28,6 +28,10 @@
<div class="text-center" style="margin-top:5%">
<a (click)="loadResetPasswordComponent()" class="blue-text">Mot de passe oublié ?</a>
</div>
<div *ngIf="echecLogin" class="alert alert-danger">
Erreur: votre <strong>email</strong> ou votre <strong>mot de passe n'est pas correct !</strong>.
</div>
</form>
</div>
</div>

@ -26,11 +26,12 @@ export class LoginComponent implements OnInit, OnDestroy {
myUser: User;
parrain: Parrain;
commercant: Commercant;
echecLogin: boolean;
user: Observable<firebase.User>;
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
private router: Router, private authService: AuthService) {
this.echecLogin = false;
this.user = afAuth.authState;
this.email = '';
this.password = '';
@ -46,7 +47,13 @@ export class LoginComponent implements OnInit, OnDestroy {
}
}
login() {
this.authService.signIn(this.email, this.password);
try{
var tto = this.authService.signIn(this.email, this.password).catch(e => this.echecLogin = true);
console.log('iiiiiiiii' + tto);
}catch (e){
console.log('iiiiiiiii');
console.log(e);
}
}
loadHomeComponent() {

@ -112,6 +112,9 @@
<div *ngIf="carteEnvoieOK" class="alert alert-danger">
Une carte vient d'être envoyée au nouveau Parrain {{cartePar.parrainCarte.firstname}} {{cartePar.parrainCarte.familyname}}
</div>
<div *ngIf="echecRegisterPar" class="alert alert-danger">
Erreur: Un compte avec cet <strong>email</strong> existe déjà.
</div>
</div>
</div>
</div>

@ -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) {

@ -92,7 +92,10 @@
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="filePar || !birthday.touched || (birthday.touched && validationBirthdayParrain()) || email.errors || password.errors || (parrain.password != ConfirmPasswordParrain) || parrain.familyname == '' || parrain.firstname == '' || parrain.sex == '' || test" (click)="register()">S'inscrire</button>
<!--<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>-->
<div *ngIf="test" class="alert alert-danger">
<div *ngIf="echecRegisterPar" class="alert alert-danger">
Erreur: Un compte avec cet <strong>email</strong> existe déjà.
</div>
<div *ngIf="(echecRegisterCom !== true) && test" class="alert alert-danger">
<strong><i>{{parrain.familyname}} {{parrain.firstname}}, </i></strong> votre compte à bien été créé, un email de validation vient de vous être envoyé à l'adresse <strong><i>{{parrain.email}}</i></strong> !
</div>
</div>
@ -156,7 +159,10 @@
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="fileCom || email.errors || password.errors || siret.errors || commercant.raisonSociale == '' || commercant.commercialName == '' || (commercant.password != ConfirmPasswordCommercant) || test" (click)="register()">S'inscrire</button>
<!--<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>-->
<div *ngIf="test" class="alert alert-danger">
<div *ngIf="echecRegisterCom" class="alert alert-danger">
Erreur: Un compte avec cet <strong>email</strong> existe déjà.
</div>
<div *ngIf="test && (echecRegisterCom !== true)" class="alert alert-danger">
<strong><i>{{commercant.commercialName}}, </i></strong> votre compte à bien été créé, un email de validation vient de vous être envoyé à l'adresse <strong><i>{{commercant.email}}</i></strong> !
</div>
</div>

@ -26,11 +26,14 @@ export class RegisterComponent implements OnInit, OnDestroy {
parrainDateTimeTest: Date;
fileCom: boolean;
filePar: boolean;
echecRegisterPar: boolean;
echecRegisterCom: boolean;
constructor(private router: Router, private authService: AuthService) {
// this.fileTest = new File();
this.fileCom = true;
this.filePar = true;
this.echecRegisterPar = false;
this.echecRegisterCom = false;
this.currentUser = new User();
this.parrain = new Parrain();
this.commercant = new Commercant();
@ -83,19 +86,27 @@ export class RegisterComponent implements OnInit, OnDestroy {
if (this.currentUser.status === 'Parrain') {
this.parrain.status = this.currentUser.status;
this.parrain.secretCode = this.getRandomArbitrary(1111, 9999).toString();
this.authService.signUp(this.parrain);
this.authService.signUp(this.parrain).catch(e => {
this.echecRegisterPar = true;
this.test = false;
});
/*if ((<HTMLInputElement>document.getElementById('orangeForm-File')).value !== '') {
this.clean();
}*/
this.echecRegisterPar = false;
this.test = true;
}else if (this.currentUser.status === 'Commercant') {
this.commercant.status = this.currentUser.status;
let dateTemp = new Date(Date.now());
this.commercant.dateInscription = new Date(dateTemp);
this.authService.signUp(this.commercant);
this.authService.signUp(this.commercant).catch(e => {
this.echecRegisterCom = true;
this.test = false;
});
/*if ((<HTMLInputElement>document.getElementById('orangeForm-File')).value !== '') {
this.clean();
}*/
this.echecRegisterCom = false;
this.test = true;
}
}

@ -103,7 +103,12 @@ export class AuthService {
// oublie pas de MAJ emailVerified dans database
signIn(email: string, password: string) {
firebase.auth().signInWithEmailAndPassword(email, password).then(user => {
return firebase.auth().signInWithEmailAndPassword(email, password)
.catch(e => {
console.log('lololo ' + e);
return e;
})
.then(user => {
if (user) {
this.profileDataParrain = this.afDb.list('/Parrain/', {
@ -217,7 +222,11 @@ export class AuthService {
}
*/
signUp(infoUser: any) {
firebase.auth().createUserWithEmailAndPassword(infoUser.email, infoUser.password)
return firebase.auth().createUserWithEmailAndPassword(infoUser.email, infoUser.password)
.catch(e => {
console.log('lololo ' + e);
return e;
})
.then(userCreate => {
userCreate.sendEmailVerification().then(res => {
console.log('res : ');
@ -235,7 +244,7 @@ export class AuthService {
console.log('save info failed !!! ');
}
})
});
}

Loading…
Cancel
Save