@social-mail/social-mail-client 1.2.645 → 1.2.646

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-client",
3
- "version": "1.2.645",
3
+ "version": "1.2.646",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,12 @@
1
+ import { IVerification } from "./IVerification";
2
+
3
+
4
+ export interface IUserModel {
5
+ emailAddress?: string;
6
+ phoneNumber?: string;
7
+ name?: string;
8
+
9
+ email?: IVerification;
10
+ phone?: IVerification;
11
+ captcha?: IVerification;
12
+ }
@@ -0,0 +1,6 @@
1
+
2
+ export interface IVerification {
3
+ id: any;
4
+ accessCode: string;
5
+ code: string;
6
+ }
@@ -13,6 +13,10 @@ import PhoneEditor from "../../../common/controls/phone-editor/PhoneEditor";
13
13
  import Action from "@web-atoms/core/dist/view-model/Action";
14
14
  import QRCodeControl from "../../../common/controls/qrcode/QRCode";
15
15
  import styled from "@web-atoms/core/dist/style/styled";
16
+ import sleep from "@web-atoms/core/dist/core/sleep";
17
+ import PageNavigator from "@web-atoms/web-controls/dist/PageNavigator";
18
+ import { IUserModel } from "./IUserModel";
19
+ import SiteSignupPage from "./SiteSignupPage";
16
20
 
17
21
  styled.css `
18
22
  & [data-page-element=content] {
@@ -22,22 +26,6 @@ import styled from "@web-atoms/core/dist/style/styled";
22
26
  }
23
27
  `.installGlobal("[site-login-page]");
24
28
 
25
- export interface IVerification {
26
- id: any;
27
- accessCode: string;
28
- code: string;
29
- }
30
-
31
- export interface IUserModel {
32
- emailAddress?: string;
33
- phoneNumber?: string;
34
- name?: string;
35
-
36
- email?: IVerification;
37
- phone?: IVerification;
38
- captcha?: IVerification;
39
- }
40
-
41
29
  const verifyModes = [
42
30
  { label: "Email", value: "email" },
43
31
  { label: "Cell Phone", value: "phone" }
@@ -166,7 +154,7 @@ export default class SiteLoginPage extends ContentPage {
166
154
  smsConfig={ve.smsConfig} />
167
155
  </div>;
168
156
 
169
- for (let index = 0; index < 5; index++) {
157
+ for (let index = 0; index < 100; index++) {
170
158
  const v = await this.entityService.query(VerificationToken, "get", ve.verificationID, ve.accessCode)
171
159
  .firstOrDefault();
172
160
  if (v.verified) {
@@ -177,7 +165,10 @@ export default class SiteLoginPage extends ContentPage {
177
165
  }
178
166
  break;
179
167
  }
168
+ await sleep(5000);
180
169
  }
170
+
171
+ await this.askForSignup();
181
172
  }
182
173
 
183
174
  @Action({ onEvent: "verify-email"})
@@ -191,6 +182,12 @@ export default class SiteLoginPage extends ContentPage {
191
182
  await this.login(vt);
192
183
  return;
193
184
  }
185
+ await this.askForSignup();
186
+ }
187
+
188
+ async askForSignup() {
189
+ const { captcha, email, phone } = this.model;
190
+ PageNavigator.openPage(SiteSignupPage, { captcha, email, phone });
194
191
  }
195
192
 
196
193
  @Action({})
@@ -0,0 +1,199 @@
1
+ import { ContentPage } from "@web-atoms/web-controls/dist/mobile-app/MobileApp";
2
+ import { IUserModel, IVerification } from "../SiteLogin";
3
+ import XNode from "@web-atoms/core/dist/core/XNode";
4
+ import FormField from "@web-atoms/web-controls/dist/basic/FormField";
5
+ import Form from "@web-atoms/web-controls/dist/basic/Form";
6
+ import Bind from "@web-atoms/core/dist/core/Bind";
7
+ import PhoneEditor from "../../../common/controls/phone-editor/PhoneEditor";
8
+ import Action from "@web-atoms/core/dist/view-model/Action";
9
+ import { IVerificationToken, VerificationToken } from "../../../model/model";
10
+ import InjectProperty from "@web-atoms/core/dist/core/InjectProperty";
11
+ import EntityService from "../../../services/EntityService";
12
+ import { EmailIconTextButton } from "../../../common/controls/buttons/IconButton";
13
+ import QRCodeControl from "../../../common/controls/qrcode/QRCode";
14
+ import sleep from "@web-atoms/core/dist/core/sleep";
15
+
16
+ const pending = "⬜";
17
+ const done = "✅";
18
+
19
+ export default class SiteSignupPage extends ContentPage {
20
+
21
+ parameters: IUserModel;
22
+
23
+ model: IUserModel = { emailAddress: "", phoneNumber: "", name: "" };
24
+ emailVerified: string;
25
+ step = 1;
26
+
27
+ verification: IVerificationToken;
28
+
29
+ @InjectProperty
30
+ entityService: EntityService;
31
+
32
+ getHeader() {
33
+ if (this.emailVerified) {
34
+ <div>
35
+ <ol>
36
+ <li>✅ Email Verified</li>
37
+ <li>{this.step > 1 ? done : pending} Add Phone Number</li>
38
+ <li>{this.step > 2 ? done : pending} Confirm Phone Number</li>
39
+ <li>{this.step > 3 ? done : pending} Add Name/Address Details</li>
40
+ </ol>
41
+ </div>;
42
+ }
43
+ return <div>
44
+ <ol>
45
+ <li>✅ Phone Verification</li>
46
+ <li>{this.step > 1 ? done : pending} Add Email Address</li>
47
+ <li>{this.step > 2 ? done : pending} Confirm Email Address</li>
48
+ <li>{this.step > 3 ? done : pending} Name/Address Details</li>
49
+ </ol>
50
+ </div>;
51
+ }
52
+
53
+ async init() {
54
+
55
+ this.model.phone = this.parameters.phone;
56
+ this.model.email = this.parameters.email;
57
+
58
+ const emailVerified = this.parameters.email?.accessCode && this.parameters.email?.code;
59
+
60
+ this.emailVerified = emailVerified;
61
+
62
+ if (emailVerified) {
63
+ await this.askPhoneNumber();
64
+ return;
65
+ }
66
+
67
+ this.renderer = <div>
68
+ <Form>
69
+ {this.getHeader()}
70
+ <div>
71
+ To complete signup, please verify your email address.
72
+ </div>
73
+ <FormField label="Email">
74
+ <input value={Bind.twoWaysImmediate(() => this.model.emailAddress)}/>
75
+ </FormField>
76
+ <div>
77
+ <button data-submit-event="verify-phone">Request Code</button>
78
+ </div>
79
+ </Form>
80
+ </div>;
81
+ }
82
+
83
+ async askPhoneNumber() {
84
+
85
+ this.model.phone = {
86
+ id: "",
87
+ code: "",
88
+ accessCode: ""
89
+ };
90
+
91
+ this.renderer = <div>
92
+ <Form>
93
+ {this.getHeader()}
94
+ <div>
95
+ To complete signup, please verify your phone number.
96
+ </div>
97
+ <FormField label="Cell Phone">
98
+ <PhoneEditor value={Bind.twoWaysImmediate(() => this.model.phoneNumber)}/>
99
+ </FormField>
100
+ <div>
101
+ <button data-submit-event="verify-phone">Verify</button>
102
+ </div>
103
+ </Form>
104
+ </div>;
105
+ }
106
+
107
+ @Action({ onEvent: ""})
108
+ async verifyPhone() {
109
+ this.step = 2;
110
+ const isEmail = !!this.emailVerified;
111
+
112
+ const type = isEmail ? "email" : "sms";
113
+
114
+ const address = isEmail ? this.model.emailAddress : this.model.phoneNumber;
115
+
116
+ const ve = VerificationToken.create({
117
+ type,
118
+ verifyAddresses: address
119
+ });
120
+
121
+ this.verification = ve;
122
+
123
+ await this.entityService.save(ve, (c) => c.include((x) => x.addresses));
124
+
125
+ if (!isEmail) {
126
+ await this.displayPhoneVerification(ve);
127
+ return;
128
+ }
129
+
130
+ this.model.email = {
131
+ id: ve.verificationID,
132
+ accessCode: ve.accessCode,
133
+ code: ""
134
+ };
135
+
136
+ this.renderer = <div>
137
+ <Form>
138
+ {this.getHeader()}
139
+ <FormField label="Email Verification">
140
+ <div>We have sent you the verification code in your email, please enter it again to complete the verification.</div>
141
+ </FormField>
142
+ <FormField label="Code">
143
+ <input value={Bind.twoWaysImmediate(() => this.model.email.code)}/>
144
+ </FormField>
145
+ <div>
146
+ <EmailIconTextButton
147
+ text="Proceed"
148
+ data-submit-event="verify-email"
149
+ />
150
+ </div>
151
+ </Form>
152
+ </div>;
153
+ }
154
+
155
+ @Action({ onEvent: "verify-email"})
156
+ async verifyEmail() {
157
+ const v = this.verification;
158
+ const vt = await this.entityService.invoke(VerificationToken, "verifyCode", v, v.verificationID, v.accessCode, this.model.email.code);
159
+ if (!vt.verified) {
160
+ throw new Error("Verification failed, try again");
161
+ }
162
+ await this.askForSignup();
163
+ }
164
+
165
+ async displayPhoneVerification(ve: IVerificationToken) {
166
+ this.renderer = <div>
167
+ <Form>
168
+ {this.getHeader()}
169
+ <QRCodeControl
170
+ smsConfig={ve.smsConfig} />
171
+ </Form>
172
+ </div>;
173
+
174
+ for (let index = 0; index < 100; index++) {
175
+ const v = await this.entityService.query(VerificationToken, "get", ve.verificationID, ve.accessCode)
176
+ .firstOrDefault();
177
+ if (v.verified) {
178
+ ve.verified = true;
179
+ break;
180
+ }
181
+ await sleep(5000);
182
+ }
183
+ await this.askForSignup();
184
+ }
185
+
186
+ async askForSignup() {
187
+ this.step = 3;
188
+
189
+ this.renderer = <div>
190
+ <Form>
191
+ {this.getHeader()}
192
+ <FormField label="Name">
193
+ <input value={Bind.twoWaysImmediate(() => this.model.name)}/>
194
+ </FormField>
195
+ </Form>
196
+ </div>;
197
+ }
198
+
199
+ }