Skip to content

Commit

Permalink
Step 5.9: Create LoginComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and DAB0mB committed Dec 16, 2016
1 parent b446f3b commit 6889635
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions client/imports/pages/auth/login.component.ts
@@ -0,0 +1,74 @@
import { Component } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';
import { Accounts } from 'meteor/accounts-base';
import { VerificationComponent } from './verification.component';
import template from './login.component.html';
import style from "./login.component.scss";

@Component({
selector: 'login',
template,
styles: [
style
]
})
export class LoginComponent {
phone = '';

constructor(
private navCtrl: NavController,
private 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 6889635

Please sign in to comment.