login, register et profil rectification bug
parent
831fe9f336
commit
6b0055220d
@ -0,0 +1,14 @@
|
||||
<p>
|
||||
Profil
|
||||
</p>
|
||||
|
||||
<div> ID: {{ (user | async)?.uid }} </div>
|
||||
<div> Email: {{ (user | async)?.email }} </div>
|
||||
<div> Salut {{localUser.firstname}} {{localUser.familyname}} {{localUser.uid}} surnommé {{localUser.username}} et bienvenue ! </div>
|
||||
<div> tu es né le {{localUser.birthday.getDate()}}, ton email est {{localUser.email}}</div>
|
||||
<div *ngFor="let user of profileData | async">
|
||||
User is {{user.firstname}}
|
||||
</div>
|
||||
<button (click)="logout()">Logout</button>
|
||||
<button (click)="loadLoginComponent()">Go to login</button>
|
||||
<button (click)="loadHomeComponent()">Go to home</button>
|
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProfilComponent } from './profil.component';
|
||||
|
||||
describe('ProfilComponent', () => {
|
||||
let component: ProfilComponent;
|
||||
let fixture: ComponentFixture<ProfilComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ProfilComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProfilComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,88 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Router } from '@angular/router';
|
||||
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
|
||||
import * as firebase from 'firebase/app';
|
||||
import { AngularFireAuth } from 'angularfire2/auth';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ProfilService } from '../../services/profil/profil.service';
|
||||
import { User } from '../../../User';
|
||||
import {forEach} from "@angular/router/src/utils/collection";
|
||||
import { AuthService } from '../../services/auth/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'profil',
|
||||
styleUrls: ['./profil.component.scss'],
|
||||
templateUrl: './profil.component.html',
|
||||
providers: [AuthService]
|
||||
})
|
||||
|
||||
export class ProfilComponent implements OnInit, OnDestroy {
|
||||
|
||||
user: Observable<firebase.User>;
|
||||
localUser: User;
|
||||
profileData: FirebaseListObservable<User[]>;
|
||||
|
||||
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
|
||||
private router: Router, private authService: AuthService) {
|
||||
|
||||
this.user = afAuth.authState;
|
||||
|
||||
this.user.subscribe(
|
||||
(auth) => {
|
||||
console.log('bouyaka auth.uid: ' + auth.uid.toString());
|
||||
|
||||
this.profileData = this.afDb.list('/users/', {
|
||||
query: {
|
||||
orderByChild: 'uid',
|
||||
equalTo: auth.uid.toString()
|
||||
}
|
||||
}
|
||||
);
|
||||
this.profileData.forEach(utilisateur => {
|
||||
utilisateur.forEach( element => {
|
||||
this.localUser = element;
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.authService.logout();
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
|
||||
loadLoginComponent() {
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
|
||||
loadHomeComponent() {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.localUser = {
|
||||
uid: '',
|
||||
email: '',
|
||||
emailVerified: false,
|
||||
password: '',
|
||||
familyname: '',
|
||||
firstname: '',
|
||||
username: '',
|
||||
birthday: new Date(),
|
||||
idCard: '',
|
||||
secretCode: '',
|
||||
status: ''
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue