-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup-email.ts
116 lines (101 loc) · 3.55 KB
/
signup-email.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Component, NgZone, ViewChild } from '@angular/core';
import { IonicPage, TextInput, Platform, NavParams, NavController, ViewController, ModalController, ToastController, AlertController, LoadingController, ActionSheetController } from 'ionic-angular';
import { BasePublicPage } from '../../pages/base-public-page/base-public-page';
import { SignupCheckPage } from '../../pages/signup-check/signup-check';
import { SigninUrlPage } from '../../pages/signin-url/signin-url';
import { Email } from '../../models/email';
import { Organization } from '../../models/organization';
import { ApiProvider } from '../../providers/api/api';
import { StorageProvider } from '../../providers/storage/storage';
@IonicPage({
name: 'SignupEmailPage',
segment: 'signup',
defaultHistory: ['SigninUrlPage']
})
@Component({
selector: 'page-signup-email',
templateUrl: 'signup-email.html',
providers: [ ApiProvider, StorageProvider ],
entryComponents:[ SignupCheckPage]
})
export class SignupEmailPage extends BasePublicPage {
@ViewChild('email')
email:TextInput;
showBackButton:boolean = false;
constructor(
protected zone:NgZone,
protected platform:Platform,
protected navParams:NavParams,
protected navController:NavController,
protected viewController:ViewController,
protected modalController:ModalController,
protected toastController:ToastController,
protected alertController:AlertController,
protected loadingController:LoadingController,
protected actionController:ActionSheetController,
protected api:ApiProvider,
protected storage:StorageProvider) {
super(zone, platform, navParams, navController, viewController, modalController, toastController, alertController, loadingController, actionController, storage);
}
ionViewWillEnter() {
super.ionViewWillEnter();
this.showBackButton = this.getParameter<boolean>("showBackButton");
}
ionViewDidEnter() {
super.ionViewDidEnter();
this.analytics.trackPage(this);
if (this.hasParameter('email')) {
this.email.value = decodeURIComponent(this.getParameter('email'));
this.showNext(undefined);
}
}
private showNext(event:any) {
this.logger.info(this, "showNext");
if (this.email.value.length == 0) {
this.showToast("Please enter your email");
setTimeout(() => {
this.email.setFocus();
}, 500);
}
else if (this.email.value.indexOf("@") == -1) {
this.showToast("Please enter a valid email");
setTimeout(() => {
this.email.setFocus();
}, 500);
}
else {
let loading = this.showLoading("Registering...", true);
this.api.registerEmail(this.email.value).then((email:Email) => {
loading.dismiss();
let organization = new Organization({});
organization.email = this.email.value;
this.storage.setOrganization(organization).then((stored:boolean) => {
this.showModal(SignupCheckPage, {
organization: organization
}, {
enableBackdropDismiss: false
});
});
},
(error:any) => {
loading.dismiss();
this.showAlert("Email Signup", error);
});
}
}
private showNextOnReturn(event:any) {
if (this.isKeyReturn(event)) {
this.hideKeyboard();
this.showNext(event);
return false;
}
return true;
}
private signinToOrganization(event:any) {
this.logger.info(this, "signinToOrganization");
this.showModal(SigninUrlPage, {});
}
private closeModal(event:any=null) {
this.hideModal();
}
}