Skip to content

Commit

Permalink
Step 5.9: Create login component
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Feb 26, 2017
1 parent c2e0db4 commit 882d00e
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/pages/auth/login.ts
@@ -0,0 +1,67 @@
import { Component } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';

@Component({
selector: 'login',
templateUrl: "login.html"
})
export class LoginComponent {
phone = '';

constructor(
public navCtrl: NavController,
public alertCtrl: AlertController
) {}

onInputKeypress({keyCode}: KeyboardEvent): void {
if (keyCode == 13) {
this.login();
}
}

login(): void {
const alert = this.alertCtrl.create({
title: 'Confirm',
message: `Would you like to proceed with the phone number ${this.phone}?`,
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Yes',
handler: () => {
this.handleLogin(alert);
return false;
}
}
]
});

alert.present();
}

private handleLogin(alert): void {
Accounts.requestPhoneVerification(this.phone, (e: Error) => {
alert.dismiss().then(() => {
if (e) return this.handleError(e);

// this.navCtrl.push(VerificationComponent, {
// phone: this.phone
// });
});
});
}

private handleError(e: Error): void {
console.error(e);

const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});

alert.present();
}
}

0 comments on commit 882d00e

Please sign in to comment.