Pushing data to create user account node in firebase


#1

menustateProvider:

/**

  • Created by brice on 5/30/18.
    */
    //import { HttpClient } from ‘@angular/common/http’;
    import { Injectable } from ‘@angular/core’;
    import { Http } from ‘@angular/http’;
    import ‘rxjs/add/operator/map’;
    import * as firebase from ‘firebase’;

@Injectable()
export class MenustateProvider {
privacy:boolean=false;
infos:boolean=true;
pics:boolean=false;
titre:string=“Account settings”;

public fireAuth: any;
public userProfile: any;

constructor(private http: Http) {

this.fireAuth = firebase.auth();
this.userProfile = firebase.database().ref('/users');

}

loginUserService(email: string, password: string): any {
return this.fireAuth.signInWithEmailAndPassword(email, password);
}

registerUserService(dateNaissance : any, telephone: any, password: string, pays: any, pseudo: string, email: string){

return this.fireAuth.createUserWithEmailAndPassword(email, password).then((newUser) => {
  //sign in the user
  this.fireAuth.signInWithEmailAndPassword(email, password).then((authenticatedUser) => {
    //successful login, create user profile
    this.userProfile.child(authenticatedUser.uid).set( {dateNaissance : dateNaissance, telephone : telephone, password : password, pays : pays, pseudo : pseudo, email : email});
  });
});

}

forgotpasswordUSer(email: string) {
return this.fireAuth.sendPasswordResetEmail(email);
}

}

register.ts:
import { Component, ViewChild } from ‘@angular/core’;
import { IonicPage, NavController, NavParams,Slides,LoadingController, ToastController } from ‘ionic-angular’;
//import * as firebase from ‘firebase’;
import { HomePage} from ‘…/home/home’
//Import of UsersService
import { MenustateProvider } from ‘…/…/providers/menustate/menustate’;

@IonicPage()
@Component({
selector: ‘page-register’,
templateUrl: ‘register.html’,
providers: [MenustateProvider]
})
export class RegisterPage {
public dateNaissance : any;
public telephone : any;
public password : string;
public pays : any;
public pseudo : string;
public email : string;

private numero:number=0;
@ViewChild(Slides) slide:Slides;

constructor(public menustateProvider : MenustateProvider,public navCtrl: NavController, public navParams: NavParams, public loadingCtrl: LoadingController, public toastCtrl: ToastController) {
this.numero=0;
}

register(){

var that = this;

var loader = this.loadingCtrl.create({
  content: "Please wait...",
  duration: 3000
});
loader.present();


this.menustateProvider.registerUserService(this.uid, this.dateNaissance, this.telephone, this.password, this.pays, this.pseudo, this.email).then(authData => {
  //successful
  loader.dismiss();
  that.navCtrl.setRoot(HomePage);

}, error => {
  loader.dismiss();
  // Unable to log in
  let toast = this.toastCtrl.create({
    message: error,
    duration: 3000,
    position: 'top'
  });
  toast.present();

  that.password = ""//empty the password field

});

}
}

register.html:

icebreakt

<h2 class="sub_title" text-center>Se connecter</h2>

<div class="logo">
  <img src="assets/imgs/logo.png" alt="">
</div>

Vous avez un compte ? Connectez-vous


  <ion-slide>

    <ion-datetime cancelText="Annuler" doneText="Ok"text-center class="btn" [(ngModel)]="dateNaissance" name="dateNaissance" required="required" placeholder="Date de naissance">

    </ion-datetime>
    <br/>

    <ion-input text-center type="tel" class="btn" [(ngModel)]="telephone" name="telephone" required="required" placeholder="Téléphone">

    </ion-input>

    <br/>

    <ion-input text-center type="password" class="btn" [(ngModel)]="password" name="password" required="required" placeholder="Mot de passe">

    </ion-input>
  </ion-slide>

  <ion-slide>
    <ion-input text-center type="text" class="btn" [(ngModel)]="pays" name="pays" required="required" placeholder="Pays">

    </ion-input>

    <br/>

    <ion-input type="text" text-center class="btn" [(ngModel)]="pseudo" name="pseudo" required="required" placeholder="Pseudo">

    </ion-input>
    <br/>

    <ion-input text-center type="email" class="btn" [(ngModel)]="email" name="email" required="required" placeholder="email">

    </ion-input>
  </ion-slide>
</ion-slides>
Terminé

<button class=“btn-login pad” (click)=“next()” *ngIf=“this.numero == 0”>

Suivant

[quote=“brice18, post:1, topic:132222, full:true”]
menustateProvider:

/**

  • Created by brice on 5/30/18.
    */
    //import { HttpClient } from ‘@angular/common/http’;
    import { Injectable } from ‘@angular/core’;
    import { Http } from ‘@angular/http’;
    import ‘rxjs/add/operator/map’;
    import * as firebase from ‘firebase’;

@Injectable()
export class MenustateProvider {
privacy:boolean=false;
infos:boolean=true;
pics:boolean=false;
titre:string=“Account settings”;

public fireAuth: any;
public userProfile: any;

constructor(private http: Http) {

this.fireAuth = firebase.auth();
this.userProfile = firebase.database().ref('/users');

}

loginUserService(email: string, password: string): any {
return this.fireAuth.signInWithEmailAndPassword(email, password);
}

registerUserService(dateNaissance : any, telephone: any, password: string, pays: any, pseudo: string, email: string){

return this.fireAuth.createUserWithEmailAndPassword(email, password).then((newUser) => {
  //sign in the user
  this.fireAuth.signInWithEmailAndPassword(email, password).then((authenticatedUser) => {
    //successful login, create user profile
    this.userProfile.child(authenticatedUser.uid).set( {dateNaissance : dateNaissance, telephone : telephone, password : password, pays : pays, pseudo : pseudo, email : email});
  });
});

}

forgotpasswordUSer(email: string) {
return this.fireAuth.sendPasswordResetEmail(email);
}

}

register.ts:
import { Component, ViewChild } from ‘@angular/core’;
import { IonicPage, NavController, NavParams,Slides,LoadingController, ToastController } from ‘ionic-angular’;
//import * as firebase from ‘firebase’;
import { HomePage} from ‘…/home/home’
//Import of UsersService
import { MenustateProvider } from ‘…/…/providers/menustate/menustate’;

@IonicPage()
@Component({
selector: ‘page-register’,
templateUrl: ‘register.html’,
providers: [MenustateProvider]
})
export class RegisterPage {
public dateNaissance : any;
public telephone : any;
public password : string;
public pays : any;
public pseudo : string;
public email : string;

private numero:number=0;
@ViewChild(Slides) slide:Slides;

constructor(public menustateProvider : MenustateProvider,public navCtrl: NavController, public navParams: NavParams, public loadingCtrl: LoadingController, public toastCtrl: ToastController) {
this.numero=0;
}

register(){

var that = this;

var loader = this.loadingCtrl.create({
  content: "Please wait...",
  duration: 3000
});
loader.present();


this.menustateProvider.registerUserService(this.uid, this.dateNaissance, this.telephone, this.password, this.pays, this.pseudo, this.email).then(authData => {
  //successful
  loader.dismiss();
  that.navCtrl.setRoot(HomePage);

}, error => {
  loader.dismiss();
  // Unable to log in
  let toast = this.toastCtrl.create({
    message: error,
    duration: 3000,
    position: 'top'
  });
  toast.present();

  that.password = ""//empty the password field

});

}
}

register.html:

icebreakt

<h2 class="sub_title" text-center>Se connecter</h2>

<div class="logo">
  <img src="assets/imgs/logo.png" alt="">
</div>

Vous avez un compte ? Connectez-vous


  <ion-slide>

    <ion-datetime cancelText="Annuler" doneText="Ok"text-center class="btn" [(ngModel)]="dateNaissance" name="dateNaissance" required="required" placeholder="Date de naissance">

    </ion-datetime>
    <br/>

    <ion-input text-center type="tel" class="btn" [(ngModel)]="telephone" name="telephone" required="required" placeholder="Téléphone">

    </ion-input>

    <br/>

    <ion-input text-center type="password" class="btn" [(ngModel)]="password" name="password" required="required" placeholder="Mot de passe">

    </ion-input>
  </ion-slide>

  <ion-slide>
    <ion-input text-center type="text" class="btn" [(ngModel)]="pays" name="pays" required="required" placeholder="Pays">

    </ion-input>

    <br/>

    <ion-input type="text" text-center class="btn" [(ngModel)]="pseudo" name="pseudo" required="required" placeholder="Pseudo">

    </ion-input>
    <br/>

    <ion-input text-center type="email" class="btn" [(ngModel)]="email" name="email" required="required" placeholder="email">

    </ion-input>
  </ion-slide>
</ion-slides>
Terminé

<button class=“btn-login pad” (click)=“next()” *ngIf=“this.numero == 0”>

Suivant

I have this error when I create an account: Error: Reference.child failed: First argument was an invalid path = “undefined”. Paths must be non-empty strings and can not contain “.”, “#”, “$”, “[”, Or “]”
at validatePathString (http: // localhost: 8117 / build / vendor.js: 138231: 15)
at Reference.child (http: // localhost: 8117 / build / vendor.js: 150548: 17)
at http: // localhost: 8117 / build / main.js: 1165: 35
at e.g (http: // localhost: 8117 / build / vendor.js: 136322: 101)
at Eb (http: // localhost: 8117 / build / vendor.js: 136325: 195)
at Ab (http: // localhost: 8117 / build / vendor.js: 136325: 85)
at y.g.Ub (http: // localhost: 8117 / build / vendor.js: 136324: 303)
at jb (http: // localhost: 8117 / build / vendor.js: 136318: 586)
at t.invoke (http: // localhost: 8117 / build / polyfills.js: 3: 14976)
at Object.onInvoke (http: // localhost: 8117 / build / vendor.js: 5134: 33)