File

src/pages/authentication/register/register.ts

Metadata

selector page-register
templateUrl register.html

Index

Properties
Methods

Constructor

constructor(viewCtrl: ViewController, navCtrl: NavController, authService: AuthService, formBuilder: FormBuilder, alertCtrl: AlertController, loadingCtrl: LoadingController, userService: UserService)
Parameters :
Name Type Optional Description
viewCtrl ViewController
navCtrl NavController
authService AuthService
formBuilder FormBuilder
alertCtrl AlertController
loadingCtrl LoadingController
userService UserService

Methods

createAccount
createAccount()

metodo chiamato dalla pagina html alla pressione del tasto 'registrati' verifico se i campi inseriti sono corretti e procedo alla registrazione dell'utente al termine dismetto loading e dismetto view

Returns : void
elementChanged
elementChanged(input: )

chiamato ogni volta che cambio il valore di un campo input NON ricordo a cosa serve!!!!

Parameters :
Name Type Optional Description
input
Returns : void
goBack
goBack()

chiudo il popup di registrazione

Returns : void
ngOnInit
ngOnInit()

imposto espressione regolare per verifica email imposto il form della pagina con i campi da validare (email, psw, firstname, lastname)

Returns : void

Properties

Public alertCtrl
alertCtrl: AlertController
Type : AlertController
Public authService
authService: AuthService
Type : AuthService
Public emailChanged
emailChanged: boolean
Type : boolean
Default value : false
Public formBuilder
formBuilder: FormBuilder
Type : FormBuilder
Public fullnameChanged
fullnameChanged: boolean
Type : boolean
Default value : false
Public loading
loading: any
Type : any
Public loadingCtrl
loadingCtrl: LoadingController
Type : LoadingController
Public navCtrl
navCtrl: NavController
Type : NavController
Public passwordChanged
passwordChanged: boolean
Type : boolean
Default value : false
Public registerForm
registerForm:
Public submitAttempt
submitAttempt: boolean
Type : boolean
Default value : false
Public usernameChanged
usernameChanged: boolean
Type : boolean
Default value : false
Public userService
userService: UserService
Type : UserService
Public viewCtrl
viewCtrl: ViewController
Type : ViewController
import { Component } from '@angular/core';
import { ViewController, NavController, AlertController, LoadingController } from 'ionic-angular';
import { FormBuilder, Validators } from '@angular/forms';

// services
import { AuthService } from '../../../providers/auth-service';
import { UserService } from '../../../providers/user/user';

@Component({
  selector: 'page-register',
  templateUrl: 'register.html'
})
export class RegisterPage {

  public registerForm;
  public usernameChanged: boolean = false;
  public emailChanged: boolean = false;
  public passwordChanged: boolean = false;
  public fullnameChanged: boolean = false;
  public submitAttempt: boolean = false;
  public loading: any;

  constructor(
    public viewCtrl: ViewController, 
    public navCtrl: NavController, 
    public authService: AuthService,  
    public formBuilder: FormBuilder,
    public alertCtrl: AlertController, 
    public loadingCtrl: LoadingController,
    public userService: UserService
  ) {
  }

  /**
   * imposto espressione regolare per verifica email
   * imposto il form della pagina con i campi da validare (email, psw, firstname, lastname)
   */
  ngOnInit() {
    let EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
    this.registerForm = this.formBuilder.group({
      email: ['', Validators.compose([Validators.required, Validators.pattern(EMAIL_REGEXP)])],
      password: ['', Validators.compose([Validators.minLength(6), Validators.required])],
      firstname: ['', Validators.compose([Validators.minLength(2), Validators.required])],
      lastname: ['', Validators.compose([Validators.minLength(2), Validators.required])]
    });
  }
  /**
   * chiamato ogni volta che cambio il valore di un campo input
   * NON ricordo a cosa serve!!!!
   * @param input 
   */
  elementChanged(input){
    let field = input.inputControl.firstname;
    this[field + "Changed"] = true;
  }
  /**
   * metodo chiamato dalla pagina html alla pressione del tasto 'registrati'
   * verifico se i campi inseriti sono corretti e procedo alla registrazione dell'utente
   * al termine dismetto loading e dismetto view
   */
  createAccount(){
    this.submitAttempt = true;
    if (!this.registerForm.valid){
      // console.log(this.registerForm.value);
      // non faccio nulla perchè gli errori sono evidenziati in rosso nella pg html
    } else {
      console.log("createAccount", this.authService);
      this.authService.register(this.registerForm.value.email, this.registerForm.value.password, this.registerForm.value.firstname, this.registerForm.value.lastname)
      .then((newUser) => {
        // creo current user detail
        console.log("register",newUser.uid, this.userService);
        this.userService.saveCurrentUserDetail(newUser.uid, this.registerForm.value.email, this.registerForm.value.firstname, this.registerForm.value.lastname)
        .then(_ => {
          console.log('success saveCurrentUserDetail');
          this.loading.dismiss().then( () => {
            //dismetto la modale ricarico lista conversazioni passando user
            //this.loading.dismiss();
            this.viewCtrl.dismiss({animate: false, duration: 0});
          });
        }) 
        .catch(err => {
          console.log(err,'ERROR saveCurrentUserDetail');
          this.authService.delete();
        });
      })
      .catch(error => {
        console.log(error, 'Registrazione authentication fallita');
        this.loading.dismiss().then( () => {
          console.log("dismetto con errore");
          let alert = this.alertCtrl.create({
            message: error.message,
            buttons: [
              {
                text: "Ok",
                role: 'cancel'
              }
            ]
          });
          alert.present();
        });
      });  
      // attivo il loading
      this.loading = this.loadingCtrl.create({
        dismissOnPageChange: true,
      });
      this.loading.present();
    }
  }
  /**
   * chiudo il popup di registrazione
   */
  goBack(){
    this.navCtrl.pop({animate: false, duration: 0});    
  }

}
<!--
  Generated template for the Register page.

  See http://ionicframework.com/docs/components/#navigation for more info on
  Ionic pages and navigation.
-->
<ion-header>

  <ion-navbar>
    <ion-title>Registrazione</ion-title>
    <ion-buttons left>
        <button ion-button icon-only (click)="goBack()">
          <ion-icon name="close"></ion-icon>
        </button>
      </ion-buttons>
  </ion-navbar>

</ion-header>



<ion-content padding class="sample-modal-page">
  <div class="content-page">
  <!-- <h2>Registrazione</h2> -->
  
  <form [formGroup]="registerForm" (submit)="createAccount()" novalidate>
    <!-- <ion-item>
      <ion-label stacked>Username</ion-label>
      <ion-input #username formControlName="username" type="text" (change)="elementChanged(username)"
        placeholder="Your username"
        [class.invalid]="!registerForm.controls.username.valid && (usernameChanged || submitAttempt)"></ion-input>
    </ion-item>
    <ion-item class="error-message" *ngIf="!registerForm.controls.username.valid  && (usernameChanged || submitAttempt)">
      <p>Please enter a valid username.</p>
    </ion-item> -->

    <ion-item>
      <ion-label stacked>Email</ion-label>
      <ion-input #email formControlName="email" type="email" (change)="elementChanged(email)"
        placeholder="Il tuo indirizzo email"
        [class.invalid]="!registerForm.controls.email.valid && (emailChanged || submitAttempt)"></ion-input>
    </ion-item>
    <div class="div-error-message">
    <ion-item class="error-message" *ngIf="!registerForm.controls.email.valid  && (emailChanged || submitAttempt)">
      <p>Inserisci un indirizzo email valido.</p>
    </ion-item>
    </div>

    <ion-item>
      <ion-label stacked>Password</ion-label>
      <ion-input #password formControlName="password" type="password" (change)="elementChanged(password)"
        placeholder="La tua password"
        [class.invalid]="!registerForm.controls.password.valid && (passwordChanged || submitAttempt)"></ion-input>
    </ion-item>
    <div class="div-error-message">
    <ion-item class="error-message" *ngIf="!registerForm.controls.password.valid  && (passwordChanged || submitAttempt)">
      <p>La password deve essere di almeno 6 caratteri.</p>
    </ion-item>
    </div>

    <ion-item>
      <ion-label stacked>Nome</ion-label>
      <ion-input #firstname formControlName="firstname" type="text" (change)="elementChanged(firstname)"
        placeholder="Il tuo Nome"
        [class.invalid]="!registerForm.controls.firstname.valid && (nameChanged || submitAttempt)"></ion-input>
    </ion-item>
    <div class="div-error-message">
    <ion-item class="error-message" *ngIf="!registerForm.controls.firstname.valid  && (nameChanged || submitAttempt)">
      <p>Il campo nome non può essere vuoto.</p>
    </ion-item>
    </div>
    <ion-item>
        <ion-label stacked>Cognome</ion-label>
        <ion-input #lastname formControlName="lastname" type="text" (change)="elementChanged(lastname)"
          placeholder="Il tuo cognome"
          [class.invalid]="!registerForm.controls.lastname.valid && (lastnameChanged || submitAttempt)"></ion-input>
      </ion-item>
      <div class="div-error-message">
      <ion-item class="error-message" *ngIf="!registerForm.controls.lastname.valid  && (lastnameChanged || submitAttempt)">
        <p>Il campo cognome non può essere vuoto.</p>
      </ion-item>
      </div>
    <button ion-button block class="full" type="submit">
      Registrati
    </button>
  </form>
  </div>
</ion-content>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""