reset password OK

thierry
Tmadkaud 7 years ago
parent 7508821307
commit a99b49cc7f

@ -0,0 +1,31 @@
<div class="container">
<div class="card">
<div class="well">
<p class="h5 text-center mb-4">Réinitialiser mot de passe</p>
<!--<div> ID: {{ (user | async)?.uid }} </div>
<div> Email: {{ (user | async)?.email }} </div>-->
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" [(ngModel)]="email" placeholder="Email" name="mail" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" #mail="ngModel">
<div *ngIf="mail.errors && mail.errors.pattern && (mail.dirty || mail.touched)" class="alert alert-danger">
Votre <strong>email</strong> est requis et doit avoir ce format : <strong><i>john@gmail.fr</i></strong>.
</div>
</div>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-dark-green" [disabled]="mail.errors" (click)="resetPass()">Réinitialiser mot de passe<i class="fa fa-paper-plane-o ml-1"></i></button>
<!--<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>-->
<button class="btn btn-cyan" (click)="loadHomeComponent()">Retour</button>
</div>
<div *ngIf="emailExist" class="alert alert-danger">
Un <strong>email pour réinitiliser votre mot de passe</strong> vient de vous être envoyé à <strong><i>{{email}}</i></strong>.
</div>
<div *ngIf="emailExist == false" class="alert alert-danger">
L'email <strong><i>{{email}}</i></strong> n'est pas inscrit sur ParraineTesAmis.com
</div>
</div>
</div>
</div>

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ResetPasswordComponent } from './reset-password.component';
describe('ResetPasswordComponent', () => {
let component: ResetPasswordComponent;
let fixture: ComponentFixture<ResetPasswordComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ResetPasswordComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ResetPasswordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,86 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import * as firebase from 'firebase/app';
import { AuthService } from '../../../services/auth/auth.service';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
@Component({
selector: 'app-reset-password',
templateUrl: './reset-password.component.html',
styleUrls: ['./reset-password.component.scss'],
providers: [AuthService]
})
export class ResetPasswordComponent implements OnInit, OnDestroy {
email: string;
emailExist: boolean;
profileDataParrainEmail: FirebaseListObservable<any[]>;
profileDataCommercantEmail: FirebaseListObservable<any[]>;
constructor(private router: Router, private afDb: AngularFireDatabase, private authService: AuthService) {
this.email = '';
}
/*
keyDownFunction(event) {
if(event.keyCode === 13) {
console.log('you just clicked enter');
// rest of your code
if (this.email !== ''){
this.resetPass();
}
}
}*/
resetPass() {
if (this.email !== '') {
console.log(this.emailExist);
this.verifEmail(this.email);
console.log(this.emailExist);
}
}
verifEmail(email: string){
let parrainExistPas = false;
let commercantExistPas = false;
this.profileDataParrainEmail = this.afDb.list('/Parrain/', {
query: {
orderByChild: 'email',
equalTo: email
}
}
);
this.profileDataParrainEmail.subscribe(snapshot => {
if (snapshot.length > 0) {
firebase.auth().sendPasswordResetEmail(email);
this.emailExist = true;
} else {
parrainExistPas = true;
}
});
this.profileDataCommercantEmail = this.afDb.list('/Commercant/', {
query: {
orderByChild: 'email',
equalTo: email
}
}
);
this.profileDataCommercantEmail.subscribe(snapshot => {
if (snapshot.length > 0) {
firebase.auth().sendPasswordResetEmail(email);
this.emailExist = true;
} else {
commercantExistPas = true;
if (parrainExistPas && commercantExistPas) {
this.emailExist = false;
}
}
});
}
loadHomeComponent() {
this.router.navigate(['/']);
}
ngOnInit() {
}
ngOnDestroy() {
this.email = '';
}
}
Loading…
Cancel
Save