Merge branch 'thierry' of ssh://git.marbelium.com:10023/Viiciouss/XJC into anis

thierry
Viiciouss 7 years ago
commit ae5d2ddb27

@ -4,6 +4,7 @@ import { AngularFireAuth } from 'angularfire2/auth';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { HomeService } from '../../services/home/home.service'; import { HomeService } from '../../services/home/home.service';
import { OpCommercialService } from '../../services/opCommercial/op-commercial.service'; import { OpCommercialService } from '../../services/opCommercial/op-commercial.service';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
@ -14,10 +15,12 @@ import { OpCommercialService } from '../../services/opCommercial/op-commercial.s
export class HomeComponent implements OnInit { export class HomeComponent implements OnInit {
public loadComponentRegister = false; public loadComponentRegister = false;
public loadComponentLogin = false; public loadComponentLogin = false;
commList: FirebaseListObservable<any[]>;
constructor(public afAuth: AngularFireAuth, private opComService: OpCommercialService, private router: Router) { constructor(public afAuth: AngularFireAuth, private opComService: OpCommercialService, private router: Router) {
try{ try{
opComService.updateCarteEtOpCom(); opComService.updateCarteEtOpCom();
this.commList = this.opComService.getCommercants();
this.commList.subscribe(tabCommercant => console.log(tabCommercant));
}catch (e){ }catch (e){
console.log(e); console.log(e);
} }

@ -19,7 +19,7 @@
<!--<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>--> <!--<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>-->
<button class="btn btn-cyan" (click)="loadHomeComponent()">Retour</button> <button class="btn btn-cyan" (click)="loadHomeComponent()">Retour</button>
</div> </div>
<div *ngIf="emailExist" class="alert alert-danger"> <div *ngIf="emailExist" class="alert alert-success">
Un <strong>email pour réinitiliser votre mot de passe</strong> vient de vous être envoyé à <strong><i>{{email}}</i></strong>. Un <strong>email pour réinitiliser votre mot de passe</strong> vient de vous être envoyé à <strong><i>{{email}}</i></strong>.
</div> </div>
<div *ngIf="emailExist == false" class="alert alert-danger"> <div *ngIf="emailExist == false" class="alert alert-danger">

@ -15,6 +15,7 @@ export class ResetPasswordComponent implements OnInit, OnDestroy {
emailExist: boolean; emailExist: boolean;
profileDataParrainEmail: FirebaseListObservable<any[]>; profileDataParrainEmail: FirebaseListObservable<any[]>;
profileDataCommercantEmail: FirebaseListObservable<any[]>; profileDataCommercantEmail: FirebaseListObservable<any[]>;
constructor(private router: Router, private afDb: AngularFireDatabase) { constructor(private router: Router, private afDb: AngularFireDatabase) {
this.email = ''; this.email = '';
} }

@ -75,6 +75,8 @@ export class LoginComponent implements OnInit, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
this.email = '';
this.password = '';
this.myUser = { this.myUser = {
uid: '', uid: '',
image: new FireImg(), image: new FireImg(),

@ -16,7 +16,7 @@
<ul class="navbar-nav nav-flex-icons"> <ul class="navbar-nav nav-flex-icons">
<li class="nav-item dropdown" dropdown> <li class="nav-item dropdown" dropdown>
<a dropdownToggle mdbRippleRadius type="button" class="nav-link dropdown-toggle waves-light" mdbRippleRadius> <a dropdownToggle mdbRippleRadius type="button" class="nav-link dropdown-toggle waves-light" mdbRippleRadius>
xjc@gmail.com<span class="caret"></span></a> {{this.admin.email}}<span class="caret"></span></a>
<div *dropdownMenu class="dropdown-menu dropdown dropdown-primary" role="menu"> <div *dropdownMenu class="dropdown-menu dropdown dropdown-primary" role="menu">
<a class="dropdown-item waves-light" mdbRippleRadius (click)="logout()">Se déconnecter</a> <a class="dropdown-item waves-light" mdbRippleRadius (click)="logout()">Se déconnecter</a>
</div> </div>

@ -5,6 +5,7 @@ import { AngularFireAuth } from 'angularfire2/auth';
import { AuthService } from '../../../services/auth/auth.service'; import { AuthService } from '../../../services/auth/auth.service';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Admin } from '../../../../models/Admin';
@Component({ @Component({
@ -16,13 +17,28 @@ export class NavAdminComponent implements OnInit {
user: Observable<firebase.User>; user: Observable<firebase.User>;
profileData: FirebaseListObservable<any[]>; profileData: FirebaseListObservable<any[]>;
role: any; role: any;
adminData: FirebaseListObservable<any[]>;
admin: Admin;
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase, constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
private router: Router, private authService: AuthService) { private router: Router, private authService: AuthService) {
this.user = afAuth.authState; this.user = afAuth.authState;
this.admin = new Admin();
this.user.subscribe( this.user.subscribe(
(auth) => { (auth) => {
if (auth) { if (auth) {
this.adminData = this.afDb.list('/Admin/', {
query: {
orderByChild: 'uid',
equalTo: auth.uid
}
}
);
this.adminData.forEach(avantage => {
avantage.forEach(elementavantage => {
this.admin = elementavantage;
console.log(this.admin.email);
});
});
this.profileData = this.afDb.list('/' + auth.displayName + '/', { this.profileData = this.afDb.list('/' + auth.displayName + '/', {
query: { query: {
orderByChild: 'uid', orderByChild: 'uid',

@ -275,6 +275,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this.creerCartePar(); this.creerCartePar();
this.carteEnvoieEncours = true; this.carteEnvoieEncours = true;
this.carteEnvoieOK = true; this.carteEnvoieOK = true;
this.echecRegisterPar = false;
setTimeout(() => { setTimeout(() => {
this.secondaryApp.auth().sendPasswordResetEmail(elementParTemp.email); this.secondaryApp.auth().sendPasswordResetEmail(elementParTemp.email);
this.secondaryApp.auth().currentUser.sendEmailVerification(); this.secondaryApp.auth().currentUser.sendEmailVerification();

@ -18,6 +18,7 @@ import { AuthService } from '../../../services/auth/auth.service';
import { Filleul } from '../../../../models/Filleul'; import { Filleul } from '../../../../models/Filleul';
import { Scan } from '../../../../models/Scan'; import { Scan } from '../../../../models/Scan';
import { ToastrService } from '../../../typescripts/angular-bootstrap-md/pro'; import { ToastrService } from '../../../typescripts/angular-bootstrap-md/pro';
import { Admin } from '../../../../models/Admin';
@Component({ @Component({
@ -48,7 +49,8 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
scanList: FirebaseListObservable<any[]>; scanList: FirebaseListObservable<any[]>;
adminAvantage: FirebaseListObservable<any[]>; adminAvantage: FirebaseListObservable<any[]>;
filleulExistList: FirebaseListObservable<any[]>; filleulExistList: FirebaseListObservable<any[]>;
adminData: FirebaseListObservable<any[]>;
admin: Admin;
databaseRef: any; databaseRef: any;
filleulTest: Filleul[]; filleulTest: Filleul[];
@ -63,6 +65,7 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase, constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
private router: Router, private opComService: OpCommercialService, private router: Router, private opComService: OpCommercialService,
private route: ActivatedRoute, private toastrService: ToastrService) { private route: ActivatedRoute, private toastrService: ToastrService) {
this.admin = new Admin();
this.isFilleulAnonyme = false; this.isFilleulAnonyme = false;
this.radioFilleul = ''; this.radioFilleul = '';
this.filleulSelect = ''; this.filleulSelect = '';
@ -134,6 +137,17 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
}); });
}); });
// fin si parrain exist non affilié // fin si parrain exist non affilié
this.adminData = this.afDb.list('/Admin/', {
query: {
orderByChild: 'uid'
}
}
);
this.adminData.forEach(avantage => {
avantage.forEach(elementavantage => {
this.admin = elementavantage;
});
});
} }
} }
); );
@ -202,10 +216,11 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
this.avAdmin = elementavantage; this.avAdmin = elementavantage;
}); });
}); });
this.avAdmin = ((+this.avAdmin) + (+this.opComm.avantageParrain)).toString(); this.admin.avantageCumule = ((+this.admin.avantageCumule) + (+this.opComm.avantageParrain)).toString();
//this.avAdmin = ((+this.avAdmin) + (+this.opComm.avantageParrain)).toString();
const adminAvantageRef = this.databaseRef.child('Admin').child('avantageCumule'); const adminAvantageRef = this.databaseRef.child('Admin').child(this.admin.uid).child('avantageCumule');
adminAvantageRef.set(this.avAdmin); adminAvantageRef.set(this.admin.avantageCumule);
//Fin Admin //Fin Admin

@ -24,47 +24,17 @@
</div> </div>
--> -->
<div class="flex-column flex-center">
<div class="btn-block"> <button class="btn btn-deep-orange" style="margin-top: 2%;" (click)="resetPass()">Réinitialiser mot de passe</button>
<button class="btn btn-deep-orange" style="margin-top: 2%;" (click)="modifyPasswordSection()">Modifier Email/Mot de passe</button> <div *ngIf="resetPassEmail" class="alert alert-success">
Un <strong>email pour réinitiliser votre mot de passe</strong> vient de vous être envoyé à <strong><i>{{localUser.email}}</i></strong>.
</div>
</div> </div>
<div class="md-form" style="margin-top: 2%"> <div class="md-form" style="margin-top: 2%">
<i class="fa fa-file-picture-o prefix grey-text"></i> <i class="fa fa-file-picture-o prefix grey-text"></i>
<input type="file" id="orangeForm-File" name="file" style="padding-top: 1%;" accept=".jpg, .jpeg, .png"> <input type="file" id="orangeForm-File" name="file" style="padding-top: 1%;" accept=".jpg, .jpeg, .png">
</div> </div>
<div class="card" style="margin-bottom: 5%" *ngIf="modifiermdp">
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="confirmOldPassword" placeholder="Ancien mot de passe" name="confirmOldPasswordPar" #confirmOldPasswordPar="ngModel">
<div *ngIf="(parrain.password != confirmOldPassword) && (confirmOldPasswordPar.touched)" class="alert alert-danger">
Mot de passe <strong><i>incorrect</i></strong>.
</div>
</div>
<div *ngIf="modifiermdp && (parrain.password === confirmOldPassword)">
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" id="orangeForm-email" [(ngModel)]="parrain.email" placeholder="{{parrain.email}}" name="email" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" #email="ngModel">
<div *ngIf="email.errors && email.errors.pattern && (email.dirty || email.touched)" class="alert alert-danger">
Votre <strong>email</strong> est requis et doit avoir ce format : <strong><i>john@parrain.fr</i></strong>.
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-pass" type="password" [(ngModel)]="newPassword" placeholder="Nouveau mot de passe" name="password" #password= "ngModel" required minlength="5">
<div *ngIf="password.errors && (password.dirty || password.touched)" class="alert alert-danger">
Votre <strong>nouveau mot de passe</strong> doit avoir 5 caractères au minimum.
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="ConfirmPassword" placeholder="Confirmer votre nouveau mot de passe" name="confirmPassword" #confirmPassword="ngModel">
<div *ngIf="(newPassword != ConfirmPassword) && (confirmPassword.touched)" class="alert alert-danger">
Ecrivez le même <strong><i>nouveau mot de passe</i></strong>.
</div>
</div>
</div>
</div>
<div class="md-form"> <div class="md-form">
<i class="fa fa-user prefix grey-text"></i> <i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" [(ngModel)]="parrain.familyname" placeholder="{{parrain.firstname}}"> <input type="text" id="orangeForm-Familyname" [(ngModel)]="parrain.familyname" placeholder="{{parrain.firstname}}">
@ -152,44 +122,16 @@
<div class="flex-column flex-center"> <div class="flex-column flex-center">
<button class="btn btn-deep-orange" style="margin-top: 2%;" (click)="modifyPasswordSection()">Modifier Email/Mot de passe</button> <button class="btn btn-deep-orange" style="margin-top: 2%;" (click)="resetPass()">Réinitialiser mot de passe</button>
<div *ngIf="resetPassEmail" class="alert alert-success">
Un <strong>email pour réinitiliser votre mot de passe</strong> vient de vous être envoyé à <strong><i>{{localUser.email}}</i></strong>.
</div>
</div> </div>
<div class="md-form"> <div class="md-form">
<i class="fa fa-file-picture-o prefix grey-text"></i> <i class="fa fa-file-picture-o prefix grey-text"></i>
<input type="file" id="orangeForm-File" name="file" style="padding-top: 1%;" accept=".jpg, .jpeg, .png"> <input type="file" id="orangeForm-File" name="file" style="padding-top: 1%;" accept=".jpg, .jpeg, .png">
</div> </div>
<div class="card" style="margin-bottom: 5%" *ngIf="modifiermdp">
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="confirmOldPassword" placeholder="Ancien mot de passe" name="confirmOldPasswordPar" #confirmOldPasswordCommer="ngModel">
<div *ngIf="(commercant.password != confirmOldPassword) && (confirmOldPasswordCommer.touched)" class="alert alert-danger">
Mot de passe <strong><i>incorrect</i></strong>.
</div>
</div>
<div *ngIf="modifiermdp && (commercant.password === confirmOldPassword)">
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" id="orangeForm-email" [(ngModel)]="commercant.email" placeholder="{{commercant.email}}" name="email" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" #email="ngModel">
<div *ngIf="email.errors && email.errors.pattern && (email.dirty || email.touched)" class="alert alert-danger">
Votre <strong>email</strong> est requis et doit avoir ce format : <strong><i>john@commercant.fr</i></strong>.
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-pass" type="password" [(ngModel)]="newPassword" placeholder="Nouveau mot de passe" name="password" #password= "ngModel" required minlength="5">
<div *ngIf="password.errors && (password.dirty || password.touched)" class="alert alert-danger">
Votre <strong>nouveau mot de passe</strong> doit avoir 5 caractères au minimum.
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="ConfirmPassword" placeholder="Confirmer le nouveau mot de passe" name="confirmPassword" #confirmPassword="ngModel">
<div *ngIf="(parrain.password != ConfirmPassword) && (confirmPassword.touched)" class="alert alert-danger">
Ecrivez le même <strong><i>nouveau mot de passe</i></strong>.
</div>
</div>
</div>
</div>
<div class="md-form"> <div class="md-form">
<i class="fa fa-user prefix grey-text"></i> <i class="fa fa-user prefix grey-text"></i>

@ -32,8 +32,11 @@ export class EditProfilComponent implements OnInit, OnDestroy {
minDateTimeTest: Date; minDateTimeTest: Date;
maxDateTimeTest: Date; maxDateTimeTest: Date;
parrainDateTimeTest: Date; parrainDateTimeTest: Date;
userCurrentFB: firebase.User;
resetPassEmail: boolean;
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase, constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
private router: Router, private authService: AuthService ) { private router: Router, private authService: AuthService ) {
this.resetPassEmail = false;
this.localUser = new User(); this.localUser = new User();
this.parrain = new Parrain(); this.parrain = new Parrain();
this.commercant = new Commercant(); this.commercant = new Commercant();
@ -49,6 +52,7 @@ export class EditProfilComponent implements OnInit, OnDestroy {
this.user.subscribe( this.user.subscribe(
(auth) => { (auth) => {
if (auth) { if (auth) {
this.userCurrentFB = auth;
this.profileData = this.afDb.list('/' + auth.displayName + '/', { this.profileData = this.afDb.list('/' + auth.displayName + '/', {
query: { query: {
orderByChild: 'uid', orderByChild: 'uid',
@ -101,23 +105,35 @@ export class EditProfilComponent implements OnInit, OnDestroy {
modifyProfile() { modifyProfile() {
if (this.newPassword === '') { if (this.newPassword === '') {
if (this.localUser.status === 'Parrain') { 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') { } 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(); this.goToProfil();
} else { } else {
if (this.localUser.status === 'Parrain') { if (this.localUser.status === 'Parrain') {
this.parrain.password = this.newPassword; 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') { } else if (this.localUser.status === 'Commercant') {
this.commercant.password = this.newPassword; 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(); 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() { goToProfil() {
this.router.navigate(['/profil']); this.router.navigate(['/profil']);
} }
@ -154,13 +170,13 @@ export class EditProfilComponent implements OnInit, OnDestroy {
if (auth) { if (auth) {
console.log(auth.uid); console.log(auth.uid);
} else { } else {
this.router.navigate(['/']); // this.router.navigate(['/']);
} }
}); });
} catch (e) { } catch (e) {
// No content response.. // No content response..
console.log(e); console.log(e);
this.router.navigate(['/']); // this.router.navigate(['/']);
} }
} }

@ -95,7 +95,7 @@
<div *ngIf="echecRegisterPar" class="alert alert-danger"> <div *ngIf="echecRegisterPar" class="alert alert-danger">
Erreur: Un compte avec cet <strong>email</strong> existe déjà. Erreur: Un compte avec cet <strong>email</strong> existe déjà.
</div> </div>
<div *ngIf="(echecRegisterCom !== true) && test" class="alert alert-danger"> <div *ngIf="(echecRegisterCom !== true) && test" class="alert alert-success">
<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> ! <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>
</div> </div>
@ -162,7 +162,7 @@
<div *ngIf="echecRegisterCom" class="alert alert-danger"> <div *ngIf="echecRegisterCom" class="alert alert-danger">
Erreur: Un compte avec cet <strong>email</strong> existe déjà. Erreur: Un compte avec cet <strong>email</strong> existe déjà.
</div> </div>
<div *ngIf="test && (echecRegisterCom !== true)" class="alert alert-danger"> <div *ngIf="test && (echecRegisterCom !== true)" class="alert alert-success">
<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> ! <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>
</div> </div>

@ -81,8 +81,9 @@ export class AuthService {
this.parrain = elementParrain; this.parrain = elementParrain;
this.utilisateur = elementParrain; this.utilisateur = elementParrain;
if (/*user.emailVerified*/true){ if (/*user.emailVerified*/true){
firebase.auth().onAuthStateChanged(function (userUpdate) { firebase.auth().onAuthStateChanged(function (userUpdate) {
if(userUpdate !== null){ if (userUpdate !== null){
userUpdate.updateProfile({ userUpdate.updateProfile({
displayName: elementParrain.status, displayName: elementParrain.status,
photoURL: elementParrain.image.downloadURL photoURL: elementParrain.image.downloadURL
@ -90,6 +91,10 @@ export class AuthService {
} }
}); });
if (this.utilisateur.status === 'Parrain') { 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']); this.router.navigate(['/carteParrainageComponent']);
} else if (this.utilisateur.status === 'Commercant') { } else if (this.utilisateur.status === 'Commercant') {
this.router.navigate(['/opCommercial']); this.router.navigate(['/opCommercial']);
@ -126,6 +131,10 @@ export class AuthService {
if (this.utilisateur.status === 'Parrain') { if (this.utilisateur.status === 'Parrain') {
this.router.navigate(['/carteParrainageComponent']); this.router.navigate(['/carteParrainageComponent']);
} else if (this.utilisateur.status === 'Commercant') { } 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']); this.router.navigate(['/opCommercial']);
} }
}/*else{ }/*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']); this.router.navigate(['/demandeOpCommercialAdmin']);
} }
}else { }else {
@ -210,15 +219,22 @@ export class AuthService {
const folder = this.folder; const folder = this.folder;
const path = `${this.folder}`; const path = `${this.folder}`;
const iRef = storageRef.child(path); 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) { firebase.auth().onAuthStateChanged(function (userUpdate) {
if (userUpdate !== null){ 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') { if (infoUser.status === 'Parrain') {
const userRef = this.databaseRef.child('Parrain').child(user.uid); const userRef = this.databaseRef.child('Parrain').child(user.uid);
const parrainTemp = user;
infoUser.uid = user.uid; 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') { }else if (infoUser.status === 'Commercant') {
const userReff = this.databaseRef.child('Commercant').child(user.uid); const userReff = this.databaseRef.child('Commercant').child(user.uid);
infoUser.uid = user.uid; infoUser.uid = user.uid;
userReff.update(infoUser); const commercantTemp = user;
this.uploadModify(infoUser); try {
firebase.auth().onAuthStateChanged(function (userUpdate) { userReff.update(infoUser);
userUpdate.updateEmail(infoUser.email); this.uploadModify(infoUser);
userUpdate.updatePassword(infoUser.password); firebase.auth().onAuthStateChanged(function (userUpdate) {
if (userUpdate) { if (userUpdate) {
console.log('');
} else { /*
console.log('Error'); 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);
}
});
} }
} }

@ -35,6 +35,15 @@ export class OpCommercialService {
); );
} }
getCommercants(): FirebaseListObservable<any> {
return this.afDb.list('/Commercant/', {
query: {
orderByChild: 'commercialName'
}
}
);
}
getOpComs(): FirebaseListObservable<any> { getOpComs(): FirebaseListObservable<any> {
return this.afDb.list('/OperationCommercial/', { return this.afDb.list('/OperationCommercial/', {
query: { query: {
@ -72,20 +81,55 @@ export class OpCommercialService {
updateOpCommStatus() { updateOpCommStatus() {
const opComAll = this.getOpComs(); const opComAll = this.getOpComs();
opComAll.forEach(utilisateur => { opComAll.subscribe(tabOpComs => {
utilisateur.forEach(monOpCom => { if (tabOpComs.length > 0) {
var todayTemp = new Date(Date.now()); for (let i = 0; i < tabOpComs.length ; ++i){
var debutTemp = new Date(monOpCom.dateDebut); console.log('tabOpComs[i].name' + tabOpComs[i].name);
var finTemp = new Date(monOpCom.dateFin); if(tabOpComs[i].name !== ''){
if (monOpCom.status !== 'Bloqué') { let monOpCom = tabOpComs[i];
if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { console.log('tabOpComs[i].name not vide' + tabOpComs[i].name);
monOpCom.status = 'Active';
} else {
monOpCom.status = 'Inactive';
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);
}
}
}
} }
const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid.toString()).child('status');
carteStatusRef.set(monOpCom.status);
} }
}
});
opComAll.forEach(utilisateur => {
utilisateur.forEach(monOpCom => {
}); });
}); });
} }
@ -98,19 +142,48 @@ export class OpCommercialService {
updateCarteStatus(){ updateCarteStatus(){
const carteAll = this.getCartes(); 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 => { carteAll.forEach(utilisateur => {
utilisateur.forEach(maCarte => { 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';
}
const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid.toString()).child('status');
carteStatusRef.set(maCarte.status);
}); });
}); });
} }

Loading…
Cancel
Save