register login avec verification parfait profil commercant et parrain

thierry
Tmadkaud 7 years ago
parent 9429287744
commit 0b3df7fae3

@ -6,7 +6,11 @@ import * as firebase from 'firebase/app';
import { AngularFireAuth } from 'angularfire2/auth';
import { FormsModule } from '@angular/forms';
import { LoginService } from '../../services/login/login.service';
import { User } from '../../../models/User';
import { Parrain } from '../../../models/Parrain';
import { Commercant } from '../../../models/Commercant';
import {forEach} from "@angular/router/src/utils/collection";
import { AuthService } from '../../services/auth/auth.service';
@ -20,6 +24,8 @@ export class LoginComponent implements OnInit, OnDestroy {
email: string;
password: string;
myUser: User;
parrain: Parrain;
commercant: Commercant;
user: Observable<firebase.User>;
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
@ -55,12 +61,6 @@ export class LoginComponent implements OnInit, OnDestroy {
email: '',
emailVerified: false,
password: '',
familyname: '',
firstname: '',
username: '',
birthday: new Date(),
idCard: '',
secretCode: '',
status: ''
};

@ -4,11 +4,51 @@
<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}}, ton email est {{localUser.email}}</div>
<div *ngFor="let user of profileData | async">
User is {{user.firstname}}
<div> Statut: {{ (user | async)?.displayName }} </div>
<div *ngIf="(user | async)?.displayName === 'Parrain'" class="alert alert-danger">
<div>
<p>Salut {{localUser.firstname}} {{localUser.familyname}} {{localUser.uid}} </p>
<ul>
<li>status : {{localUser.status}}</li>
<li>email : {{localUser.email}}</li>
<li>emailVerified : {{localUser.emailVerified}}</li>
<li>password : {{localUser.password}}</li>
<li>familyname : {{localUser.familyname}}</li>
<li>firstname : {{localUser.firstname}}</li>
<li>sex : {{localUser.sex}}</li>
<li>birthday : {{localUser.birthday}}</li>
<li>telephone : {{localUser.telephone}}</li>
<li>idCard : {{localUser.idCard}}</li>
<li>secretCode : {{localUser.secretCode}}</li>
</ul>
</div>
<div *ngFor="let user of profileData | async">
User is {{user.firstname}}
</div>
</div>
<div *ngIf="(user | async)?.displayName === 'Commercant'" class="alert alert-danger">
<div>
<p>Salut {{localUser.commercialName}} {{localUser.uid}} </p>
<ul>
<li>raisonSociale : {{localUser.raisonSociale}}</li>
<li>siret : {{localUser.siret}}</li>
<li>email : {{localUser.email}}</li>
<li>emailVerified : {{localUser.emailVerified}}</li>
<li>password : {{localUser.password}}</li>
<li>dateInscription : {{localUser.dateInscription}}</li>
<li>status : {{localUser.status}}</li>
</ul>
</div>
<div *ngFor="let user of profileData | async">
User is {{user.commercialName}}
</div>
</div>
<button (click)="logout()">Logout</button>
<button (click)="loadLoginComponent()">Go to login</button>
<button (click)="loadHomeComponent()">Go to home</button>
<button>Cartes</button>

@ -7,7 +7,11 @@ 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 '../../../models/User';
import { Parrain } from '../../../models/Parrain';
import { Commercant } from '../../../models/Commercant';
import {forEach} from "@angular/router/src/utils/collection";
import { AuthService } from '../../services/auth/auth.service';
@ -21,11 +25,17 @@ import { AuthService } from '../../services/auth/auth.service';
export class ProfilComponent implements OnInit, OnDestroy {
user: Observable<firebase.User>;
localUser: User;
profileData: FirebaseListObservable<User[]>;
localUser: any;
parrain: Parrain;
commercant: Commercant;
profileData: FirebaseListObservable<any[]>;
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
private router: Router, private authService: AuthService) {
this.localUser = new User();
this.parrain = new Parrain();
this.commercant = new Commercant();
this.user = afAuth.authState;
@ -33,7 +43,7 @@ export class ProfilComponent implements OnInit, OnDestroy {
(auth) => {
console.log('bouyaka auth.uid: ' + auth.uid.toString());
this.profileData = this.afDb.list('/users/', {
this.profileData = this.afDb.list('/' + auth.displayName + '/', {
query: {
orderByChild: 'uid',
equalTo: auth.uid.toString()
@ -42,7 +52,15 @@ export class ProfilComponent implements OnInit, OnDestroy {
);
this.profileData.forEach(utilisateur => {
utilisateur.forEach( element => {
this.localUser = element;
if (auth.displayName === 'Parrain') {
this.localUser = new Parrain();
this.localUser = element;
this.parrain = element;
}else if (auth.displayName === 'Commercant') {
this.localUser = new Commercant();
this.localUser = element;
this.commercant = element;
}
});
});
}
@ -51,14 +69,6 @@ export class ProfilComponent implements OnInit, OnDestroy {
logout() {
this.authService.logout();
this.router.navigate(['/login']);
}
loadLoginComponent() {
this.router.navigate(['/login']);
}
loadHomeComponent() {
this.router.navigate(['/']);
}
@ -67,6 +77,7 @@ export class ProfilComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
/*
this.localUser = {
uid: '',
email: '',
@ -74,13 +85,45 @@ export class ProfilComponent implements OnInit, OnDestroy {
password: '',
familyname: '',
firstname: '',
username: '',
sex: '',
birthday: new Date(),
telephone: '',
idCard: '',
secretCode: '',
status: ''
};*/
this.localUser = {
uid: '',
email: '',
emailVerified: false,
password: '',
status: ''
};
this.parrain = {
uid: '',
email: '',
emailVerified: false,
password: '',
familyname: '',
firstname: '',
sex: '',
birthday: new Date(),
telephone: '',
idCard: '',
secretCode: '',
status: ''
};
this.commercant = {
uid : '',
raisonSociale : '',
commercialName : '',
siret : '',
email : '',
emailVerified : false,
password : '',
dateInscription : new Date(),
status : ''
};
}
}

@ -2,49 +2,140 @@
<div class="well">
<p class="h5 text-center mb-4">Sign up</p>
<label>
<form class="form-inline">
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="parrain" value="Parrain" [(ngModel)]="currentUser.status">
<label for="parrain">Parrain</label>
</div>
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="commercant" value="Commercant" [(ngModel)]="currentUser.status">
<label for="commercant">Commercant</label>
</div>
</form>
</label>
<!--Si cest un parrain-->
<div *ngIf="currentUser.status === 'Parrain'" class="alert alert-danger">
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" [(ngModel)]="currentUser.familyname" placeholder="Your family name">
<input type="text" id="orangeForm-Familyname" [(ngModel)]="parrain.familyname" placeholder="Family name">
</div>
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Firstname" [(ngModel)]="currentUser.firstname" placeholder="Your firstname">
<input type="text" id="orangeForm-Firstname" [(ngModel)]="parrain.firstname" placeholder="Firstname">
</div>
<form class="form-inline">
<div class="md-form">
<i class="fa fa-venus-mars prefix grey-text"></i>
<input name="group3" type="radio" class="with-gap" id="homme" value="Homme" [(ngModel)]="parrain.sex">
<label for="homme">Homme</label>
</div>
<div class="md-form">
<input name="group3" type="radio" class="with-gap" id="femme" value="Femme" [(ngModel)]="parrain.sex">
<label for="femme">Femme</label>
</div>
</form>
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Username" [(ngModel)]="currentUser.username" placeholder="User name">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" [(ngModel)]="parrain.birthday" placeholder="Birthday">
</div>
<div class="md-form">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" [(ngModel)]="currentUser.birthday" placeholder="Birthday..">
<i class="fa fa-tty prefix grey-text"></i>
<input type="text" id="orangeForm-Username" required minlength="10" [(ngModel)]="parrain.telephone" placeholder="Telephone" name="telephone" #telephone="ngModel">
<div *ngIf="telephone.errors && (telephone.dirty || telephone.touched)" class="alert alert-danger">
<strong>Telephone</strong> must have 10 numbers or more
</div>
</div>
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" id="orangeForm-email" [(ngModel)]="currentUser.email" placeholder="Your email">
<input type="email" id="orangeForm-email" [(ngModel)]="parrain.email" placeholder="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">
Email is required and format should be <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)]="currentUser.password" placeholder="Your password">
</div>
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="client">
<label for="client">Client</label>
<input id="orangeForm-pass" type="password" [(ngModel)]="parrain.password" placeholder="Password" name="password" #password= "ngModel" required minlength="5">
<div *ngIf="password.errors && (password.dirty || password.touched)" class="alert alert-danger">
<strong>Password</strong> must have more than 5 caracteres
</div>
</div>
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="commercant">
<label for="commercant">Commercant</label>
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="ConfirmPasswordParrain" placeholder="Confirm your password" name="confirmPassword" #confirmPassword="ngModel">
<div *ngIf="(parrain.password != ConfirmPasswordParrain) && (confirmPassword.touched)" class="alert alert-danger">
Please write the same of your <strong><i>password</i></strong>.
</div>
</div>
<label>
En cliquant sur Créer un compte, vous acceptez nos Conditions
et indiquez que vous aves lu notre Politique d'utilisation des
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" (click)="register()">Sign up</button>
<button class="btn btn-deep-orange" [disabled]="email.errors || password.errors || (parrain.password != ConfirmPasswordParrain)" (click)="register()">Sign up</button>
<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>
</div>
</div>
<!--Fin Si cest un parrain-->
<!--Si cest un commercant-->
<div *ngIf="currentUser.status === 'Commercant'" class="alert alert-danger">
<div class="md-form">
<i class="fa fa-institution prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" [(ngModel)]="commercant.raisonSociale" placeholder="Raison sociale">
</div>
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Firstname" [(ngModel)]="commercant.commercialName" placeholder="Commercial name">
</div>
<div class="md-form">
<i class="fa fa-info prefix grey-text"></i>
<input type="text" id="orangeForm-Username" [(ngModel)]="commercant.siret" placeholder="Siret" required minlength="14" name="siret" #siret="ngModel">
<div *ngIf="siret.errors && (siret.dirty || siret.touched)" class="alert alert-danger">
<strong>Siret</strong> must have 14 numbers
</div>
</div>
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" id="orangeForm-email" [(ngModel)]="commercant.email" placeholder="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">
Email is required and format should be <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)]="commercant.password" placeholder="Password" name="password" #password= "ngModel" required minlength="5">
<div *ngIf="password.errors && (password.dirty || password.touched)" class="alert alert-danger">
<strong>Password</strong> must have more than 5 caracteres
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="ConfirmPasswordCommercant" placeholder="Confirm your password" name="confirmPassword" #confirmPassword="ngModel">
<div *ngIf="(commercant.password != ConfirmPasswordCommercant) && (confirmPassword.touched)" class="alert alert-danger">
Please write the same of your <strong><i>password</i></strong>.
</div>
</div>
<label>
En cliquant sur Créer un compte, vous acceptez nos Conditions
et indiquez que vous aves lu notre Politique d'utilisation des
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="email.errors || password.errors || (commercant.password != ConfirmPasswordCommercant)" (click)="register()">Sign up</button>
<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>
</div>
</div>
<!--Fin Si cest un commercant-->
</div>
</div>

@ -1,15 +1,11 @@
///<reference path="../../../../node_modules/angularfire2/database/database.d.ts"/>
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import * as firebase from 'firebase/app';
import { AngularFireAuth } from 'angularfire2/auth';
import { FormsModule } from '@angular/forms';
import { RegisterService } from '../../services/register/register.service';
import { AuthService } from '../../services/auth/auth.service';
import { User } from '../../../models/User';
import { Parrain } from '../../../models/Parrain';
import { Commercant } from '../../../models/Commercant';
@Component({
selector: 'app-register',
@ -18,30 +14,42 @@ import { User } from '../../../models/User';
providers: [AuthService]
})
export class RegisterComponent implements OnInit, OnDestroy {
user: Observable<firebase.User>;
userC: firebase.User;
currentUser: User;
email: string;
password: string;
name: string;
parrain: Parrain;
commercant: Commercant;
ConfirmPasswordParrain: String;
ConfirmPasswordCommercant: String;
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase, private router: Router, private authService: AuthService) {
this.user = afAuth.authState;
this.userC = afAuth.auth.currentUser;
constructor(private router: Router, private authService: AuthService) {
this.currentUser = new User();
this.name = '';
this.email = '';
this.password = '';
this.parrain = new Parrain();
this.commercant = new Commercant();
}
register() {
this.authService.signUp(this.currentUser);
if (this.currentUser.status === 'Parrain') {
this.parrain.status = this.currentUser.status;
this.authService.signUp(this.parrain);
}else if (this.currentUser.status === 'Commercant') {
this.commercant.status = this.currentUser.status;
this.authService.signUp(this.commercant);
}
}
loadHomeComponent() {
this.router.navigate(['/']);
}
/*
luhn(str) {
return str.split('').reduceRight(function(prev, curr, idx){
prev = parseInt(prev, 10);
if ((idx + 1) % 2 !== 0) {
curr = (curr * 2).toString().split('').reduce(function(p, c){ return parseInt(p, 10) + parseInt(c, 10)});
}
return prev + parseInt(curr, 10);
}) % 10 === 0;
}
*/
loadLoginComponent() {
this.router.navigate(['/login']);
}
@ -51,18 +59,37 @@ export class RegisterComponent implements OnInit, OnDestroy {
ngOnDestroy() {
this.currentUser = {
uid: '',
email: '',
emailVerified: false,
password: '',
status: ''
};
this.parrain = {
uid: '',
email: '',
emailVerified: false,
password: '',
familyname: '',
firstname: '',
username: '',
sex: '',
birthday: new Date(),
telephone: '',
idCard: '',
secretCode: '',
status: ''
};
this.commercant = {
uid : '',
raisonSociale : '',
commercialName : '',
siret : '',
email : '',
emailVerified : false,
password : '',
dateInscription : new Date(),
status : ''
};
}
}

@ -11,6 +11,8 @@ import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { User } from '../../../models/User';
import { Parrain } from '../../../models/Parrain';
import { Commercant } from '../../../models/Commercant';
@ -19,27 +21,33 @@ export class AuthService {
databaseRef: any;
changeRequest: any;
userModel: User;
parrain: Parrain;
commercant: Commercant;
test: string;
constructor(private http: HttpModule, public afAuth: AngularFireAuth, public afDb: AngularFireDatabase, public router: Router) {
this.databaseRef = firebase.database().ref();
}
saveInfo(currentUser: User, user: firebase.User){
const userRef = this.databaseRef.child('users').child(user.uid);
var userInfo = currentUser;
userInfo.uid = user.uid;
userInfo.email = user.email;
userInfo.emailVerified = user.emailVerified;
userRef.set(userInfo);
// this.router.navigate(['/login']);
saveInfo(user: firebase.User, infoUser: any) {
if (infoUser.status === 'Parrain') {
const userRef = this.databaseRef.child('Parrain').child(user.uid);
// var parrainInfo = infoUser;
infoUser.uid = user.uid;
userRef.set(infoUser);
}else if (infoUser.status === 'Commercant') {
const userReff = this.databaseRef.child('Commercant').child(user.uid);
// var commercantInfo = infoUser;
infoUser.uid = user.uid;
userReff.set(infoUser);
}
}
signIn(email: string, password: string) {
firebase.auth().signInWithEmailAndPassword(email, password).then(user =>{
firebase.auth().signInWithEmailAndPassword(email, password).then(user => {
if (user) {
console.log('salut ' + user.displayName + ' has signed!');
console.log('salut le ' + user.displayName + ' ' + user.email + ' has signed!');
this.router.navigate(['/profil']);
}else {
console.log('error!!');
@ -47,11 +55,11 @@ export class AuthService {
});
}
setUserInfo(currentUser: User, user: firebase.User) {
setUserInfo(user: firebase.User, infoUser: any) {
const imagePath = 'profilImage/!' + user.uid + '/userPic.jpg';
firebase.auth().onAuthStateChanged(function (userUpdate) {
userUpdate.updateProfile({
displayName: currentUser.username,
displayName: infoUser.status,
photoURL: imagePath
});
if (userUpdate) {
@ -61,12 +69,12 @@ export class AuthService {
}
});
this.saveInfo(currentUser, user);
this.saveInfo(user, infoUser);
}
signUp(currentUser: User) {
firebase.auth().createUserWithEmailAndPassword(currentUser.email, currentUser.password).then(userCreate => {
this.setUserInfo(currentUser, userCreate);
signUp(infoUser: any) {
firebase.auth().createUserWithEmailAndPassword(infoUser.email, infoUser.password).then(userCreate => {
this.setUserInfo(userCreate, infoUser);
});
}

@ -8,17 +8,5 @@ import { HttpModule, Headers } from '@angular/http';
@Injectable()
export class LoginService {
user: Observable<firebase.User>;
constructor(private http: HttpModule, public afAuth: AngularFireAuth) {
this.user = afAuth.authState;
}
login(email, password){
return this.afAuth.auth.signInWithEmailAndPassword(email, password);
}
logout() {
return this.afAuth.auth.signOut();
}
constructor() { }
}

@ -1,16 +1,18 @@
export class Commercant
import { User } from './User';
export class Commercant extends User
{
uid: string;
// uid: string;
raisonSociale: string;
commercialName: string;
siret: string;
email: string;
emailVerified: boolean;
password:string;
// email: string;
// emailVerified: boolean;
// password:string;
dateInscription: Date;
status: string;
// status: string;
constructor() {
super();
this.uid = '';
this.raisonSociale = '';
this.commercialName = '';

@ -1,23 +1,26 @@
export class Parrain
import * as firebase from 'firebase/app';
import { User } from './User';
export class Parrain extends User
{
uid: string;
// uid: string;
familyname: string;
firstname: string;
sexe: string;
sex: string;
birthday: Date;
email: string;
emailVerified: boolean;
password:string;
// email: string;
// emailVerified: boolean;
// password:string;
telephone: string;
idCard: string;
secretCode: string;
status: string;
// status: string;
constructor() {
super();
this.uid = '';
this.familyname = '';
this.firstname = '';
this.sexe = '';
this.sex = '';
this.birthday = new Date();
this.email = '';
this.emailVerified = false;
@ -27,6 +30,7 @@ export class Parrain
this.secretCode = '';
this.status = '';
}
/*
addParrain(addStatus, addEmail, addFamilyname, addFirstname) {
this.uid = '';

@ -1,30 +1,37 @@
export class User
{
uid: string;
// familyname: string;
// firstname: string;
// sex: string;
// birthday: Date;
email: string;
emailVerified: boolean;
password: string;
familyname: string;
firstname: string;
username: string;
birthday: Date;
idCard: string;
secretCode: string;
// telephone: string;
// username ne serta a rien
// username: string;
// idCard: string;
// secretCode: string;
status: string;
constructor() {
this.uid = '';
// this.familyname = '';
// this.firstname = '';
// this.sex = '';
// this.birthday = new Date();
this.email = '';
this.emailVerified = false;
this.password = '';
this.familyname = '';
this.firstname = '';
this.username = '';
this.birthday = new Date();
this.idCard = '';
this.secretCode = '';
// this.telephone = '';
// username ne serta a rien
// this.username = '';
// this.idCard = '';
// this.secretCode = '';
this.status = '';
}
/*
addParrain(addStatus, addEmail, addFamilyname, addFirstname) {
this.uid = '';

Loading…
Cancel
Save