Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b446f3b
commit 6889635
Showing
1 changed file
with
74 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,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(); | ||
} | ||
} |