Skip to content

Instantly share code, notes, and snippets.

@geykel
Created June 27, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geykel/5aaa8d88076451fae67a6b9bf0ae9e42 to your computer and use it in GitHub Desktop.
Save geykel/5aaa8d88076451fae67a6b9bf0ae9e42 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { NavController, LoadingController, AlertController, Platform } from 'ionic-angular';
import { Facebook } from '@ionic-native/facebook';
import { AuthService } from '../../providers/auth-service';
import { UserModel } from '../../models/user-model';
import { SignUpPage } from '../signup/signup';
import { HomePage } from '../home/home';
@Component({
selector: 'page-signin',
templateUrl: 'signin.html'
})
export class SignInPage {
userModel: UserModel;
constructor(
public navCtrl: NavController,
public loadingCtrl: LoadingController,
public alertCtrl: AlertController,
public authService: AuthService,
public platform: Platform,
public facebook: Facebook) {
this.userModel = new UserModel();
}
signIn() {
let loading = this.loadingCtrl.create({
content: 'Iniciando sesión. Por favor, espere...'
});
loading.present();
this.authService.signInWithEmailAndPassword(this.userModel).then(result => {
loading.dismiss();
this.navCtrl.setRoot(HomePage);
}).catch(error => {
loading.dismiss();
console.log(error);
this.alert('Error', 'Ha ocurrido un error inesperado. Por favor intente nuevamente.');
});
}
signInWithFacebook() {
if (this.platform.is('cordova')) {
return this.facebook.login(['email']).then(result => {
this.authService.signInWithFacebook(result.authResponse.accessToken).then(result => {
this.navCtrl.setRoot(HomePage);
});
});
} else {
return this.authService.signInWithPopup().then(result => {
this.navCtrl.setRoot(HomePage);
});
}
}
signUp() {
this.navCtrl.push(SignUpPage);
}
alert(title: string, message: string) {
let alert = this.alertCtrl.create({
title: title,
subTitle: message,
buttons: ['OK']
});
alert.present();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment