@everymatrix/general-player-login-form 0.0.207 → 0.0.212
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": "@everymatrix/general-player-login-form",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.212",
|
|
4
4
|
"main": "dist/general-player-login-form.js",
|
|
5
5
|
"svelte": "src/index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "899faeb0029947feb81828796644ba54ec467e1d"
|
|
40
40
|
}
|
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
import { onMount } from "svelte";
|
|
5
5
|
import { isMobile } from 'rvhelper';
|
|
6
6
|
|
|
7
|
+
import {
|
|
8
|
+
isNative,
|
|
9
|
+
call as callNative,
|
|
10
|
+
registerEventListener as registerNativeEventListener,
|
|
11
|
+
} from 'js-native-bridge';
|
|
12
|
+
|
|
7
13
|
export let imagedesktop:string = '';
|
|
14
|
+
export let captchakey:string = '';
|
|
8
15
|
|
|
9
16
|
let mobileView:boolean = false;
|
|
10
17
|
let userAgent:string = window.navigator.userAgent;
|
|
@@ -24,6 +31,11 @@
|
|
|
24
31
|
let isPasswordVisible:boolean = false;
|
|
25
32
|
let isFormDataInvalid:boolean = true;
|
|
26
33
|
|
|
34
|
+
let isOnNative:boolean = !!isNative(userAgent);
|
|
35
|
+
let waitingForCredentials:boolean = isOnNative;
|
|
36
|
+
|
|
37
|
+
let nativeCredentials:any = {};
|
|
38
|
+
|
|
27
39
|
const captchaKey = '6Lc7w8YcAAAAAEMHc_VNN9bqfVnILoUOHSHyZ0yn';
|
|
28
40
|
|
|
29
41
|
const regexValidators = {
|
|
@@ -32,54 +44,59 @@
|
|
|
32
44
|
password: /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,20}$/
|
|
33
45
|
}
|
|
34
46
|
|
|
35
|
-
const doRecaptcha = () => {
|
|
47
|
+
const doRecaptcha = ():Promise<string> => {
|
|
36
48
|
return new Promise((resolve, reject) => {
|
|
49
|
+
// @ts-ignore
|
|
37
50
|
grecaptcha.ready(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
grecaptcha.execute(captchakey, { action: "submit" })
|
|
53
|
+
.then((token:string) => {
|
|
54
|
+
resolve(token);
|
|
55
|
+
});
|
|
41
56
|
});
|
|
42
57
|
});
|
|
43
58
|
}
|
|
44
59
|
|
|
45
|
-
const showPassword = () => {
|
|
60
|
+
const showPassword = ():void => {
|
|
46
61
|
isPasswordVisible = true;
|
|
47
62
|
togglePasswordVisibility();
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
const hidePassword = () => {
|
|
65
|
+
const hidePassword = ():void => {
|
|
51
66
|
isPasswordVisible = false;
|
|
52
67
|
togglePasswordVisibility();
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
const togglePasswordVisibility = () => {
|
|
70
|
+
const togglePasswordVisibility = ():void => {
|
|
71
|
+
// @ts-ignore
|
|
56
72
|
passwordVisibilityToggle.type = isPasswordVisible ? "text" : "password";
|
|
57
73
|
}
|
|
58
74
|
|
|
59
|
-
const switchToRegister = () => {
|
|
75
|
+
const switchToRegister = ():void => {
|
|
60
76
|
window.postMessage({ type: "ToRegister" }, window.location.href);
|
|
61
77
|
}
|
|
62
78
|
|
|
63
|
-
const switchToForgotPassword = () => {
|
|
79
|
+
const switchToForgotPassword = ():void => {
|
|
64
80
|
window.postMessage({ type: "NavForgotPassword" }, window.location.href);
|
|
65
81
|
}
|
|
66
82
|
|
|
67
|
-
const submitLoginForm = () => {
|
|
68
|
-
doRecaptcha()
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
const submitLoginForm = ():void => {
|
|
84
|
+
doRecaptcha()
|
|
85
|
+
.then((token:string) => {
|
|
86
|
+
if (checkUserIdentifier(userValue) && checkUserPassword(userPassword)) {
|
|
87
|
+
loginFormData = {
|
|
88
|
+
username: userValue,
|
|
89
|
+
password: userPassword,
|
|
90
|
+
token: token
|
|
91
|
+
};
|
|
92
|
+
isLoading = true;
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
window.postMessage({ type: "SubmitLoginForm", loginData: loginFormData }, window.location.href);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
80
97
|
}
|
|
81
98
|
|
|
82
|
-
const checkUserIdentifier = (user:string) => {
|
|
99
|
+
const checkUserIdentifier = (user:string):boolean => {
|
|
83
100
|
if (regexValidators.user.test(user) || regexValidators.email.test(user)) {
|
|
84
101
|
return true;
|
|
85
102
|
} else {
|
|
@@ -87,7 +104,7 @@
|
|
|
87
104
|
}
|
|
88
105
|
}
|
|
89
106
|
|
|
90
|
-
const checkUserPassword = (password:string) => {
|
|
107
|
+
const checkUserPassword = (password:string):boolean => {
|
|
91
108
|
if (regexValidators.password.test(password)) {
|
|
92
109
|
return true;
|
|
93
110
|
} else {
|
|
@@ -95,36 +112,31 @@
|
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
|
|
98
|
-
const validateUserName = () => {
|
|
115
|
+
const validateUserName = ():void => {
|
|
99
116
|
invalidName = !checkUserIdentifier(userValue);
|
|
100
117
|
isFormDataInvalid = (!invalidName && !invalidPassword && userPassword) ? false : true;
|
|
101
118
|
}
|
|
102
119
|
|
|
103
|
-
const validatePassword = () => {
|
|
120
|
+
const validatePassword = ():void => {
|
|
104
121
|
invalidPassword = !checkUserPassword(userPassword);
|
|
105
122
|
isFormDataInvalid = (!invalidName && !invalidPassword && userValue) ? false : true;
|
|
106
123
|
}
|
|
107
124
|
|
|
108
|
-
const messageHandler = (e:
|
|
125
|
+
const messageHandler = (e:MessageEvent):void => {
|
|
109
126
|
if (e.data) {
|
|
110
|
-
switch(e.data.type) {
|
|
111
|
-
|
|
127
|
+
switch (e.data.type) {
|
|
112
128
|
case 'ModalLoader':
|
|
113
129
|
isLoading = false;
|
|
114
|
-
|
|
130
|
+
break;
|
|
115
131
|
|
|
116
132
|
case 'UserSessionID':
|
|
117
133
|
isLoading = false;
|
|
118
|
-
|
|
134
|
+
break;
|
|
119
135
|
|
|
120
136
|
case 'HasError':
|
|
121
137
|
errorMessage = e.data.error;
|
|
122
138
|
isLoading = false;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
default:
|
|
126
|
-
// do nothing
|
|
127
|
-
break;
|
|
139
|
+
break;
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
142
|
}
|
|
@@ -133,10 +145,34 @@
|
|
|
133
145
|
window.addEventListener('message', messageHandler, false);
|
|
134
146
|
window.postMessage({ type: "LoginRegisterModalActive" }, window.location.href);
|
|
135
147
|
|
|
136
|
-
if (
|
|
137
|
-
|
|
148
|
+
if (isOnNative) {
|
|
149
|
+
registerNativeEventListener(
|
|
150
|
+
'GET_CREDENTIALS',
|
|
151
|
+
(credentials:any):void => {
|
|
152
|
+
if (waitingForCredentials) {
|
|
153
|
+
if (credentials) {
|
|
154
|
+
const { username, password } = credentials;
|
|
155
|
+
|
|
156
|
+
userValue = username;
|
|
157
|
+
userPassword = password;
|
|
158
|
+
|
|
159
|
+
submitLoginForm();
|
|
160
|
+
} else {
|
|
161
|
+
waitingForCredentials = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const methodFound = callNative('GET_CREDENTIALS');
|
|
168
|
+
|
|
169
|
+
if (!methodFound) {
|
|
170
|
+
waitingForCredentials = false;
|
|
171
|
+
}
|
|
138
172
|
}
|
|
139
173
|
|
|
174
|
+
mobileView = isMobile(userAgent);
|
|
175
|
+
|
|
140
176
|
return () => {
|
|
141
177
|
window.removeEventListener('message', messageHandler);
|
|
142
178
|
}
|
|
@@ -144,10 +180,13 @@
|
|
|
144
180
|
</script>
|
|
145
181
|
|
|
146
182
|
<svelte:head>
|
|
147
|
-
|
|
183
|
+
{#if captchakey}
|
|
184
|
+
<script src="//www.google.com/recaptcha/api.js?render={captchakey}" async defer></script>
|
|
185
|
+
{/if}
|
|
148
186
|
</svelte:head>
|
|
149
187
|
|
|
150
|
-
<div class="g-recaptcha" data-sitekey="{
|
|
188
|
+
<div class="g-recaptcha" data-sitekey="{captchakey}" />
|
|
189
|
+
|
|
151
190
|
{#if isLoading}
|
|
152
191
|
<div class="ModalLoader"></div>
|
|
153
192
|
{:else}
|