@everymatrix/general-player-login-form 0.0.208 → 0.0.213

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.208",
3
+ "version": "0.0.213",
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": "38199cc25098bd517d1f8b13d7607e97cce49af4"
39
+ "gitHead": "0b49e65f747ec6eaac6ca9d4a4e7ee9702980bfc"
40
40
  }
@@ -4,6 +4,12 @@
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 = '';
8
14
  export let captchakey:string = '';
9
15
 
@@ -25,60 +31,72 @@
25
31
  let isPasswordVisible:boolean = false;
26
32
  let isFormDataInvalid:boolean = true;
27
33
 
34
+ let isOnNative:boolean = !!isNative(userAgent);
35
+ let waitingForCredentials:boolean = isOnNative;
36
+
37
+ let nativeCredentials:any = {};
38
+
39
+ const captchaKey = '6Lc7w8YcAAAAAEMHc_VNN9bqfVnILoUOHSHyZ0yn';
40
+
28
41
  const regexValidators = {
29
42
  user: /^(?!(?:.*\d){9})(?=(?:.*[a-zA-Z]){2})^[a-zA-Z\d]*$/,
30
43
  email: /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,
31
44
  password: /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,20}$/
32
45
  }
33
46
 
34
- const doRecaptcha = () => {
47
+ const doRecaptcha = ():Promise<string> => {
35
48
  return new Promise((resolve, reject) => {
49
+ // @ts-ignore
36
50
  grecaptcha.ready(() => {
37
- grecaptcha.execute(captchakey, { action: "submit" }).then((token) => {
38
- resolve(token);
39
- });
51
+ // @ts-ignore
52
+ grecaptcha.execute(captchakey, { action: "submit" })
53
+ .then((token:string) => {
54
+ resolve(token);
55
+ });
40
56
  });
41
57
  });
42
58
  }
43
59
 
44
- const showPassword = () => {
60
+ const showPassword = ():void => {
45
61
  isPasswordVisible = true;
46
62
  togglePasswordVisibility();
47
63
  }
48
64
 
49
- const hidePassword = () => {
65
+ const hidePassword = ():void => {
50
66
  isPasswordVisible = false;
51
67
  togglePasswordVisibility();
52
68
  }
53
69
 
54
- const togglePasswordVisibility = () => {
70
+ const togglePasswordVisibility = ():void => {
71
+ // @ts-ignore
55
72
  passwordVisibilityToggle.type = isPasswordVisible ? "text" : "password";
56
73
  }
57
74
 
58
- const switchToRegister = () => {
75
+ const switchToRegister = ():void => {
59
76
  window.postMessage({ type: "ToRegister" }, window.location.href);
60
77
  }
61
78
 
62
- const switchToForgotPassword = () => {
79
+ const switchToForgotPassword = ():void => {
63
80
  window.postMessage({ type: "NavForgotPassword" }, window.location.href);
64
81
  }
65
82
 
66
- const submitLoginForm = () => {
67
- doRecaptcha().then((token) => {
68
- if (checkUserIdentifier(userValue) && checkUserPassword(userPassword)) {
69
- loginFormData = {
70
- username: userValue,
71
- password: userPassword,
72
- token: token
73
- };
74
- isLoading = true;
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;
75
93
 
76
- window.postMessage({ type: "SubmitLoginForm", loginData: loginFormData }, window.location.href);
77
- }
78
- });
94
+ window.postMessage({ type: "SubmitLoginForm", loginData: loginFormData }, window.location.href);
95
+ }
96
+ });
79
97
  }
80
98
 
81
- const checkUserIdentifier = (user:string) => {
99
+ const checkUserIdentifier = (user:string):boolean => {
82
100
  if (regexValidators.user.test(user) || regexValidators.email.test(user)) {
83
101
  return true;
84
102
  } else {
@@ -86,7 +104,7 @@
86
104
  }
87
105
  }
88
106
 
89
- const checkUserPassword = (password:string) => {
107
+ const checkUserPassword = (password:string):boolean => {
90
108
  if (regexValidators.password.test(password)) {
91
109
  return true;
92
110
  } else {
@@ -94,36 +112,31 @@
94
112
  }
95
113
  }
96
114
 
97
- const validateUserName = () => {
115
+ const validateUserName = ():void => {
98
116
  invalidName = !checkUserIdentifier(userValue);
99
117
  isFormDataInvalid = (!invalidName && !invalidPassword && userPassword) ? false : true;
100
118
  }
101
119
 
102
- const validatePassword = () => {
120
+ const validatePassword = ():void => {
103
121
  invalidPassword = !checkUserPassword(userPassword);
104
122
  isFormDataInvalid = (!invalidName && !invalidPassword && userValue) ? false : true;
105
123
  }
106
124
 
107
- const messageHandler = (e:any) => {
125
+ const messageHandler = (e:MessageEvent):void => {
108
126
  if (e.data) {
109
- switch(e.data.type) {
110
-
127
+ switch (e.data.type) {
111
128
  case 'ModalLoader':
112
129
  isLoading = false;
113
- break;
130
+ break;
114
131
 
115
132
  case 'UserSessionID':
116
133
  isLoading = false;
117
- break;
134
+ break;
118
135
 
119
136
  case 'HasError':
120
137
  errorMessage = e.data.error;
121
138
  isLoading = false;
122
- break;
123
-
124
- default:
125
- // do nothing
126
- break;
139
+ break;
127
140
  }
128
141
  }
129
142
  }
@@ -132,10 +145,34 @@
132
145
  window.addEventListener('message', messageHandler, false);
133
146
  window.postMessage({ type: "LoginRegisterModalActive" }, window.location.href);
134
147
 
135
- if (isMobile(userAgent)) {
136
- mobileView = true;
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
+ }
137
172
  }
138
173
 
174
+ mobileView = isMobile(userAgent);
175
+
139
176
  return () => {
140
177
  window.removeEventListener('message', messageHandler);
141
178
  }
@@ -149,6 +186,7 @@
149
186
  </svelte:head>
150
187
 
151
188
  <div class="g-recaptcha" data-sitekey="{captchakey}" />
189
+
152
190
  {#if isLoading}
153
191
  <div class="ModalLoader"></div>
154
192
  {:else}