forked from anchetaWern/ionic2-auth-app
/
signup-page.ts
68 lines (51 loc) · 1.5 KB
/
signup-page.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
67
68
import { Component } from '@angular/core';
import { NavController, AlertController, LoadingController } from 'ionic-angular';
import { Auth, UserDetails, IDetailedError } from '@ionic/cloud-angular';
@Component({
selector: 'page-signup-page',
templateUrl: 'signup-page.html',
})
export class SignupPage {
email: string;
password: string;
constructor(public navCtrl: NavController, public auth: Auth, public alertCtrl: AlertController, public loadingCtrl: LoadingController) {
}
register() {
let loader = this.loadingCtrl.create({
content: "Signing you up..."
});
loader.present();
setTimeout(() => {
loader.dismiss();
}, 5000);
let details: UserDetails = {
'email': this.email,
'password': this.password
};
this.auth.signup(details).then((res) => {
loader.dismiss();
let alert = this.alertCtrl.create({
title: "You're registered!",
subTitle: 'You can now login.',
buttons: ['OK']
});
alert.present();
}, (err: IDetailedError<string[]>) => {
loader.dismiss();
var error_message = '';
for (let e of err.details) {
if (e === 'conflict_email') {
error_message += "Email already exists. <br />";
} else {
error_message += "Invalid credentials. <br />";
}
}
let alert = this.alertCtrl.create({
title: error_message,
subTitle: 'Please try again.',
buttons: ['OK']
});
alert.present();
});
}
}