Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 5.14: Add verification component
- Loading branch information
1 parent
1622c37
commit 495abfb
Showing
1 changed file
with
53 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,53 @@ | ||
import { Component, OnInit, NgZone } from '@angular/core'; | ||
import { NavController, NavParams, AlertController } from 'ionic-angular'; | ||
import { Accounts } from 'meteor/accounts-base'; | ||
|
||
@Component({ | ||
selector: 'verification', | ||
templateUrl: 'verification.html' | ||
}) | ||
export class VerificationComponent implements OnInit { | ||
code: string = ''; | ||
phone: string; | ||
|
||
constructor( | ||
public navCtrl: NavController, | ||
public alertCtrl: AlertController, | ||
public zone: NgZone, | ||
public 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(); | ||
} | ||
} |