aio-login 2.0.1 → 2.0.3
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/index.js +9 -1272
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
|
-
import React, { Component, createRef } from 'react';
|
|
5
|
-
import RVD from 'react-virtual-dom';
|
|
6
|
-
import AIOStorage from 'aio-storage';
|
|
7
|
-
import AIOInput from './../../npm/aio-input/aio-input';
|
|
8
|
-
import { getFormInputs } from './../../npm/aio-input/utils';
|
|
9
|
-
import { Icon } from '@mdi/react';
|
|
10
|
-
import { mdiCellphone, mdiLock, mdiLoading, mdiAccount, mdiAccountBoxOutline, mdiEmail, mdiChevronRight } from '@mdi/js';
|
|
11
|
-
import AIOPopup from 'aio-popup';
|
|
12
|
-
import './index.css';
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
-
export default class AIOlogin {
|
|
16
|
-
constructor(props) {
|
|
17
|
-
_defineProperty(this, "render", (p = {}) => {
|
|
18
|
-
let {
|
|
19
|
-
attrs = this.props.attrs,
|
|
20
|
-
profile
|
|
21
|
-
} = p;
|
|
22
|
-
if (profile) {
|
|
23
|
-
if (typeof profile !== 'object' || !Array.isArray(profile.fields) || !profile.fields.length || typeof profile.onSubmit !== 'function') {
|
|
24
|
-
let error = `
|
|
1
|
+
function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:String(t)}function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}import e,{Component as t,createRef as i}from"react";import r from"react-virtual-dom";import o from"aio-storage";import s from"aio-input";import{getFormInputs as n}from"./../../npm/aio-input/utils";import{Icon as l}from"@mdi/react";import{mdiCellphone as a,mdiLock as u,mdiLoading as d,mdiAccount as g,mdiAccountBoxOutline as p,mdiEmail as h,mdiChevronRight as m}from"@mdi/js";import f from"aio-popup";import"./index.css";import{jsx as b}from"react/jsx-runtime";import{jsxs as c}from"react/jsx-runtime";export default class y{constructor(e){_defineProperty(this,"render",(e={})=>{let{attrs:t=this.props.attrs,profile:i}=e;if(i&&("object"!=typeof i||!Array.isArray(i.fields)||!i.fields.length||"function"!=typeof i.onSubmit)){let r=`
|
|
25
2
|
aio-login-error => profile props should be an object contain :
|
|
26
3
|
submitText : string | undefined,
|
|
27
4
|
title : string | undefined,
|
|
@@ -33,1214 +10,18 @@ export default class AIOlogin {
|
|
|
33
10
|
<default field> : (
|
|
34
11
|
"fullname" | "firstname" | "lastname" | "username" | "address" | "email" | "fathername" | "phone" | "mobile" | "postalcode",
|
|
35
12
|
"nationalcode" | "idcode" | "cardbank" | "state" | "city" | "gender" | "married" | "militaryservice" | "location"
|
|
36
|
-
)`;
|
|
37
|
-
alert(error);
|
|
38
|
-
console.log(error);
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return /*#__PURE__*/_jsx(AIOLOGIN, {
|
|
43
|
-
...this.props,
|
|
44
|
-
getActions: ({
|
|
45
|
-
setMode
|
|
46
|
-
}) => this.setMode = setMode,
|
|
47
|
-
profile: profile,
|
|
48
|
-
attrs: attrs
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
let {
|
|
52
|
-
id,
|
|
53
|
-
onAuth,
|
|
54
|
-
onSubmit,
|
|
55
|
-
modes,
|
|
56
|
-
timer,
|
|
57
|
-
checkToken,
|
|
58
|
-
register,
|
|
59
|
-
userId,
|
|
60
|
-
attrs: _attrs,
|
|
61
|
-
forget,
|
|
62
|
-
otpLength
|
|
63
|
-
} = props;
|
|
64
|
-
AIOLoginValidator(props);
|
|
65
|
-
let storage = AIOStorage(`-AIOLogin-${id}`);
|
|
66
|
-
this.setStorage = (key, value) => {
|
|
67
|
-
storage.save({
|
|
68
|
-
name: key,
|
|
69
|
-
value
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
this.getStorage = () => {
|
|
73
|
-
let token = storage.load({
|
|
74
|
-
name: 'token',
|
|
75
|
-
def: false
|
|
76
|
-
});
|
|
77
|
-
let userId = storage.load({
|
|
78
|
-
name: 'userId',
|
|
79
|
-
def: ''
|
|
80
|
-
});
|
|
81
|
-
let userInfo = storage.load({
|
|
82
|
-
name: 'userInfo'
|
|
83
|
-
});
|
|
84
|
-
return {
|
|
85
|
-
token,
|
|
86
|
-
userId,
|
|
87
|
-
userInfo
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
this.setUserInfo = userInfo => {
|
|
91
|
-
this.setStorage('userInfo', userInfo);
|
|
92
|
-
};
|
|
93
|
-
this.getUserInfo = () => {
|
|
94
|
-
return this.getStorage().userInfo;
|
|
95
|
-
};
|
|
96
|
-
this.setToken = token => {
|
|
97
|
-
this.setStorage('token', token);
|
|
98
|
-
};
|
|
99
|
-
this.getToken = () => {
|
|
100
|
-
return this.getStorage().token;
|
|
101
|
-
};
|
|
102
|
-
this.removeToken = () => {
|
|
103
|
-
storage.remove({
|
|
104
|
-
name: 'token'
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
this.getUserId = () => {
|
|
108
|
-
return this.getStorage().userId;
|
|
109
|
-
};
|
|
110
|
-
this.logout = () => {
|
|
111
|
-
this.removeToken();
|
|
112
|
-
window.location.reload();
|
|
113
|
-
};
|
|
114
|
-
this.props = {
|
|
115
|
-
id,
|
|
116
|
-
checkToken,
|
|
117
|
-
onAuth,
|
|
118
|
-
onSubmit,
|
|
119
|
-
modes,
|
|
120
|
-
register,
|
|
121
|
-
userId,
|
|
122
|
-
attrs: _attrs,
|
|
123
|
-
timer,
|
|
124
|
-
forget,
|
|
125
|
-
otpLength,
|
|
126
|
-
getStorage: this.getStorage,
|
|
127
|
-
setStorage: this.setStorage,
|
|
128
|
-
removeToken: this.removeToken,
|
|
129
|
-
setToken: this.setToken,
|
|
130
|
-
getToken: this.getToken,
|
|
131
|
-
getUserId: this.getUserId,
|
|
132
|
-
logout: this.logout
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
class AIOLOGIN extends Component {
|
|
137
|
-
constructor(props) {
|
|
138
|
-
super(props);
|
|
139
|
-
this.state = {
|
|
140
|
-
isTokenChecked: false,
|
|
141
|
-
showReload: false,
|
|
142
|
-
mode: props.mode || props.modes[0],
|
|
143
|
-
loading: false
|
|
144
|
-
};
|
|
145
|
-
props.getActions({
|
|
146
|
-
setMode: this.setMode.bind(this)
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
async checkToken() {
|
|
150
|
-
let {
|
|
151
|
-
getStorage,
|
|
152
|
-
checkToken,
|
|
153
|
-
removeToken
|
|
154
|
-
} = this.props;
|
|
155
|
-
let {
|
|
156
|
-
token,
|
|
157
|
-
userId,
|
|
158
|
-
userInfo
|
|
159
|
-
} = getStorage();
|
|
160
|
-
let result;
|
|
161
|
-
if (typeof token !== 'string') {
|
|
162
|
-
result = false;
|
|
163
|
-
} else {
|
|
164
|
-
try {
|
|
165
|
-
result = await checkToken(token, {
|
|
166
|
-
userId,
|
|
167
|
-
userInfo
|
|
168
|
-
});
|
|
169
|
-
} catch (err) {
|
|
170
|
-
new AIOPopup().addAlert({
|
|
171
|
-
type: 'error',
|
|
172
|
-
text: 'بررسی توکن با خطا روبرو شد',
|
|
173
|
-
subtext: this.getError(err)
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (result === true) {
|
|
178
|
-
this.setMode('auth');
|
|
179
|
-
} else if (result === false) {
|
|
180
|
-
removeToken();
|
|
181
|
-
} else {
|
|
182
|
-
if (typeof result === 'string') {
|
|
183
|
-
new AIOPopup().addAlert({
|
|
184
|
-
type: 'error',
|
|
185
|
-
text: 'بررسی توکن با خطا روبرو شد',
|
|
186
|
-
subtext: result
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
this.setState({
|
|
190
|
-
showReload: true
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
this.setState({
|
|
194
|
-
isTokenChecked: true
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
getError(err) {
|
|
198
|
-
if (typeof err === 'string') {
|
|
199
|
-
return err;
|
|
200
|
-
}
|
|
201
|
-
if (typeof err === 'object') {
|
|
202
|
-
if (typeof err.response === 'object') {
|
|
203
|
-
if (typeof err.response.data === 'object') {
|
|
204
|
-
let {
|
|
205
|
-
message,
|
|
206
|
-
Message
|
|
207
|
-
} = err.response.data;
|
|
208
|
-
return Message || message;
|
|
209
|
-
} else if (typeof err.response.data === 'string') {
|
|
210
|
-
return err.response.data;
|
|
211
|
-
} else {
|
|
212
|
-
return 'error';
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
return err.message || err.Message;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async componentDidMount() {
|
|
220
|
-
let {
|
|
221
|
-
profile
|
|
222
|
-
} = this.props;
|
|
223
|
-
if (profile) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
this.checkToken();
|
|
227
|
-
}
|
|
228
|
-
setLoading(loading) {
|
|
229
|
-
this.setState({
|
|
230
|
-
loading
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
async onSubmit(model) {
|
|
234
|
-
let {
|
|
235
|
-
setStorage,
|
|
236
|
-
onSubmit
|
|
237
|
-
} = this.props;
|
|
238
|
-
let {
|
|
239
|
-
mode: currentMode
|
|
240
|
-
} = this.state;
|
|
241
|
-
let res;
|
|
242
|
-
this.setLoading(true);
|
|
243
|
-
try {
|
|
244
|
-
res = await onSubmit(model, currentMode);
|
|
245
|
-
} catch {
|
|
246
|
-
this.setLoading(false);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
this.setLoading(false);
|
|
250
|
-
if (typeof res === 'string') {
|
|
251
|
-
let text = {
|
|
252
|
-
"OTPNumber": 'ارسال شماره همراه',
|
|
253
|
-
"OTPCode": 'ارسال کد یکبار مصرف',
|
|
254
|
-
"userName": 'ارسال نام کاربری و رمز عبور',
|
|
255
|
-
"phoneNumber": 'ارسال شماره همراه و رمز عبور',
|
|
256
|
-
"email": 'ارسال آدرس ایمیل و رمز عبور',
|
|
257
|
-
"register": 'عملیات ثبت نام'
|
|
258
|
-
}[currentMode];
|
|
259
|
-
text = `${text} با خطا روبرو شد`;
|
|
260
|
-
let subtext = res;
|
|
261
|
-
new AIOPopup().addAlert({
|
|
262
|
-
type: 'error',
|
|
263
|
-
text,
|
|
264
|
-
subtext
|
|
265
|
-
});
|
|
266
|
-
} else {
|
|
267
|
-
if (['OTPNumber', 'phoneNumber', 'userName', 'email'].indexOf(currentMode) !== -1) {
|
|
268
|
-
setStorage('userId', model.login.userId);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async onSubmitProfile(model) {
|
|
273
|
-
let {
|
|
274
|
-
profile
|
|
275
|
-
} = this.props;
|
|
276
|
-
let res;
|
|
277
|
-
this.setLoading(true);
|
|
278
|
-
try {
|
|
279
|
-
res = await profile.onSubmit(model);
|
|
280
|
-
} catch {
|
|
281
|
-
this.setLoading(false);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
this.setLoading(false);
|
|
285
|
-
if (typeof res === 'string') {
|
|
286
|
-
new AIOPopup().addAlert({
|
|
287
|
-
type: 'error',
|
|
288
|
-
text: 'ویرایش پروفایل با خطا روبرو شد',
|
|
289
|
-
subtext: res
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
setMode(mode) {
|
|
294
|
-
this.setState({
|
|
295
|
-
mode
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
render() {
|
|
299
|
-
let {
|
|
300
|
-
otpLength,
|
|
301
|
-
onAuth,
|
|
302
|
-
id,
|
|
303
|
-
timer,
|
|
304
|
-
modes,
|
|
305
|
-
userId,
|
|
306
|
-
register = {},
|
|
307
|
-
profile,
|
|
308
|
-
attrs = {},
|
|
309
|
-
forget,
|
|
310
|
-
getStorage,
|
|
311
|
-
logout,
|
|
312
|
-
splash = () => null
|
|
313
|
-
} = this.props;
|
|
314
|
-
let {
|
|
315
|
-
isTokenChecked,
|
|
316
|
-
showReload,
|
|
317
|
-
mode,
|
|
318
|
-
loading
|
|
319
|
-
} = this.state;
|
|
320
|
-
if (profile) {
|
|
321
|
-
let props = {
|
|
322
|
-
timer,
|
|
323
|
-
id,
|
|
324
|
-
attrs,
|
|
325
|
-
userId,
|
|
326
|
-
loading,
|
|
327
|
-
profile,
|
|
328
|
-
onSubmitProfile: this.onSubmitProfile.bind(this)
|
|
329
|
-
};
|
|
330
|
-
return /*#__PURE__*/_jsx(LoginForm, {
|
|
331
|
-
...props
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
if (showReload) {
|
|
335
|
-
return /*#__PURE__*/_jsx("div", {
|
|
336
|
-
className: "aio-login-reload",
|
|
337
|
-
children: /*#__PURE__*/_jsx("button", {
|
|
338
|
-
onClick: () => window.location.reload(),
|
|
339
|
-
children: "\u0628\u0627\u0631\u06AF\u0630\u0627\u0631\u06CC \u0645\u062C\u062F\u062F"
|
|
340
|
-
})
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
//اگر هنوز توکن چک نشده ادامه نده
|
|
344
|
-
if (!isTokenChecked) {
|
|
345
|
-
return splash();
|
|
346
|
-
}
|
|
347
|
-
//اگر توکن چک شده و توکن ولید بوده onAuth رو کال کن و ادامه نده
|
|
348
|
-
if (mode === 'auth') {
|
|
349
|
-
//برای جلوگیری از لوپ بی نهایت فقط یکبار onAuth رو کال کن
|
|
350
|
-
if (!this.reportedAuthToParent) {
|
|
351
|
-
this.reportedAuthToParent = true;
|
|
352
|
-
let {
|
|
353
|
-
token,
|
|
354
|
-
userId,
|
|
355
|
-
userInfo
|
|
356
|
-
} = getStorage();
|
|
357
|
-
onAuth({
|
|
358
|
-
token,
|
|
359
|
-
userId,
|
|
360
|
-
userInfo,
|
|
361
|
-
logout
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
return splash();
|
|
365
|
-
}
|
|
366
|
-
// وقتی به اینجا رسیدی یعنی توکن قطعا چک شده و ولید نبوده پس لاگین رو رندر کن
|
|
367
|
-
return /*#__PURE__*/_jsx(LoginForm, {
|
|
368
|
-
forget,
|
|
369
|
-
timer,
|
|
370
|
-
otpLength,
|
|
371
|
-
id,
|
|
372
|
-
modes,
|
|
373
|
-
attrs,
|
|
374
|
-
userId,
|
|
375
|
-
register,
|
|
376
|
-
loading,
|
|
377
|
-
mode,
|
|
378
|
-
onSubmit: this.onSubmit.bind(this),
|
|
379
|
-
onChangeMode: this.setMode.bind(this)
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
class LoginForm extends Component {
|
|
384
|
-
constructor(props) {
|
|
385
|
-
super(props);
|
|
386
|
-
this.storage = AIOStorage(`-AIOLogin-${props.id}`);
|
|
387
|
-
let {
|
|
388
|
-
timer = 30
|
|
389
|
-
} = props;
|
|
390
|
-
this.state = {
|
|
391
|
-
timer,
|
|
392
|
-
recode: false,
|
|
393
|
-
tab: 'login',
|
|
394
|
-
model: this.getInitialModel(props.mode)
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
getLabels(mode) {
|
|
398
|
-
let {
|
|
399
|
-
model,
|
|
400
|
-
tab
|
|
401
|
-
} = this.state;
|
|
402
|
-
let {
|
|
403
|
-
register,
|
|
404
|
-
profile,
|
|
405
|
-
forget
|
|
406
|
-
} = this.props;
|
|
407
|
-
if (profile) {
|
|
408
|
-
let {
|
|
409
|
-
title,
|
|
410
|
-
onClose,
|
|
411
|
-
submitText = 'ویرایش اطلاعات کاربری',
|
|
412
|
-
subtitle = false
|
|
413
|
-
} = profile;
|
|
414
|
-
if (!title && !onClose) {
|
|
415
|
-
return {
|
|
416
|
-
inputLabel: false,
|
|
417
|
-
title: false,
|
|
418
|
-
subtitle: false,
|
|
419
|
-
submitText,
|
|
420
|
-
backButton: false
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
return {
|
|
424
|
-
inputLabel: false,
|
|
425
|
-
title: title || 'ویرایش اطلاعات کاربری',
|
|
426
|
-
submitText,
|
|
427
|
-
subtitle,
|
|
428
|
-
backButton: !!onClose
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
if (mode === 'OTPNumber') {
|
|
432
|
-
let subtitle = 'شماره همراه خود را وارد کنید . پیامکی حاوی کد برای شما ارسال خواهد شد';
|
|
433
|
-
return {
|
|
434
|
-
inputLabel: 'شماره همراه',
|
|
435
|
-
title: 'ورود با کد یکبار مصرف',
|
|
436
|
-
submitText: 'ورود',
|
|
437
|
-
subtitle
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
if (mode === 'OTPCode') {
|
|
441
|
-
return {
|
|
442
|
-
inputLabel: 'کد پیامک شده',
|
|
443
|
-
title: false,
|
|
444
|
-
submitText: 'ورود',
|
|
445
|
-
subtitle: `کد پیامک شده به شماره ی ${model.login.userId} را وارد کنید`
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
if (mode === 'register') {
|
|
449
|
-
let {
|
|
450
|
-
title,
|
|
451
|
-
submitText = 'ثبت نام',
|
|
452
|
-
subtitle = false
|
|
453
|
-
} = register;
|
|
454
|
-
return {
|
|
455
|
-
inputLabel: false,
|
|
456
|
-
title,
|
|
457
|
-
submitText,
|
|
458
|
-
subtitle,
|
|
459
|
-
backButton: tab !== 'register'
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
if (mode === 'forgetUserId') {
|
|
463
|
-
let subtitle = `${forget.mode === 'phoneNumber' ? 'شماره همراه' : 'ایمیل'} خود را وارد کنید . کد باز یابی رمز عبور برای شما ارسال خواهد شد`;
|
|
464
|
-
return {
|
|
465
|
-
inputLabel: forget.mode === 'email' ? 'ایمیل' : 'شماره همراه',
|
|
466
|
-
backButton: true,
|
|
467
|
-
title: 'بازیابی رمز عبور',
|
|
468
|
-
submitText: 'دریافت کد بازیابی رمز',
|
|
469
|
-
subtitle
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
if (mode === 'forgetPassword') {
|
|
473
|
-
let {
|
|
474
|
-
mode
|
|
475
|
-
} = forget;
|
|
476
|
-
let subtitle = `کد ${mode === 'phoneNumber' ? 'پیامک' : 'ایمیل'} شده به ${mode === 'phoneNumber' ? 'شماره ی' : 'آدرس'} ${model.forget.userId} را وارد کنید`;
|
|
477
|
-
return {
|
|
478
|
-
inputLabel: `کد ${mode === 'email' ? 'ایمیل' : 'پیامک'} شده`,
|
|
479
|
-
backButton: true,
|
|
480
|
-
title: 'بازیابی رمز عبور',
|
|
481
|
-
submitText: 'تایید',
|
|
482
|
-
subtitle
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
if (mode === 'userName') {
|
|
486
|
-
return {
|
|
487
|
-
inputLabel: 'نام کاربری',
|
|
488
|
-
title: 'ورود با نام کاربری',
|
|
489
|
-
submitText: 'ورود',
|
|
490
|
-
subtitle: false
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
if (mode === 'email') {
|
|
494
|
-
return {
|
|
495
|
-
inputLabel: 'ایمیل',
|
|
496
|
-
title: 'ورود با ایمیل',
|
|
497
|
-
submitText: 'ورود',
|
|
498
|
-
subtitle: false
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
if (mode === 'phoneNumber') {
|
|
502
|
-
return {
|
|
503
|
-
inputLabel: 'شماره همراه',
|
|
504
|
-
title: 'ورود با شماره همراه',
|
|
505
|
-
submitText: 'ورود',
|
|
506
|
-
subtitle: false
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
changeMode(mode) {
|
|
511
|
-
let {
|
|
512
|
-
onChangeMode
|
|
513
|
-
} = this.props;
|
|
514
|
-
onChangeMode(mode);
|
|
515
|
-
this.setState({
|
|
516
|
-
model: this.getInitialModel(mode)
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
getInitialModel(mode) {
|
|
520
|
-
if (!mode) {
|
|
521
|
-
mode = this.props.mode;
|
|
522
|
-
}
|
|
523
|
-
let {
|
|
524
|
-
userId,
|
|
525
|
-
profile = {}
|
|
526
|
-
} = this.props;
|
|
527
|
-
return {
|
|
528
|
-
forget: {},
|
|
529
|
-
register: {},
|
|
530
|
-
profile: profile.model,
|
|
531
|
-
login: {
|
|
532
|
-
userId
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
title_layout({
|
|
537
|
-
title,
|
|
538
|
-
backButton
|
|
539
|
-
}) {
|
|
540
|
-
if (!title) {
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
let {
|
|
544
|
-
modes,
|
|
545
|
-
profile
|
|
546
|
-
} = this.props;
|
|
547
|
-
return {
|
|
548
|
-
className: 'aio-login-title',
|
|
549
|
-
align: 'v',
|
|
550
|
-
row: [{
|
|
551
|
-
show: !!backButton,
|
|
552
|
-
html: /*#__PURE__*/_jsx(Icon, {
|
|
553
|
-
path: mdiChevronRight,
|
|
554
|
-
size: 1
|
|
555
|
-
}),
|
|
556
|
-
size: 48,
|
|
557
|
-
align: 'vh',
|
|
558
|
-
onClick: () => profile ? profile.onClose() : this.changeMode(modes[0])
|
|
559
|
-
}, {
|
|
560
|
-
html: title
|
|
561
|
-
}]
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
subtitle_layout({
|
|
565
|
-
subtitle
|
|
566
|
-
}) {
|
|
567
|
-
if (!subtitle) {
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
return {
|
|
571
|
-
html: subtitle,
|
|
572
|
-
className: 'aio-login-subtitle'
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
getInput_phoneNumber(field, getValue) {
|
|
576
|
-
return {
|
|
577
|
-
field,
|
|
578
|
-
label: 'شماره همراه',
|
|
579
|
-
input: {
|
|
580
|
-
type: 'text',
|
|
581
|
-
justNumber: true,
|
|
582
|
-
before: /*#__PURE__*/_jsx(Icon, {
|
|
583
|
-
path: mdiCellphone,
|
|
584
|
-
size: 0.8
|
|
585
|
-
}),
|
|
586
|
-
placeholder: '09...',
|
|
587
|
-
maxLength: 11,
|
|
588
|
-
attrs: {
|
|
589
|
-
style: {
|
|
590
|
-
direction: 'ltr'
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
validations: [['function', () => {
|
|
595
|
-
let value = getValue();
|
|
596
|
-
if (!value) {
|
|
597
|
-
return 'شماره همراه خود را وارد کنید';
|
|
598
|
-
}
|
|
599
|
-
if (value.indexOf('09') !== 0) {
|
|
600
|
-
return 'شماره همراه باید با 09 شروع شود';
|
|
601
|
-
}
|
|
602
|
-
if (value.length !== 11) {
|
|
603
|
-
return 'شماره همراه باید 11 رقم باشد';
|
|
604
|
-
}
|
|
605
|
-
return false;
|
|
606
|
-
}]]
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
getInput_userName(field) {
|
|
610
|
-
let {
|
|
611
|
-
userId
|
|
612
|
-
} = this.props;
|
|
613
|
-
return {
|
|
614
|
-
field,
|
|
615
|
-
label: 'نام کاربری',
|
|
616
|
-
validations: [['required']],
|
|
617
|
-
style: {
|
|
618
|
-
direction: 'ltr'
|
|
619
|
-
},
|
|
620
|
-
input: {
|
|
621
|
-
type: 'text',
|
|
622
|
-
disabled: !!userId,
|
|
623
|
-
before: /*#__PURE__*/_jsx(Icon, {
|
|
624
|
-
path: mdiAccount,
|
|
625
|
-
size: 0.8
|
|
626
|
-
})
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
getInput_email(field, getValue) {
|
|
631
|
-
let {
|
|
632
|
-
userId
|
|
633
|
-
} = this.props;
|
|
634
|
-
return {
|
|
635
|
-
field,
|
|
636
|
-
label: 'ایمیل',
|
|
637
|
-
style: {
|
|
638
|
-
direction: 'ltr'
|
|
639
|
-
},
|
|
640
|
-
input: {
|
|
641
|
-
type: 'text',
|
|
642
|
-
disabled: !!userId,
|
|
643
|
-
before: /*#__PURE__*/_jsx(Icon, {
|
|
644
|
-
path: mdiEmail,
|
|
645
|
-
size: 0.8
|
|
646
|
-
})
|
|
647
|
-
},
|
|
648
|
-
validations: [['function', () => {
|
|
649
|
-
let value = getValue();
|
|
650
|
-
if (!value) {
|
|
651
|
-
return 'ایمیل خود را وارد کنید';
|
|
652
|
-
}
|
|
653
|
-
let atSignIndex = value.indexOf('@');
|
|
654
|
-
if (atSignIndex < 1) {
|
|
655
|
-
return 'ایمیل خود را به درستی وارد کنید';
|
|
656
|
-
}
|
|
657
|
-
if (value.indexOf('.') === -1) {
|
|
658
|
-
return 'ایمیل خود را به درستی وارد کنید';
|
|
659
|
-
}
|
|
660
|
-
if (value.lastIndexOf('.') > value.length - 3) {
|
|
661
|
-
return 'ایمیل خود را به درستی وارد کنید';
|
|
662
|
-
}
|
|
663
|
-
return false;
|
|
664
|
-
}]]
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
getInput_otp(field, getValue) {
|
|
668
|
-
let {
|
|
669
|
-
otpLength
|
|
670
|
-
} = this.props;
|
|
671
|
-
return {
|
|
672
|
-
field,
|
|
673
|
-
label: 'رمز یکبار مصرف',
|
|
674
|
-
input: {
|
|
675
|
-
maxLength: otpLength,
|
|
676
|
-
justNumber: true,
|
|
677
|
-
type: 'text',
|
|
678
|
-
placeholder: Array(otpLength).fill('-').join(''),
|
|
679
|
-
className: 'aio-login-otp-code'
|
|
680
|
-
},
|
|
681
|
-
validations: [['function', () => {
|
|
682
|
-
let {
|
|
683
|
-
otpLength
|
|
684
|
-
} = this.props;
|
|
685
|
-
let value = getValue();
|
|
686
|
-
if (!value) {
|
|
687
|
-
return 'رمز یکبار مصرف را وارد کنید';
|
|
688
|
-
}
|
|
689
|
-
return value.length !== otpLength ? `رمز یکبار مصرف باید شامل ${otpLength} کاراکتر باشد` : false;
|
|
690
|
-
}]]
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
getInput_password(field, type) {
|
|
694
|
-
let validations;
|
|
695
|
-
if (type === 2) {
|
|
696
|
-
validations = [['function', () => {
|
|
697
|
-
let {
|
|
698
|
-
model
|
|
699
|
-
} = this.state;
|
|
700
|
-
let value = model.forget.reNewPassword;
|
|
701
|
-
if (!value) {
|
|
702
|
-
return 'تکرار رمز عبور جدید را وارد کنید';
|
|
703
|
-
}
|
|
704
|
-
if (value.length < 1) {
|
|
705
|
-
return 'رمز عبور را وارد کنید';
|
|
706
|
-
}
|
|
707
|
-
if (value !== model.forget.newPassword) {
|
|
708
|
-
return 'رمز با تکرار آن مطابقت ندارد';
|
|
709
|
-
}
|
|
710
|
-
return false;
|
|
711
|
-
}]];
|
|
712
|
-
} else {
|
|
713
|
-
validations = [['required']];
|
|
714
|
-
}
|
|
715
|
-
return {
|
|
716
|
-
field,
|
|
717
|
-
label: ['رمز عبور', 'رمز عبور جدید', 'تکرار رمز عبور جدید'][type],
|
|
718
|
-
validations,
|
|
719
|
-
input: {
|
|
720
|
-
type: 'password',
|
|
721
|
-
before: /*#__PURE__*/_jsx(Icon, {
|
|
722
|
-
path: mdiLock,
|
|
723
|
-
size: 0.8
|
|
724
|
-
}),
|
|
725
|
-
style: {
|
|
726
|
-
direction: 'ltr'
|
|
727
|
-
},
|
|
728
|
-
visible: true
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
getInputs() {
|
|
733
|
-
let {
|
|
734
|
-
forget,
|
|
735
|
-
mode,
|
|
736
|
-
profile,
|
|
737
|
-
register
|
|
738
|
-
} = this.props;
|
|
739
|
-
if (profile) {
|
|
740
|
-
return getFormInputs(profile.fields, 'profile');
|
|
741
|
-
}
|
|
742
|
-
if (mode === 'register') {
|
|
743
|
-
return getFormInputs(register.fields, 'register');
|
|
744
|
-
}
|
|
745
|
-
if (mode === 'forgetUserId') {
|
|
746
|
-
return [this['getInput_' + forget.mode](`value.forget.userId`, () => this.state.model.forget.userId)];
|
|
747
|
-
}
|
|
748
|
-
if (mode === 'forgetPassword') {
|
|
749
|
-
return [this.getInput_otp('value.forget.password', () => this.state.model.forget.password), this.getInput_password('value.forget.newPassword', 1), this.getInput_password('value.forget.reNewPassword', 2)];
|
|
750
|
-
}
|
|
751
|
-
if (mode === 'OTPNumber') {
|
|
752
|
-
return [this.getInput_phoneNumber(`value.login.userId`, () => this.state.model.login.userId)];
|
|
753
|
-
}
|
|
754
|
-
if (mode === 'OTPCode') {
|
|
755
|
-
return [this.getInput_otp('value.login.password', () => this.state.model.login.password)];
|
|
756
|
-
}
|
|
757
|
-
return [this['getInput_' + mode]('value.login.userId', () => this.state.model.login.userId), this.getInput_password('value.login.password', 0)];
|
|
758
|
-
}
|
|
759
|
-
form_layout(labels) {
|
|
760
|
-
let {
|
|
761
|
-
model
|
|
762
|
-
} = this.state,
|
|
763
|
-
{
|
|
764
|
-
mode,
|
|
765
|
-
userId
|
|
766
|
-
} = this.props;
|
|
767
|
-
return {
|
|
768
|
-
className: 'ofy-auto',
|
|
769
|
-
html: /*#__PURE__*/_jsx(AIOInput, {
|
|
770
|
-
type: "form",
|
|
771
|
-
lang: "fa",
|
|
772
|
-
value: model,
|
|
773
|
-
rtl: true,
|
|
774
|
-
initialDisabled: !userId,
|
|
775
|
-
onChange: model => {
|
|
776
|
-
this.setState({
|
|
777
|
-
model
|
|
778
|
-
});
|
|
779
|
-
},
|
|
780
|
-
inputs: {
|
|
781
|
-
props: {
|
|
782
|
-
gap: 12
|
|
783
|
-
},
|
|
784
|
-
column: this.getInputs(labels)
|
|
785
|
-
},
|
|
786
|
-
footer: ({
|
|
787
|
-
disabled
|
|
788
|
-
}) => this.submit_layout({
|
|
789
|
-
submitText: labels.submitText,
|
|
790
|
-
disabled
|
|
791
|
-
})
|
|
792
|
-
}, mode)
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
submit_layout({
|
|
796
|
-
submitText,
|
|
797
|
-
disabled
|
|
798
|
-
}) {
|
|
799
|
-
let {
|
|
800
|
-
loading,
|
|
801
|
-
timer,
|
|
802
|
-
mode
|
|
803
|
-
} = this.props;
|
|
804
|
-
let layout = {
|
|
805
|
-
style: {
|
|
806
|
-
padding: '0 12px'
|
|
807
|
-
},
|
|
808
|
-
html: /*#__PURE__*/_jsx(SubmitButton, {
|
|
809
|
-
mode: mode,
|
|
810
|
-
timer: timer,
|
|
811
|
-
text: submitText,
|
|
812
|
-
loading: loading,
|
|
813
|
-
disabled: () => !!disabled,
|
|
814
|
-
onClick: () => this.onSubmit()
|
|
815
|
-
})
|
|
816
|
-
};
|
|
817
|
-
return /*#__PURE__*/_jsx(RVD, {
|
|
818
|
-
layout: layout
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
async onSubmit() {
|
|
822
|
-
let {
|
|
823
|
-
onSubmit,
|
|
824
|
-
profile,
|
|
825
|
-
onSubmitProfile
|
|
826
|
-
} = this.props;
|
|
827
|
-
let {
|
|
828
|
-
model
|
|
829
|
-
} = this.state;
|
|
830
|
-
if (profile) {
|
|
831
|
-
onSubmitProfile(model);
|
|
832
|
-
} else {
|
|
833
|
-
onSubmit(model);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
changeUserId_layout() {
|
|
837
|
-
let {
|
|
838
|
-
mode
|
|
839
|
-
} = this.props;
|
|
840
|
-
if (mode !== 'OTPCode') {
|
|
841
|
-
return false;
|
|
842
|
-
}
|
|
843
|
-
return {
|
|
844
|
-
onClick: () => this.changeMode('OTPNumber'),
|
|
845
|
-
className: 'aio-login-text m-b-12',
|
|
846
|
-
align: 'vh',
|
|
847
|
-
html: 'تغییر شماره همراه'
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
recode_layout() {
|
|
851
|
-
let {
|
|
852
|
-
model
|
|
853
|
-
} = this.state;
|
|
854
|
-
let {
|
|
855
|
-
mode,
|
|
856
|
-
onChangeMode
|
|
857
|
-
} = this.props;
|
|
858
|
-
if (mode !== 'OTPCode') {
|
|
859
|
-
return false;
|
|
860
|
-
}
|
|
861
|
-
return {
|
|
862
|
-
className: 'aio-login-text m-b-12',
|
|
863
|
-
html: `ارسال مجدد کد`,
|
|
864
|
-
align: 'vh',
|
|
865
|
-
onClick: () => {
|
|
866
|
-
onChangeMode('OTPNumber');
|
|
867
|
-
this.setState({
|
|
868
|
-
model: {
|
|
869
|
-
...model,
|
|
870
|
-
login: {
|
|
871
|
-
...model.login,
|
|
872
|
-
password: ''
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
changeMode_layout() {
|
|
880
|
-
let {
|
|
881
|
-
mode,
|
|
882
|
-
modes,
|
|
883
|
-
profile
|
|
884
|
-
} = this.props;
|
|
885
|
-
if (mode === 'register' || !!profile || mode === 'forgetUserId' || mode === 'forgetPassword') {
|
|
886
|
-
return false;
|
|
887
|
-
}
|
|
888
|
-
let others = [];
|
|
889
|
-
for (let i = 0; i < modes.length; i++) {
|
|
890
|
-
let key = modes[i];
|
|
891
|
-
if (mode === key) {
|
|
892
|
-
continue;
|
|
893
|
-
}
|
|
894
|
-
if (mode === 'OTPCode' && key === 'OTPNumber') {
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
let title = {
|
|
898
|
-
OTPNumber: 'رمز یکبار مصرف',
|
|
899
|
-
userName: 'نام کاربری و رمز عبور',
|
|
900
|
-
email: 'آدرس ایمیل و رمز عبور',
|
|
901
|
-
phoneNumber: 'شماره همراه و رمز عبور'
|
|
902
|
-
}[key];
|
|
903
|
-
let icon = {
|
|
904
|
-
OTPNumber: mdiAccount,
|
|
905
|
-
phoneNumber: mdiCellphone,
|
|
906
|
-
userName: mdiAccountBoxOutline,
|
|
907
|
-
email: mdiEmail
|
|
908
|
-
}[key];
|
|
909
|
-
others.push({
|
|
910
|
-
flex: 1,
|
|
911
|
-
className: `of-visible aio-login-other-method aio-login-${key}`,
|
|
912
|
-
onClick: () => this.changeMode(key),
|
|
913
|
-
row: [{
|
|
914
|
-
html: /*#__PURE__*/_jsx(Icon, {
|
|
915
|
-
path: icon,
|
|
916
|
-
size: 0.7
|
|
917
|
-
}),
|
|
918
|
-
align: 'vh'
|
|
919
|
-
}, {
|
|
920
|
-
size: 6
|
|
921
|
-
}, {
|
|
922
|
-
align: 'v',
|
|
923
|
-
html: title
|
|
924
|
-
}]
|
|
925
|
-
});
|
|
926
|
-
}
|
|
927
|
-
if (!others.length) {
|
|
928
|
-
return false;
|
|
929
|
-
}
|
|
930
|
-
return {
|
|
931
|
-
className: 'p-h-12',
|
|
932
|
-
column: [{
|
|
933
|
-
gap: 6,
|
|
934
|
-
row: [{
|
|
935
|
-
flex: 1,
|
|
936
|
-
html: /*#__PURE__*/_jsx("div", {
|
|
937
|
-
className: "aio-login-splitter"
|
|
938
|
-
}),
|
|
939
|
-
align: 'v'
|
|
940
|
-
}, {
|
|
941
|
-
html: 'یا ورود با',
|
|
942
|
-
align: 'v',
|
|
943
|
-
className: 'aio-login-or bold'
|
|
944
|
-
}, {
|
|
945
|
-
flex: 1,
|
|
946
|
-
html: /*#__PURE__*/_jsx("div", {
|
|
947
|
-
className: "aio-login-splitter"
|
|
948
|
-
}),
|
|
949
|
-
align: 'v'
|
|
950
|
-
}]
|
|
951
|
-
}, {
|
|
952
|
-
size: 12
|
|
953
|
-
}, {
|
|
954
|
-
grid: others,
|
|
955
|
-
gridCols: 1,
|
|
956
|
-
gridRow: {
|
|
957
|
-
gap: 12
|
|
958
|
-
}
|
|
959
|
-
}]
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
registerButton_layout() {
|
|
963
|
-
let {
|
|
964
|
-
register,
|
|
965
|
-
mode
|
|
966
|
-
} = this.props;
|
|
967
|
-
if (mode === 'register') {
|
|
968
|
-
return false;
|
|
969
|
-
}
|
|
970
|
-
if (!register.type !== 'button') {
|
|
971
|
-
return false;
|
|
972
|
-
}
|
|
973
|
-
let {
|
|
974
|
-
buttonText = 'ثبت نام'
|
|
975
|
-
} = register;
|
|
976
|
-
return {
|
|
977
|
-
align: 'vh',
|
|
978
|
-
html: /*#__PURE__*/_jsx("button", {
|
|
979
|
-
onClick: () => this.changeMode('register'),
|
|
980
|
-
className: "aio-login-register-button",
|
|
981
|
-
children: buttonText
|
|
982
|
-
})
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
registerTab_layout() {
|
|
986
|
-
let {
|
|
987
|
-
register,
|
|
988
|
-
modes,
|
|
989
|
-
mode,
|
|
990
|
-
profile
|
|
991
|
-
} = this.props;
|
|
992
|
-
if (!register || register.type !== 'tab' || profile || mode === 'forgetUserId' || mode === 'forgetPassword') {
|
|
993
|
-
return false;
|
|
994
|
-
}
|
|
995
|
-
let {
|
|
996
|
-
tabText = 'ثبت نام'
|
|
997
|
-
} = register;
|
|
998
|
-
return {
|
|
999
|
-
html: /*#__PURE__*/_jsx(AIOInput, {
|
|
1000
|
-
className: "aio-login-register-tabs",
|
|
1001
|
-
type: "tabs",
|
|
1002
|
-
value: mode === 'register' ? 'register' : 'login',
|
|
1003
|
-
options: [{
|
|
1004
|
-
text: 'ورود',
|
|
1005
|
-
value: 'login'
|
|
1006
|
-
}, {
|
|
1007
|
-
text: tabText,
|
|
1008
|
-
value: 'register'
|
|
1009
|
-
}],
|
|
1010
|
-
onChange: tab => {
|
|
1011
|
-
if (tab === 'login') {
|
|
1012
|
-
this.changeMode(modes[0]);
|
|
1013
|
-
} else if (tab === 'register') {
|
|
1014
|
-
this.changeMode('register');
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
})
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
forget_layout() {
|
|
1021
|
-
let {
|
|
1022
|
-
forget,
|
|
1023
|
-
mode,
|
|
1024
|
-
profile
|
|
1025
|
-
} = this.props;
|
|
1026
|
-
if (profile) {
|
|
1027
|
-
return false;
|
|
1028
|
-
}
|
|
1029
|
-
if (!forget) {
|
|
1030
|
-
return false;
|
|
1031
|
-
}
|
|
1032
|
-
if (mode === 'register' || mode === 'OTPCode' || mode === 'OTPNumber' || mode === 'forgetUserId' || mode === 'forgetPassword') {
|
|
1033
|
-
return false;
|
|
1034
|
-
}
|
|
1035
|
-
let {
|
|
1036
|
-
text = []
|
|
1037
|
-
} = forget;
|
|
1038
|
-
let buttonText = text[0] || 'رمز عبور خود را فراموش کرده اید؟ اینجا کلیک کنید';
|
|
1039
|
-
return {
|
|
1040
|
-
className: 'aio-login-forget',
|
|
1041
|
-
html: buttonText,
|
|
1042
|
-
onClick: () => this.changeMode('forgetUserId')
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
render() {
|
|
1046
|
-
let {
|
|
1047
|
-
attrs,
|
|
1048
|
-
mode,
|
|
1049
|
-
profile
|
|
1050
|
-
} = this.props,
|
|
1051
|
-
labels = this.getLabels(mode);
|
|
1052
|
-
let column;
|
|
1053
|
-
if (profile) {
|
|
1054
|
-
column = [{
|
|
1055
|
-
column: [this.title_layout(labels), this.subtitle_layout(labels)]
|
|
1056
|
-
}, this.form_layout(labels)];
|
|
1057
|
-
} else {
|
|
1058
|
-
column = [this.registerTab_layout(), {
|
|
1059
|
-
column: [this.title_layout(labels), this.subtitle_layout(labels)]
|
|
1060
|
-
}, this.form_layout(labels), this.forget_layout(), {
|
|
1061
|
-
gap: 12,
|
|
1062
|
-
align: 'h',
|
|
1063
|
-
row: [this.recode_layout(), this.changeUserId_layout()]
|
|
1064
|
-
}, this.changeMode_layout(), this.registerButton_layout()];
|
|
1065
|
-
}
|
|
1066
|
-
let className = 'aio-login' + (attrs.className ? ' ' + attrs.className : '');
|
|
1067
|
-
let style = attrs.style;
|
|
1068
|
-
return /*#__PURE__*/_jsx(RVD, {
|
|
1069
|
-
layout: {
|
|
1070
|
-
className,
|
|
1071
|
-
style,
|
|
1072
|
-
column,
|
|
1073
|
-
attrs: {
|
|
1074
|
-
onKeyDown: e => {
|
|
1075
|
-
if (e.keyCode === 13) {
|
|
1076
|
-
this.onSubmit();
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
class SubmitButton extends Component {
|
|
1085
|
-
constructor(...args) {
|
|
1086
|
-
super(...args);
|
|
1087
|
-
_defineProperty(this, "state", {
|
|
1088
|
-
time: this.getDelta()
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
async onClick() {
|
|
1092
|
-
let {
|
|
1093
|
-
onClick,
|
|
1094
|
-
loading
|
|
1095
|
-
} = this.props;
|
|
1096
|
-
if (loading) {
|
|
1097
|
-
return;
|
|
1098
|
-
}
|
|
1099
|
-
this.setLastTry();
|
|
1100
|
-
await onClick();
|
|
1101
|
-
}
|
|
1102
|
-
setLastTry() {
|
|
1103
|
-
let {
|
|
1104
|
-
mode
|
|
1105
|
-
} = this.props;
|
|
1106
|
-
AIOStorage('aiologinlasttrypermode').save({
|
|
1107
|
-
name: 'dic',
|
|
1108
|
-
value: {
|
|
1109
|
-
...this.getLastTry(),
|
|
1110
|
-
[mode]: new Date().getTime()
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
let delta = this.getDelta();
|
|
1114
|
-
this.setState({
|
|
1115
|
-
time: delta
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
getLastTry() {
|
|
1119
|
-
return AIOStorage('aiologinlasttrypermode').load({
|
|
1120
|
-
name: 'dic',
|
|
1121
|
-
def: {}
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
getDelta() {
|
|
1125
|
-
let {
|
|
1126
|
-
mode,
|
|
1127
|
-
timer
|
|
1128
|
-
} = this.props;
|
|
1129
|
-
if (!timer) {
|
|
1130
|
-
return 0;
|
|
1131
|
-
}
|
|
1132
|
-
let lastTry = this.getLastTry();
|
|
1133
|
-
let lastTime = lastTry[mode];
|
|
1134
|
-
if (!lastTime) {
|
|
1135
|
-
return 0;
|
|
1136
|
-
}
|
|
1137
|
-
let delta = new Date().getTime() - lastTime;
|
|
1138
|
-
delta = delta / 1000;
|
|
1139
|
-
delta = timer - delta;
|
|
1140
|
-
delta = Math.round(delta);
|
|
1141
|
-
if (delta < 0) {
|
|
1142
|
-
delta = 0;
|
|
1143
|
-
}
|
|
1144
|
-
return delta;
|
|
1145
|
-
}
|
|
1146
|
-
render() {
|
|
1147
|
-
let {
|
|
1148
|
-
disabled,
|
|
1149
|
-
loading,
|
|
1150
|
-
text,
|
|
1151
|
-
outline
|
|
1152
|
-
} = this.props;
|
|
1153
|
-
let isDisabled = disabled();
|
|
1154
|
-
let loadingText = 'در حال ارسال';
|
|
1155
|
-
let {
|
|
1156
|
-
time
|
|
1157
|
-
} = this.state;
|
|
1158
|
-
if (time > 0) {
|
|
1159
|
-
setTimeout(() => this.setState({
|
|
1160
|
-
time: this.state.time - 1
|
|
1161
|
-
}), 1000);
|
|
1162
|
-
} else if (time < 0) {
|
|
1163
|
-
setTimeout(() => this.setState({
|
|
1164
|
-
time: 0
|
|
1165
|
-
}), 0);
|
|
1166
|
-
}
|
|
1167
|
-
if (time) {
|
|
1168
|
-
isDisabled = true;
|
|
1169
|
-
if (!loading) {
|
|
1170
|
-
text = `لطفا ${time} ثانیه صبر کنید`;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
return /*#__PURE__*/_jsxs("button", {
|
|
1174
|
-
className: 'aio-login-submit' + (outline ? ' aio-login-submit-outline' : ''),
|
|
1175
|
-
disabled: isDisabled,
|
|
1176
|
-
onClick: () => this.onClick(),
|
|
1177
|
-
children: [!loading && text, !!loading && /*#__PURE__*/_jsx(Icon, {
|
|
1178
|
-
path: mdiLoading,
|
|
1179
|
-
size: 1,
|
|
1180
|
-
spin: 0.2,
|
|
1181
|
-
style: {
|
|
1182
|
-
margin: '0 6px'
|
|
1183
|
-
}
|
|
1184
|
-
}), !!loading && loadingText]
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
function AIOLoginValidator(props) {
|
|
1189
|
-
let {
|
|
1190
|
-
id,
|
|
1191
|
-
onAuth,
|
|
1192
|
-
onSubmit,
|
|
1193
|
-
modes,
|
|
1194
|
-
timer,
|
|
1195
|
-
checkToken,
|
|
1196
|
-
register,
|
|
1197
|
-
userId = '',
|
|
1198
|
-
attrs,
|
|
1199
|
-
forget,
|
|
1200
|
-
otpLength
|
|
1201
|
-
} = props;
|
|
1202
|
-
for (let prop in props) {
|
|
1203
|
-
if (['id', 'onAuth', 'onSubmit', 'modes', 'timer', 'checkToken', 'register', 'userId', 'attrs', 'forget', 'otpLength', 'splash'].indexOf(prop) === -1) {
|
|
1204
|
-
let error = `
|
|
13
|
+
)`;return alert(r),console.log(r),null}return b(AIOLOGIN,{...this.props,getActions:({setMode:e})=>this.setMode=e,profile:i,attrs:t})});let{id:t,onAuth:i,onSubmit:r,modes:s,timer:n,checkToken:l,register:a,userId:u,attrs:d,forget:g,otpLength:p}=e;AIOLoginValidator(e);let h=o(`-AIOLogin-${t}`);this.setStorage=(e,t)=>{h.save({name:e,value:t})},this.getStorage=()=>{let e=h.load({name:"token",def:!1}),t=h.load({name:"userId",def:""}),i=h.load({name:"userInfo"});return{token:e,userId:t,userInfo:i}},this.setUserInfo=e=>{this.setStorage("userInfo",e)},this.getUserInfo=()=>this.getStorage().userInfo,this.setToken=e=>{this.setStorage("token",e)},this.getToken=()=>this.getStorage().token,this.removeToken=()=>{h.remove({name:"token"})},this.getUserId=()=>this.getStorage().userId,this.logout=()=>{this.removeToken(),window.location.reload()},this.props={id:t,checkToken:l,onAuth:i,onSubmit:r,modes:s,register:a,userId:u,attrs:d,timer:n,forget:g,otpLength:p,getStorage:this.getStorage,setStorage:this.setStorage,removeToken:this.removeToken,setToken:this.setToken,getToken:this.getToken,getUserId:this.getUserId,logout:this.logout}}};class AIOLOGIN extends t{constructor(e){super(e),this.state={isTokenChecked:!1,showReload:!1,mode:e.mode||e.modes[0],loading:!1},e.getActions({setMode:this.setMode.bind(this)})}async checkToken(){let{getStorage:e,checkToken:t,removeToken:i}=this.props,{token:r,userId:o,userInfo:s}=e(),n;if("string"!=typeof r)n=!1;else try{n=await t(r,{userId:o,userInfo:s})}catch(l){new f().addAlert({type:"error",text:"بررسی توکن با خطا روبرو شد",subtext:this.getError(l)})}!0===n?this.setMode("auth"):!1===n?i():("string"==typeof n&&new f().addAlert({type:"error",text:"بررسی توکن با خطا روبرو شد",subtext:n}),this.setState({showReload:!0})),this.setState({isTokenChecked:!0})}getError(e){if("string"==typeof e)return e;if("object"==typeof e){if("object"!=typeof e.response)return e.message||e.Message;if("object"==typeof e.response.data){let{message:t,Message:i}=e.response.data;return i||t}return"string"==typeof e.response.data?e.response.data:"error"}}async componentDidMount(){let{profile:e}=this.props;!e&&this.checkToken()}setLoading(e){this.setState({loading:e})}async onSubmit(e){let{setStorage:t,onSubmit:i}=this.props,{mode:r}=this.state,o;this.setLoading(!0);try{o=await i(e,r)}catch{this.setLoading(!1);return}if(this.setLoading(!1),"string"==typeof o){let s={OTPNumber:"ارسال شماره همراه",OTPCode:"ارسال کد یکبار مصرف",userName:"ارسال نام کاربری و رمز عبور",phoneNumber:"ارسال شماره همراه و رمز عبور",email:"ارسال آدرس ایمیل و رمز عبور",register:"عملیات ثبت نام"}[r];s=`${s} با خطا روبرو شد`;let n=o;new f().addAlert({type:"error",text:s,subtext:n})}else -1!==["OTPNumber","phoneNumber","userName","email"].indexOf(r)&&t("userId",e.login.userId)}async onSubmitProfile(e){let{profile:t}=this.props,i;this.setLoading(!0);try{i=await t.onSubmit(e)}catch{this.setLoading(!1);return}this.setLoading(!1),"string"==typeof i&&new f().addAlert({type:"error",text:"ویرایش پروفایل با خطا روبرو شد",subtext:i})}setMode(e){this.setState({mode:e})}render(){let{otpLength:e,onAuth:t,id:i,timer:r,modes:o,userId:s,register:n={},profile:l,attrs:a={},forget:u,getStorage:d,logout:g,splash:p=()=>null}=this.props,{isTokenChecked:h,showReload:m,mode:f,loading:c}=this.state;if(l)return b(LoginForm,{timer:r,id:i,attrs:a,userId:s,loading:c,profile:l,onSubmitProfile:this.onSubmitProfile.bind(this)});if(m)return b("div",{className:"aio-login-reload",children:b("button",{onClick:()=>window.location.reload(),children:"بارگذاری مجدد"})});if(!h)return p();if("auth"===f){if(!this.reportedAuthToParent){this.reportedAuthToParent=!0;let{token:y,userId:T,userInfo:I}=d();t({token:y,userId:T,userInfo:I,logout:g})}return p()}return b(LoginForm,{forget:u,timer:r,otpLength:e,id:i,modes:o,attrs:a,userId:s,register:n,loading:c,mode:f,onSubmit:this.onSubmit.bind(this),onChangeMode:this.setMode.bind(this)})}}class LoginForm extends t{constructor(e){super(e),this.storage=o(`-AIOLogin-${e.id}`);let{timer:t=30}=e;this.state={timer:t,recode:!1,tab:"login",model:this.getInitialModel(e.mode)}}getLabels(e){let{model:t,tab:i}=this.state,{register:r,profile:o,forget:s}=this.props;if(o){let{title:n,onClose:l,submitText:a="ویرایش اطلاعات کاربری",subtitle:u=!1}=o;return n||l?{inputLabel:!1,title:n||"ویرایش اطلاعات کاربری",submitText:a,subtitle:u,backButton:!!l}:{inputLabel:!1,title:!1,subtitle:!1,submitText:a,backButton:!1}}if("OTPNumber"===e)return{inputLabel:"شماره همراه",title:"ورود با کد یکبار مصرف",submitText:"ورود",subtitle:"شماره همراه خود را وارد کنید . پیامکی حاوی کد برای شما ارسال خواهد شد"};if("OTPCode"===e)return{inputLabel:"کد پیامک شده",title:!1,submitText:"ورود",subtitle:`کد پیامک شده به شماره ی ${t.login.userId} را وارد کنید`};if("register"===e){let{title:d,submitText:g="ثبت نام",subtitle:p=!1}=r;return{inputLabel:!1,title:d,submitText:g,subtitle:p,backButton:"register"!==i}}if("forgetUserId"===e){let h=`${"phoneNumber"===s.mode?"شماره همراه":"ایمیل"} خود را وارد کنید . کد باز یابی رمز عبور برای شما ارسال خواهد شد`;return{inputLabel:"email"===s.mode?"ایمیل":"شماره همراه",backButton:!0,title:"بازیابی رمز عبور",submitText:"دریافت کد بازیابی رمز",subtitle:h}}if("forgetPassword"===e){let{mode:m}=s,f=`کد ${"phoneNumber"===m?"پیامک":"ایمیل"} شده به ${"phoneNumber"===m?"شماره ی":"آدرس"} ${t.forget.userId} را وارد کنید`;return{inputLabel:`کد ${"email"===m?"ایمیل":"پیامک"} شده`,backButton:!0,title:"بازیابی رمز عبور",submitText:"تایید",subtitle:f}}return"userName"===e?{inputLabel:"نام کاربری",title:"ورود با نام کاربری",submitText:"ورود",subtitle:!1}:"email"===e?{inputLabel:"ایمیل",title:"ورود با ایمیل",submitText:"ورود",subtitle:!1}:"phoneNumber"===e?{inputLabel:"شماره همراه",title:"ورود با شماره همراه",submitText:"ورود",subtitle:!1}:void 0}changeMode(e){let{onChangeMode:t}=this.props;t(e),this.setState({model:this.getInitialModel(e)})}getInitialModel(e){e||(e=this.props.mode);let{userId:t,profile:i={}}=this.props;return{forget:{},register:{},profile:i.model,login:{userId:t}}}title_layout({title:e,backButton:t}){if(!e)return!1;let{modes:i,profile:r}=this.props;return{className:"aio-login-title",align:"v",row:[{show:!!t,html:b(l,{path:m,size:1}),size:48,align:"vh",onClick:()=>r?r.onClose():this.changeMode(i[0])},{html:e}]}}subtitle_layout({subtitle:e}){return!!e&&{html:e,className:"aio-login-subtitle"}}getInput_phoneNumber(e,t){return{field:e,label:"شماره همراه",input:{type:"text",justNumber:!0,before:b(l,{path:a,size:.8}),placeholder:"09...",maxLength:11,attrs:{style:{direction:"ltr"}}},validations:[["function",()=>{let e=t();return e?0!==e.indexOf("09")?"شماره همراه باید با 09 شروع شود":11!==e.length&&"شماره همراه باید 11 رقم باشد":"شماره همراه خود را وارد کنید"}]]}}getInput_userName(e){let{userId:t}=this.props;return{field:e,label:"نام کاربری",validations:[["required"]],style:{direction:"ltr"},input:{type:"text",disabled:!!t,before:b(l,{path:g,size:.8})}}}getInput_email(e,t){let{userId:i}=this.props;return{field:e,label:"ایمیل",style:{direction:"ltr"},input:{type:"text",disabled:!!i,before:b(l,{path:h,size:.8})},validations:[["function",()=>{let e=t();return e?!!(1>e.indexOf("@")||-1===e.indexOf(".")||e.lastIndexOf(".")>e.length-3)&&"ایمیل خود را به درستی وارد کنید":"ایمیل خود را وارد کنید"}]]}}getInput_otp(e,t){let{otpLength:i}=this.props;return{field:e,label:"رمز یکبار مصرف",input:{maxLength:i,justNumber:!0,type:"text",placeholder:Array(i).fill("-").join(""),className:"aio-login-otp-code"},validations:[["function",()=>{let{otpLength:e}=this.props,i=t();return i?i.length!==e&&`رمز یکبار مصرف باید شامل ${e} کاراکتر باشد`:"رمز یکبار مصرف را وارد کنید"}]]}}getInput_password(e,t){let i;return i=2===t?[["function",()=>{let{model:e}=this.state,t=e.forget.reNewPassword;return t?t.length<1?"رمز عبور را وارد کنید":t!==e.forget.newPassword&&"رمز با تکرار آن مطابقت ندارد":"تکرار رمز عبور جدید را وارد کنید"}]]:[["required"]],{field:e,label:["رمز عبور","رمز عبور جدید","تکرار رمز عبور جدید"][t],validations:i,input:{type:"password",before:b(l,{path:u,size:.8}),style:{direction:"ltr"},visible:!0}}}getInputs(){let{forget:e,mode:t,profile:i,register:r}=this.props;return i?n(i.fields,"profile"):"register"===t?n(r.fields,"register"):"forgetUserId"===t?[this["getInput_"+e.mode]("value.forget.userId",()=>this.state.model.forget.userId)]:"forgetPassword"===t?[this.getInput_otp("value.forget.password",()=>this.state.model.forget.password),this.getInput_password("value.forget.newPassword",1),this.getInput_password("value.forget.reNewPassword",2)]:"OTPNumber"===t?[this.getInput_phoneNumber("value.login.userId",()=>this.state.model.login.userId)]:"OTPCode"===t?[this.getInput_otp("value.login.password",()=>this.state.model.login.password)]:[this["getInput_"+t]("value.login.userId",()=>this.state.model.login.userId),this.getInput_password("value.login.password",0)]}form_layout(e){let{model:t}=this.state,{mode:i,userId:r}=this.props;return{className:"ofy-auto",html:b(s,{type:"form",lang:"fa",value:t,rtl:!0,initialDisabled:!r,onChange:e=>{this.setState({model:e})},inputs:{props:{gap:12},column:this.getInputs(e)},footer:({disabled:t})=>this.submit_layout({submitText:e.submitText,disabled:t})},i)}}submit_layout({submitText:e,disabled:t}){let{loading:i,timer:o,mode:s}=this.props,n={style:{padding:"0 12px"},html:b(SubmitButton,{mode:s,timer:o,text:e,loading:i,disabled:()=>!!t,onClick:()=>this.onSubmit()})};return b(r,{layout:n})}async onSubmit(){let{onSubmit:e,profile:t,onSubmitProfile:i}=this.props,{model:r}=this.state;t?i(r):e(r)}changeUserId_layout(){let{mode:e}=this.props;return"OTPCode"===e&&{onClick:()=>this.changeMode("OTPNumber"),className:"aio-login-text m-b-12",align:"vh",html:"تغییر شماره همراه"}}recode_layout(){let{model:e}=this.state,{mode:t,onChangeMode:i}=this.props;return"OTPCode"===t&&{className:"aio-login-text m-b-12",html:`ارسال مجدد کد`,align:"vh",onClick:()=>{i("OTPNumber"),this.setState({model:{...e,login:{...e.login,password:""}}})}}}changeMode_layout(){let{mode:e,modes:t,profile:i}=this.props;if("register"===e||i||"forgetUserId"===e||"forgetPassword"===e)return!1;let r=[];for(let o=0;o<t.length;o++){let s=t[o];if(e===s||"OTPCode"===e&&"OTPNumber"===s)continue;let n={OTPNumber:"رمز یکبار مصرف",userName:"نام کاربری و رمز عبور",email:"آدرس ایمیل و رمز عبور",phoneNumber:"شماره همراه و رمز عبور"}[s],u={OTPNumber:g,phoneNumber:a,userName:p,email:h}[s];r.push({flex:1,className:`of-visible aio-login-other-method aio-login-${s}`,onClick:()=>this.changeMode(s),row:[{html:b(l,{path:u,size:.7}),align:"vh"},{size:6},{align:"v",html:n}]})}return!!r.length&&{className:"p-h-12",column:[{gap:6,row:[{flex:1,html:b("div",{className:"aio-login-splitter"}),align:"v"},{html:"یا ورود با",align:"v",className:"aio-login-or bold"},{flex:1,html:b("div",{className:"aio-login-splitter"}),align:"v"}]},{size:12},{grid:r,gridCols:1,gridRow:{gap:12}}]}}registerButton_layout(){let{register:e,mode:t}=this.props;return"register"===t||e.type,!1}registerTab_layout(){let{register:e,modes:t,mode:i,profile:r}=this.props;if(!e||"tab"!==e.type||r||"forgetUserId"===i||"forgetPassword"===i)return!1;let{tabText:o="ثبت نام"}=e;return{html:b(s,{className:"aio-login-register-tabs",type:"tabs",value:"register"===i?"register":"login",options:[{text:"ورود",value:"login"},{text:o,value:"register"}],onChange:e=>{"login"===e?this.changeMode(t[0]):"register"===e&&this.changeMode("register")}})}}forget_layout(){let{forget:e,mode:t,profile:i}=this.props;if(i||!e||"register"===t||"OTPCode"===t||"OTPNumber"===t||"forgetUserId"===t||"forgetPassword"===t)return!1;let{text:r=[]}=e;return{className:"aio-login-forget",html:r[0]||"رمز عبور خود را فراموش کرده اید؟ اینجا کلیک کنید",onClick:()=>this.changeMode("forgetUserId")}}render(){let{attrs:e,mode:t,profile:i}=this.props,o=this.getLabels(t),s;s=i?[{column:[this.title_layout(o),this.subtitle_layout(o)]},this.form_layout(o)]:[this.registerTab_layout(),{column:[this.title_layout(o),this.subtitle_layout(o)]},this.form_layout(o),this.forget_layout(),{gap:12,align:"h",row:[this.recode_layout(),this.changeUserId_layout()]},this.changeMode_layout(),this.registerButton_layout()];let n="aio-login"+(e.className?" "+e.className:""),l=e.style;return b(r,{layout:{className:n,style:l,column:s,attrs:{onKeyDown:e=>{13===e.keyCode&&this.onSubmit()}}}})}}class SubmitButton extends t{constructor(...e){super(...e),_defineProperty(this,"state",{time:this.getDelta()})}async onClick(){let{onClick:e,loading:t}=this.props;!t&&(this.setLastTry(),await e())}setLastTry(){let{mode:e}=this.props;o("aiologinlasttrypermode").save({name:"dic",value:{...this.getLastTry(),[e]:new Date().getTime()}});let t=this.getDelta();this.setState({time:t})}getLastTry(){return o("aiologinlasttrypermode").load({name:"dic",def:{}})}getDelta(){let{mode:e,timer:t}=this.props;if(!t)return 0;let i=this.getLastTry()[e];if(!i)return 0;let r=new Date().getTime()-i;return r/=1e3,(r=Math.round(r=t-r))<0&&(r=0),r}render(){let{disabled:e,loading:t,text:i,outline:r}=this.props,o=e(),{time:s}=this.state;return s>0?setTimeout(()=>this.setState({time:this.state.time-1}),1e3):s<0&&setTimeout(()=>this.setState({time:0}),0),s&&(o=!0,t||(i=`لطفا ${s} ثانیه صبر کنید`)),c("button",{className:"aio-login-submit"+(r?" aio-login-submit-outline":""),disabled:o,onClick:()=>this.onClick(),children:[!t&&i,!!t&&b(l,{path:d,size:1,spin:.2,style:{margin:"0 6px"}}),!!t&&"در حال ارسال"]})}}function AIOLoginValidator(e){let{id:t,onAuth:i,onSubmit:r,modes:o,timer:s,checkToken:n,register:l,userId:a="",attrs:u,forget:d,otpLength:g}=e;for(let p in e)if(-1===["id","onAuth","onSubmit","modes","timer","checkToken","register","userId","attrs","forget","otpLength","splash"].indexOf(p)){let h=`
|
|
1205
14
|
aio-login error => invalid props
|
|
1206
|
-
${
|
|
15
|
+
${p} is not one of AIOLogin props,
|
|
1207
16
|
valid props are 'id' | 'onAuth' | 'onSubmit' | 'modes' | 'timer' | 'checkToken' | 'register' | 'userId' | 'attrs' | 'forget' | 'otpLength' | 'splash'
|
|
1208
|
-
`;
|
|
1209
|
-
alert(error);
|
|
1210
|
-
console.log(error);
|
|
1211
|
-
return;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
if (!id) {
|
|
1215
|
-
alert(`aio-login error=> missing id props, id props should be an string`);
|
|
1216
|
-
}
|
|
1217
|
-
if (!onAuth) {
|
|
1218
|
-
let error = `
|
|
17
|
+
`;alert(h),console.log(h);return}if(t||alert("aio-login error=> missing id props, id props should be an string"),!i){let m=`
|
|
1219
18
|
aio-login error => missing onAuth props
|
|
1220
19
|
onAuth type is => ({token:string,userId:string,userInfo?:any,logout:function})=>void
|
|
1221
|
-
`;
|
|
1222
|
-
alert(error);
|
|
1223
|
-
console.log(error);
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
if (typeof userId !== 'string') {
|
|
1227
|
-
let error = `aio-login error=> userId props should be an string`;
|
|
1228
|
-
alert(error);
|
|
1229
|
-
console.log(error);
|
|
1230
|
-
return;
|
|
1231
|
-
}
|
|
1232
|
-
if (!checkToken) {
|
|
1233
|
-
let error = `
|
|
20
|
+
`;alert(m),console.log(m);return}if("string"!=typeof a){let f="aio-login error=> userId props should be an string";alert(f),console.log(f);return}if(!n){let b=`
|
|
1234
21
|
aio-login error=> missing checkToken props
|
|
1235
22
|
checkToken type is => (token:string)=>boolean
|
|
1236
23
|
for prevent it set checkToken : ()=>true
|
|
1237
|
-
`;
|
|
1238
|
-
alert(error);
|
|
1239
|
-
console.log(error);
|
|
1240
|
-
return;
|
|
1241
|
-
}
|
|
1242
|
-
if (!onSubmit) {
|
|
1243
|
-
let error = `
|
|
24
|
+
`;alert(b),console.log(b);return}if(!r){let c=`
|
|
1244
25
|
aio-login error=> missing onSubmit props,
|
|
1245
26
|
onSubmit type is =>
|
|
1246
27
|
(model:<model type>,mode:<mode type>)=>string|undefined
|
|
@@ -1250,36 +31,9 @@ function AIOLoginValidator(props) {
|
|
|
1250
31
|
register:{[field:string]:any},
|
|
1251
32
|
}
|
|
1252
33
|
<mode type> is 'OTPNumber' | 'OTPCode' | 'userName' | 'email' | 'phoneNumber' | 'forgetUserId' | 'forgetPassword' | 'register' | 'auth'
|
|
1253
|
-
`;
|
|
1254
|
-
alert(error);
|
|
1255
|
-
console.log(error);
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
if (typeof timer !== 'number') {
|
|
1259
|
-
let error = `aio-login error=> timer props should be an number`;
|
|
1260
|
-
alert(error);
|
|
1261
|
-
console.log(error);
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
if (!Array.isArray(modes) || !modes.filter(o => ['OTPNumber', 'userName', 'email', 'phoneNumber'].indexOf(o) !== -1).length) {
|
|
1265
|
-
let error = `
|
|
34
|
+
`;alert(c),console.log(c);return}if("number"!=typeof s){let y="aio-login error=> timer props should be an number";alert(y),console.log(y);return}if(!Array.isArray(o)||!o.filter(e=>-1!==["OTPNumber","userName","email","phoneNumber"].indexOf(e)).length){let T=`
|
|
1266
35
|
aio-login error=> modes props should be an array contain composite of 'OTPNumber' | 'userName' | 'email' | 'phoneNumber'
|
|
1267
|
-
`;
|
|
1268
|
-
alert(error);
|
|
1269
|
-
console.log(error);
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
if (modes.indexOf('OTPNumber') !== -1) {
|
|
1273
|
-
if (!otpLength) {
|
|
1274
|
-
let error = `aio-login error => otpLength props is not an number (for define length of otp code)`;
|
|
1275
|
-
alert(error);
|
|
1276
|
-
console.log(error);
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
if (register) {
|
|
1281
|
-
if (typeof register !== 'object' || ['mode', 'tab', 'button'].indexOf(register.type) === -1 || !Array.isArray(register.fields) || !register.fields.length) {
|
|
1282
|
-
let error = `
|
|
36
|
+
`;alert(T),console.log(T);return}if(-1!==o.indexOf("OTPNumber")&&!g){let I="aio-login error => otpLength props is not an number (for define length of otp code)";alert(I),console.log(I);return}if(l&&("object"!=typeof l||-1===["mode","tab","button"].indexOf(l.type)||!Array.isArray(l.fields)||!l.fields.length)){let $=`
|
|
1283
37
|
aio-login-error => register props should be an object contain :
|
|
1284
38
|
type : "mode" | "tab" | "button"
|
|
1285
39
|
tabText : string | undefined
|
|
@@ -1293,21 +47,4 @@ function AIOLoginValidator(props) {
|
|
|
1293
47
|
"fullname" | "firstname" | "lastname" | "username" | "address" | "email" | "fathername" | "phone" | "mobile" | "postalcode",
|
|
1294
48
|
"nationalcode" | "idcode" | "cardbank" | "state" | "city" | "gender" | "married" | "militaryservice" | "location"
|
|
1295
49
|
)
|
|
1296
|
-
`;
|
|
1297
|
-
alert(error);
|
|
1298
|
-
console.log(error);
|
|
1299
|
-
return;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
if (forget) {
|
|
1303
|
-
let message = `aio-login error=> forget props should be an object contain mode:'phoneNumber | email'`;
|
|
1304
|
-
if (typeof forget !== 'object') {
|
|
1305
|
-
alert(message);
|
|
1306
|
-
}
|
|
1307
|
-
if (['phoneNumber', 'email'].indexOf(forget.mode) === -1) {
|
|
1308
|
-
alert(message);
|
|
1309
|
-
console.log(message);
|
|
1310
|
-
return;
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
50
|
+
`;alert($),console.log($);return}if(d){let _="aio-login error=> forget props should be an object contain mode:'phoneNumber | email'";if("object"!=typeof d&&alert(_),-1===["phoneNumber","email"].indexOf(d.mode)){alert(_),console.log(_);return}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-login",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"react-virtual-dom": "^4.0.1",
|
|
16
16
|
"aio-popup": "^3.0.2",
|
|
17
17
|
"aio-storage": "^4.0.1",
|
|
18
|
-
"aio-input": "^3.0.
|
|
18
|
+
"aio-input": "^3.0.2"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|