Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 5.13: Add VerificationComponent
- Loading branch information
1 parent
a6a5ea0
commit 437dc7a
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {Component, OnInit, NgZone} from '@angular/core'; | ||
import {NavController, NavParams, AlertController} from 'ionic-angular'; | ||
import {Accounts} from 'meteor/accounts-base'; | ||
import {ProfileComponent} from './profile.component'; | ||
import template from './verification.component.html'; | ||
import style from './verification.component.scss'; | ||
|
||
|
||
@Component({ | ||
selector: 'verification', | ||
template, | ||
styles: [ | ||
style | ||
] | ||
}) | ||
export class VerificationComponent implements OnInit { | ||
code: string = ''; | ||
phone: string; | ||
|
||
constructor( | ||
private navCtrl: NavController, | ||
private alertCtrl: AlertController, | ||
private zone: NgZone, | ||
private navParams: NavParams) {} | ||
|
||
ngOnInit() { | ||
this.phone = this.navParams.get('phone'); | ||
} | ||
|
||
onInputKeypress({keyCode}: KeyboardEvent): void { | ||
if (keyCode == 13) { | ||
this.verify(); | ||
} | ||
} | ||
|
||
verify(): void { | ||
Accounts.verifyPhone(this.phone, this.code, (e: Error) => { | ||
this.zone.run(() => { | ||
if (e) return this.handleError(e); | ||
|
||
this.navCtrl.setRoot(ProfileComponent, {}, { | ||
animate: true | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
private handleError(e: Error): void { | ||
console.error(e); | ||
|
||
const alert = this.alertCtrl.create({ | ||
title: 'Oops!', | ||
message: e.message, | ||
buttons: ['OK'] | ||
}); | ||
|
||
alert.present(); | ||
} | ||
} |