From 8bc92c28103adf83850c225f81b73bb296c35212 Mon Sep 17 00:00:00 2001 From: Tmadkaud Date: Thu, 12 Oct 2017 14:40:51 +0200 Subject: [PATCH 1/2] correction bug editer mdp ok --- src/app/components/home/home.component.ts | 5 +- .../reset-password.component.html | 2 +- .../reset-password.component.ts | 1 + src/app/components/login/login.component.ts | 2 + .../nav-admin/nav-admin.component.html | 2 +- .../nav-admin/nav-admin.component.ts | 18 ++- .../envoyer-carte/envoyer-carte.component.ts | 1 + .../scanner-carte/scanner-carte.component.ts | 23 +++- .../edit-profil/edit-profil.component.html | 78 ++---------- .../edit-profil/edit-profil.component.ts | 30 +++-- .../register/register.component.html | 4 +- src/app/services/auth/auth.service.ts | 115 +++++++++++++----- .../opCommercial/op-commercial.service.ts | 62 ++++++---- 13 files changed, 202 insertions(+), 141 deletions(-) diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index bb1bc8a..e1cd67e 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -4,6 +4,7 @@ import { AngularFireAuth } from 'angularfire2/auth'; import { Router } from '@angular/router'; import { HomeService } from '../../services/home/home.service'; import { OpCommercialService } from '../../services/opCommercial/op-commercial.service'; +import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database'; @Component({ selector: 'app-home', @@ -14,10 +15,12 @@ import { OpCommercialService } from '../../services/opCommercial/op-commercial.s export class HomeComponent implements OnInit { public loadComponentRegister = false; public loadComponentLogin = false; - + commList: FirebaseListObservable; constructor(public afAuth: AngularFireAuth, private opComService: OpCommercialService, private router: Router) { try{ opComService.updateCarteEtOpCom(); + this.commList = this.opComService.getCommercants(); + this.commList.subscribe(tabCommercant => console.log(tabCommercant)); }catch (e){ console.log(e); } diff --git a/src/app/components/home/reset-password/reset-password.component.html b/src/app/components/home/reset-password/reset-password.component.html index fcb4818..b18cba5 100644 --- a/src/app/components/home/reset-password/reset-password.component.html +++ b/src/app/components/home/reset-password/reset-password.component.html @@ -19,7 +19,7 @@ -
+
Un email pour réinitiliser votre mot de passe vient de vous être envoyé à {{email}}.
diff --git a/src/app/components/home/reset-password/reset-password.component.ts b/src/app/components/home/reset-password/reset-password.component.ts index 26d8560..2d280b2 100644 --- a/src/app/components/home/reset-password/reset-password.component.ts +++ b/src/app/components/home/reset-password/reset-password.component.ts @@ -15,6 +15,7 @@ export class ResetPasswordComponent implements OnInit, OnDestroy { emailExist: boolean; profileDataParrainEmail: FirebaseListObservable; profileDataCommercantEmail: FirebaseListObservable; + constructor(private router: Router, private afDb: AngularFireDatabase) { this.email = ''; } diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 1ad268d..f646d92 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -75,6 +75,8 @@ export class LoginComponent implements OnInit, OnDestroy { } ngOnDestroy() { + this.email = ''; + this.password = ''; this.myUser = { uid: '', image: new FireImg(), diff --git a/src/app/components/navigationBar/nav-admin/nav-admin.component.html b/src/app/components/navigationBar/nav-admin/nav-admin.component.html index add02a6..798bc19 100644 --- a/src/app/components/navigationBar/nav-admin/nav-admin.component.html +++ b/src/app/components/navigationBar/nav-admin/nav-admin.component.html @@ -16,7 +16,7 @@
--> - -
- +
+ +
+ Un email pour réinitiliser votre mot de passe vient de vous être envoyé à {{localUser.email}}. +
-
-
- - -
- Mot de passe incorrect. -
-
-
-
- - -
- Votre email est requis et doit avoir ce format : john@parrain.fr. -
-
-
- - -
- Votre nouveau mot de passe doit avoir 5 caractères au minimum. -
-
-
- - -
- Ecrivez le même nouveau mot de passe. -
-
-
-
@@ -152,44 +122,16 @@
- + +
+ Un email pour réinitiliser votre mot de passe vient de vous être envoyé à {{localUser.email}}. +
-
-
- - -
- Mot de passe incorrect. -
-
-
-
- - -
- Votre email est requis et doit avoir ce format : john@commercant.fr. -
-
-
- - -
- Votre nouveau mot de passe doit avoir 5 caractères au minimum. -
-
-
- - -
- Ecrivez le même nouveau mot de passe. -
-
-
-
+
diff --git a/src/app/components/profil/edit-profil/edit-profil.component.ts b/src/app/components/profil/edit-profil/edit-profil.component.ts index 7f630ea..40efa37 100644 --- a/src/app/components/profil/edit-profil/edit-profil.component.ts +++ b/src/app/components/profil/edit-profil/edit-profil.component.ts @@ -32,8 +32,11 @@ export class EditProfilComponent implements OnInit, OnDestroy { minDateTimeTest: Date; maxDateTimeTest: Date; parrainDateTimeTest: Date; + userCurrentFB: firebase.User; + resetPassEmail: boolean; constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase, private router: Router, private authService: AuthService ) { + this.resetPassEmail = false; this.localUser = new User(); this.parrain = new Parrain(); this.commercant = new Commercant(); @@ -49,6 +52,7 @@ export class EditProfilComponent implements OnInit, OnDestroy { this.user.subscribe( (auth) => { if (auth) { + this.userCurrentFB = auth; this.profileData = this.afDb.list('/' + auth.displayName + '/', { query: { orderByChild: 'uid', @@ -101,23 +105,35 @@ export class EditProfilComponent implements OnInit, OnDestroy { modifyProfile() { if (this.newPassword === '') { if (this.localUser.status === 'Parrain') { - this.authService.modifyProfile(this.localUser, this.parrain); + this.authService.modifyProfile(this.localUser, this.parrain, this.confirmOldPassword, this.userCurrentFB); } else if (this.localUser.status === 'Commercant') { - this.authService.modifyProfile(this.localUser, this.commercant); + this.authService.modifyProfile(this.localUser, this.commercant, this.confirmOldPassword, this.userCurrentFB); } this.goToProfil(); } else { if (this.localUser.status === 'Parrain') { this.parrain.password = this.newPassword; - this.authService.modifyProfile(this.localUser, this.parrain); + this.authService.modifyProfile(this.localUser, this.parrain, this.confirmOldPassword, this.userCurrentFB); } else if (this.localUser.status === 'Commercant') { this.commercant.password = this.newPassword; - this.authService.modifyProfile(this.localUser, this.commercant); + this.authService.modifyProfile(this.localUser, this.commercant, this.confirmOldPassword, this.userCurrentFB); } this.goToProfil(); } } - + resetPass() { + if (this.localUser.status === 'Parrain') { + if (this.parrain.email !== '') { + firebase.auth().sendPasswordResetEmail(this.parrain.email); + this.resetPassEmail = true; + } + } else if (this.localUser.status === 'Commercant') { + if (this.commercant.email !== '') { + firebase.auth().sendPasswordResetEmail(this.commercant.email); + this.resetPassEmail = true; + } + } + } goToProfil() { this.router.navigate(['/profil']); } @@ -154,13 +170,13 @@ export class EditProfilComponent implements OnInit, OnDestroy { if (auth) { console.log(auth.uid); } else { - this.router.navigate(['/']); + // this.router.navigate(['/']); } }); } catch (e) { // No content response.. console.log(e); - this.router.navigate(['/']); + // this.router.navigate(['/']); } } diff --git a/src/app/components/register/register.component.html b/src/app/components/register/register.component.html index fee4f91..91decf8 100644 --- a/src/app/components/register/register.component.html +++ b/src/app/components/register/register.component.html @@ -95,7 +95,7 @@
Erreur: Un compte avec cet email existe déjà.
-
+
{{parrain.familyname}} {{parrain.firstname}}, votre compte à bien été créé, un email de validation vient de vous être envoyé à l'adresse {{parrain.email}} !
@@ -162,7 +162,7 @@
Erreur: Un compte avec cet email existe déjà.
-
+
{{commercant.commercialName}}, votre compte à bien été créé, un email de validation vient de vous être envoyé à l'adresse {{commercant.email}} !
diff --git a/src/app/services/auth/auth.service.ts b/src/app/services/auth/auth.service.ts index 4a589b7..db2601d 100644 --- a/src/app/services/auth/auth.service.ts +++ b/src/app/services/auth/auth.service.ts @@ -81,8 +81,9 @@ export class AuthService { this.parrain = elementParrain; this.utilisateur = elementParrain; if (/*user.emailVerified*/true){ + firebase.auth().onAuthStateChanged(function (userUpdate) { - if(userUpdate !== null){ + if (userUpdate !== null){ userUpdate.updateProfile({ displayName: elementParrain.status, photoURL: elementParrain.image.downloadURL @@ -90,6 +91,10 @@ export class AuthService { } }); if (this.utilisateur.status === 'Parrain') { + if (password !== this.parrain.password) { + const passWRef = this.databaseRef.child('Parrain').child(this.parrain.uid).child('password'); + passWRef.set(password); + } this.router.navigate(['/carteParrainageComponent']); } else if (this.utilisateur.status === 'Commercant') { this.router.navigate(['/opCommercial']); @@ -126,6 +131,10 @@ export class AuthService { if (this.utilisateur.status === 'Parrain') { this.router.navigate(['/carteParrainageComponent']); } else if (this.utilisateur.status === 'Commercant') { + if (password !== this.parrain.password) { + const passWRef = this.databaseRef.child('Commercant').child(this.commercant.uid).child('password'); + passWRef.set(password); + } this.router.navigate(['/opCommercial']); } }/*else{ @@ -136,7 +145,7 @@ export class AuthService { } }); - if (user.email === 'xjc@gmail.com') { + if (user.email === 'webapp.xjc@gmail.com') { this.router.navigate(['/demandeOpCommercialAdmin']); } }else { @@ -210,15 +219,22 @@ export class AuthService { const folder = this.folder; const path = `${this.folder}`; const iRef = storageRef.child(path); + console.log(selectedFile); + if(selectedFile !== undefined){ + try{ + iRef.put(selectedFile).then((snapshot) => { + const updates = {}; + info.image.path = path; + info.image.filename = 'Profil picture'; + info.image.downloadURL = snapshot.downloadURL; + updates[folder] = info.image; + firebase.database().ref().update(updates); + }); + }catch (e){ + console.log('Error: ' + e); + } - iRef.put(selectedFile).then((snapshot) => { - const updates = {}; - info.image.path = path; - info.image.filename = 'Profil picture'; - info.image.downloadURL = snapshot.downloadURL; - updates[folder] = info.image; - firebase.database().ref().update(updates); - }); + } } firebase.auth().onAuthStateChanged(function (userUpdate) { if (userUpdate !== null){ @@ -236,37 +252,70 @@ export class AuthService { }); } - modifyProfile(user: User, infoUser: any) { + modifyProfile(user: User, infoUser: any, confirmOldPassword: string, userCurrentFB: firebase.User) { if (infoUser.status === 'Parrain') { const userRef = this.databaseRef.child('Parrain').child(user.uid); + const parrainTemp = user; infoUser.uid = user.uid; - userRef.update(infoUser); - this.uploadModify(infoUser); - firebase.auth().onAuthStateChanged(function (userUpdate) { - userUpdate.updateEmail(infoUser.email); - userUpdate.updatePassword(infoUser.password); - if (userUpdate) { - console.log('' ); - } else { - console.log('Error'); - } - }); + try { + userRef.update(infoUser); + this.uploadModify(infoUser); + firebase.auth().onAuthStateChanged(function (userUpdate) { + if (userUpdate) { + console.log(''); + /* + if (userCurrentFB.email !== infoUser.email){ + console.log('email diferrent '); + userUpdate.updateEmail(infoUser.email); + } + if (confirmOldPassword !== infoUser.password) { + console.log('mdp diferrent '); + + console.log('update: ' + infoUser.password); + const passWRef = firebase.database().ref().child('Parrain').child(parrainTemp.uid).child('password'); + passWRef.set(infoUser.password); + userUpdate.updatePassword(infoUser.password); + }*/ + } else { + console.log('Error'); + } + + }); + }catch (e){ + console.log('Error: ' + e); + } }else if (infoUser.status === 'Commercant') { const userReff = this.databaseRef.child('Commercant').child(user.uid); infoUser.uid = user.uid; - userReff.update(infoUser); - this.uploadModify(infoUser); - firebase.auth().onAuthStateChanged(function (userUpdate) { - userUpdate.updateEmail(infoUser.email); - userUpdate.updatePassword(infoUser.password); - if (userUpdate) { - console.log(''); - } else { - console.log('Error'); - } + const commercantTemp = user; + try { + userReff.update(infoUser); + this.uploadModify(infoUser); + firebase.auth().onAuthStateChanged(function (userUpdate) { + if (userUpdate) { + + /* + if (userCurrentFB.email !== infoUser.email){ + console.log('email diferrent '); + userUpdate.updateEmail(infoUser.email); + }*/ + /*if (confirmOldPassword !== infoUser.password) { + console.log('mdp diferrent '); + const passWRef = firebase.database().ref().child('Commercant').child(commercantTemp.uid).child('password'); + passWRef.set(infoUser.password); + userUpdate.updatePassword(infoUser.password); + }*/ + console.log(''); + } else { + console.log('Error'); + } + + }); + } catch (e) { + console.log('Error: ' + e); + } - }); } } diff --git a/src/app/services/opCommercial/op-commercial.service.ts b/src/app/services/opCommercial/op-commercial.service.ts index def5da2..e155097 100644 --- a/src/app/services/opCommercial/op-commercial.service.ts +++ b/src/app/services/opCommercial/op-commercial.service.ts @@ -35,6 +35,15 @@ export class OpCommercialService { ); } + getCommercants(): FirebaseListObservable { + return this.afDb.list('/Commercant/', { + query: { + orderByChild: 'commercialName' + } + } + ); + } + getOpComs(): FirebaseListObservable { return this.afDb.list('/OperationCommercial/', { query: { @@ -74,43 +83,50 @@ export class OpCommercialService { const opComAll = this.getOpComs(); opComAll.forEach(utilisateur => { utilisateur.forEach(monOpCom => { - var todayTemp = new Date(Date.now()); - var debutTemp = new Date(monOpCom.dateDebut); - var finTemp = new Date(monOpCom.dateFin); - if (monOpCom.status !== 'Bloqué') { - if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { - monOpCom.status = 'Active'; - } else { - monOpCom.status = 'Inactive'; + if(monOpCom !== undefined){ + var todayTemp = new Date(Date.now()); + var debutTemp = new Date(monOpCom.dateDebut); + var finTemp = new Date(monOpCom.dateFin); + if (monOpCom.status !== 'Bloqué') { + if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { + monOpCom.status = 'Active'; + } else { + monOpCom.status = 'Inactive'; + } + if (monOpCom.uid !== undefined){ + const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid.toString()).child('status'); + carteStatusRef.set(monOpCom.status); + } } - const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid.toString()).child('status'); - carteStatusRef.set(monOpCom.status); } }); }); } updateCarteEtOpCom(){ - this.updateOpCommStatus(); - this.updateCarteStatus(); + //this.updateOpCommStatus(); + //this.updateCarteStatus(); } updateCarteStatus(){ const carteAll = this.getCartes(); - carteAll.forEach(utilisateur => { utilisateur.forEach(maCarte => { - var todayTemp = new Date(Date.now()); - var debutTemp = new Date(maCarte.dateDebut); - var finTemp = new Date(maCarte.dateFin); - if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { - maCarte.status = 'Active'; - } else { - maCarte.status = 'Inactive'; - } + if(maCarte !== undefined) { + var todayTemp = new Date(Date.now()); + var debutTemp = new Date(maCarte.dateDebut); + var finTemp = new Date(maCarte.dateFin); + if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { + maCarte.status = 'Active'; + } else { + maCarte.status = 'Inactive'; + } + if (maCarte.uid !== undefined){ + const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid.toString()).child('status'); + carteStatusRef.set(maCarte.status); + } - const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid.toString()).child('status'); - carteStatusRef.set(maCarte.status); + } }); }); } From 36d478fa8e26d933de990628dab64a76b5037842 Mon Sep 17 00:00:00 2001 From: Tmadkaud Date: Thu, 12 Oct 2017 16:14:58 +0200 Subject: [PATCH 2/2] update status carte et op ok --- .../opCommercial/op-commercial.service.ts | 119 +++++++++++++----- 1 file changed, 88 insertions(+), 31 deletions(-) diff --git a/src/app/services/opCommercial/op-commercial.service.ts b/src/app/services/opCommercial/op-commercial.service.ts index e155097..fdde743 100644 --- a/src/app/services/opCommercial/op-commercial.service.ts +++ b/src/app/services/opCommercial/op-commercial.service.ts @@ -81,52 +81,109 @@ export class OpCommercialService { updateOpCommStatus() { const opComAll = this.getOpComs(); - opComAll.forEach(utilisateur => { - utilisateur.forEach(monOpCom => { - if(monOpCom !== undefined){ - var todayTemp = new Date(Date.now()); - var debutTemp = new Date(monOpCom.dateDebut); - var finTemp = new Date(monOpCom.dateFin); - if (monOpCom.status !== 'Bloqué') { - if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { - monOpCom.status = 'Active'; - } else { - monOpCom.status = 'Inactive'; - } - if (monOpCom.uid !== undefined){ - const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid.toString()).child('status'); - carteStatusRef.set(monOpCom.status); + opComAll.subscribe(tabOpComs => { + if (tabOpComs.length > 0) { + for (let i = 0; i < tabOpComs.length ; ++i){ + console.log('tabOpComs[i].name' + tabOpComs[i].name); + if(tabOpComs[i].name !== ''){ + let monOpCom = tabOpComs[i]; + console.log('tabOpComs[i].name not vide' + tabOpComs[i].name); + + + + + if (monOpCom !== undefined){ + console.log(monOpCom); + var todayTemp = new Date(Date.now()); + var debutTemp = new Date(monOpCom.dateDebut); + var finTemp = new Date(monOpCom.dateFin); + if (monOpCom.status !== 'Bloqué') { + if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { + if (monOpCom.uid !== undefined && monOpCom.status !== undefined && monOpCom.name !== undefined + && monOpCom.uid !== '' && monOpCom.status !== '' && monOpCom.name !== '') { + console.log(monOpCom.uid); + console.log(monOpCom.status); + monOpCom.status = 'Active'; + } + } else { + if (monOpCom.uid !== undefined && monOpCom.status !== undefined && monOpCom.name !== undefined + && monOpCom.uid !== '' && monOpCom.status !== '' && monOpCom.name !== ''){ + console.log(monOpCom.uid); + console.log(monOpCom.status); + monOpCom.status = 'Inactive'; + } + } + if (monOpCom.uid !== undefined && monOpCom.status !== undefined && monOpCom.name !== undefined + && monOpCom.uid !== '' && monOpCom.status !== '' && monOpCom.name !== '') { + console.log('monOpCom.uid: ' + monOpCom.uid); + console.log('monOpCom.status: ' + monOpCom.status); + const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid).child('status'); + carteStatusRef.set(monOpCom.status); + } + } } + } } + } + }); + opComAll.forEach(utilisateur => { + utilisateur.forEach(monOpCom => { + }); }); } updateCarteEtOpCom(){ - //this.updateOpCommStatus(); - //this.updateCarteStatus(); + this.updateOpCommStatus(); + this.updateCarteStatus(); } updateCarteStatus(){ const carteAll = this.getCartes(); + + carteAll.subscribe(tabCarte => { + if (tabCarte.length > 0) { + for (let i = 0; i < tabCarte.length ; ++i){ + console.log('tabCarte[i].parrainCarte.firstname' + tabCarte[i].parrainCarte.firstname); + if (tabCarte[i].parrainCarte.firstname !== '') { + let maCarte = tabCarte[i]; + + if(maCarte !== undefined) { + var todayTemp = new Date(Date.now()); + var debutTemp = new Date(maCarte.dateDebut); + var finTemp = new Date(maCarte.dateFin); + if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { + if(maCarte.status !== undefined && maCarte.uid !== undefined && maCarte.parrainCarte !== undefined + && maCarte.status !== '' && maCarte.uid !== '' && maCarte.parrainCarte.firstname !== '') { + console.log('maCarte.uid: ' + maCarte.uid); + console.log('maCarte.status: ' + maCarte.status); + maCarte.status = 'Active'; + } + } else { + if (maCarte.status !== undefined && maCarte.uid !== undefined && maCarte.parrainCarte !== undefined + && maCarte.status !== '' && maCarte.uid !== '' && maCarte.parrainCarte.firstname !== '') { + console.log('maCarte.uid: ' + maCarte.uid); + console.log('maCarte.status: ' + maCarte.status); + maCarte.status = 'Inactive'; + } + } + if (maCarte.status !== undefined && maCarte.uid !== undefined && maCarte.parrainCarte !== undefined + && maCarte.status !== '' && maCarte.uid !== '' && maCarte.parrainCarte.firstname !== '') { + console.log('maCarte.uid: ' + maCarte.uid); + console.log('maCarte.status: ' + maCarte.status); + const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid).child('status'); + carteStatusRef.set(maCarte.status); + } + + } + } + } + } + }); carteAll.forEach(utilisateur => { utilisateur.forEach(maCarte => { - if(maCarte !== undefined) { - var todayTemp = new Date(Date.now()); - var debutTemp = new Date(maCarte.dateDebut); - var finTemp = new Date(maCarte.dateFin); - if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { - maCarte.status = 'Active'; - } else { - maCarte.status = 'Inactive'; - } - if (maCarte.uid !== undefined){ - const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid.toString()).child('status'); - carteStatusRef.set(maCarte.status); - } - } }); }); }