/
login.ts
66 lines (57 loc) · 1.35 KB
/
login.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Component } from '@angular/core';
import { Alert, AlertController, NavController } from 'ionic-angular';
import { PhoneService } from '../../services/phone';
@Component({
selector: 'login',
templateUrl: 'login.html'
})
export class LoginPage {
private phone = '';
constructor(
private alertCtrl: AlertController,
private phoneService: PhoneService,
private navCtrl: NavController
) {}
onInputKeypress({keyCode}: KeyboardEvent): void {
if (keyCode === 13) {
this.login();
}
}
login(phone: string = this.phone): void {
const alert = this.alertCtrl.create({
title: 'Confirm',
message: `Would you like to proceed with the phone number ${phone}?`,
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Yes',
handler: () => {
this.handleLogin(alert);
return false;
}
}
]
});
alert.present();
}
handleLogin(alert: Alert): void {
alert.dismiss().then(() => {
return this.phoneService.verify(this.phone);
})
.catch((e) => {
this.handleError(e);
});
}
handleError(e: Error): void {
console.error(e);
const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});
alert.present();
}
}