@everymatrix/general-player-sms-verification-form 1.2.1 → 1.2.2
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-sms-verification-form",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"main": "index.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": "02dbae5b4d167acdb57c72905b756343a318870a"
|
|
40
40
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<svelte:options tag={null} />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
-
|
|
4
|
+
import { onMount } from 'svelte';
|
|
5
|
+
|
|
5
6
|
import { _, addNewMessages, setLocale, setupI18n } from './i18n';
|
|
6
7
|
import { SmsVerificationTranslations } from './translations';
|
|
7
8
|
|
|
@@ -12,20 +13,26 @@
|
|
|
12
13
|
export let number:string = '';
|
|
13
14
|
export let clientstyling:string = '';
|
|
14
15
|
export let clientstylingurl:string = '';
|
|
15
|
-
export let
|
|
16
|
+
export let translationurl:string = '';
|
|
16
17
|
|
|
17
18
|
let smsCode: number;
|
|
18
19
|
let isSmsValid: boolean = true;
|
|
19
20
|
let smsSendApiFailed:boolean = false;
|
|
20
|
-
let secondsLeft:number = 60;
|
|
21
21
|
let timer:any;
|
|
22
22
|
let customStylingContainer:HTMLElement;
|
|
23
23
|
let displayNone:boolean = false;
|
|
24
|
+
let setTimer = +localStorage.getItem('smsTimer') || 0;
|
|
25
|
+
let currentTimer = Date.now() / 1000 - setTimer;
|
|
26
|
+
let secondsLeft:number = 60 - Math.floor(currentTimer);
|
|
27
|
+
|
|
28
|
+
const regexValidators = {
|
|
29
|
+
numeric: /^[0-9]{0,6}$/,
|
|
30
|
+
}
|
|
24
31
|
|
|
25
32
|
setupI18n({ withLocale: 'en', translations: {}});
|
|
26
33
|
|
|
27
34
|
const setTranslationUrl = ():void => {
|
|
28
|
-
let url:string =
|
|
35
|
+
let url:string = translationurl;
|
|
29
36
|
|
|
30
37
|
fetch(url).then((res:any) => res.json())
|
|
31
38
|
.then((res) => {
|
|
@@ -72,6 +79,9 @@
|
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
const resendCode = async () => {
|
|
82
|
+
localStorage.setItem('smsTimer', JSON.stringify(Math.floor(Date.now() / 1000)));
|
|
83
|
+
checkSMSTimer();
|
|
84
|
+
|
|
75
85
|
try {
|
|
76
86
|
const res = await fetch(`${endpoint}/player/sms/token`,{
|
|
77
87
|
method: 'POST',
|
|
@@ -93,9 +103,7 @@
|
|
|
93
103
|
if(res.ok) {
|
|
94
104
|
tokenid = data.id;
|
|
95
105
|
smsSendApiFailed = false;
|
|
96
|
-
|
|
97
|
-
timerCountdown();
|
|
98
|
-
}, 1000);
|
|
106
|
+
timerCountdown();
|
|
99
107
|
} else {
|
|
100
108
|
smsSendApiFailed = true;
|
|
101
109
|
throw new Error("Failed to fetch");
|
|
@@ -138,10 +146,34 @@
|
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
148
|
|
|
149
|
+
const checkSMSTimer = () => {
|
|
150
|
+
if(currentTimer < 60) {
|
|
151
|
+
timer = setInterval(() => {
|
|
152
|
+
timerCountdown();
|
|
153
|
+
}, 1000);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const checkNumeric = (event) => {
|
|
158
|
+
if(!regexValidators.numeric.test(event.key) && event.keyCode !== 8 && event.keyCode !== 9 && event.keyCode !== 46) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
onMount(() => {
|
|
164
|
+
if(!playerid || !number) { /* fix for when trying to log in after registeration & mail confirmation (without sms confirmation),
|
|
165
|
+
upon switching between sms validation and register, the playerid and phone number would be lost */
|
|
166
|
+
let playerData = JSON.parse(localStorage.getItem('playerData'));
|
|
167
|
+
playerid = playerData.playerid;
|
|
168
|
+
number = playerData.number;
|
|
169
|
+
}
|
|
170
|
+
checkSMSTimer();
|
|
171
|
+
});
|
|
172
|
+
|
|
141
173
|
$: tokenid && playerid && endpoint;
|
|
142
174
|
$: clientstyling && customStylingContainer && setClientStyling();
|
|
143
175
|
$: clientstylingurl && customStylingContainer && setClientStylingURL();
|
|
144
|
-
$:
|
|
176
|
+
$: translationurl && setTranslationUrl();
|
|
145
177
|
</script>
|
|
146
178
|
|
|
147
179
|
|
|
@@ -158,7 +190,7 @@
|
|
|
158
190
|
<label for="SmsCode">
|
|
159
191
|
{$_('smsVerification.code')}:<span class="FormRequired" part="FormRequired">*</span>
|
|
160
192
|
</label>
|
|
161
|
-
<input bind:value={smsCode} type="
|
|
193
|
+
<input bind:value={smsCode} type="text" id="SmsCode" on:keydown={(e) => checkNumeric(e)} inputmode="numeric" pattern="[0-9]*" maxlength="6"/>
|
|
162
194
|
|
|
163
195
|
{#if !isSmsValid}
|
|
164
196
|
<p class="InvalidInput" part="InvalidInput">{$_('smsVerification.smsCodeError')}</p>
|
|
@@ -244,6 +276,9 @@
|
|
|
244
276
|
}
|
|
245
277
|
}
|
|
246
278
|
|
|
279
|
+
.LoginSMSHint {
|
|
280
|
+
margin-top: 20px;
|
|
281
|
+
}
|
|
247
282
|
.InvalidInput {
|
|
248
283
|
color: var(--emfe-w-color-error, #FD2839);
|
|
249
284
|
font-size: 10px;
|
package/src/translations.js
CHANGED
|
@@ -7,7 +7,8 @@ export const SmsVerificationTranslations = {
|
|
|
7
7
|
smsCodeError: 'Invalid sms code, you can resend the code',
|
|
8
8
|
resendMessage: 'A new verification code has been sent to your phone number.',
|
|
9
9
|
activate: 'Activate Account',
|
|
10
|
-
resend: 'Resend'
|
|
10
|
+
resend: 'Resend',
|
|
11
|
+
loginSMSHint: 'A new verification code has been sent to your phone number'
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
zh: {
|
|
@@ -16,9 +17,9 @@ export const SmsVerificationTranslations = {
|
|
|
16
17
|
errorTitle: '您的代码无效,您可以重新发送代码并重试',
|
|
17
18
|
code: '短信代码',
|
|
18
19
|
smsCodeError: '短信验证码无效,请重新发送验证码',
|
|
19
|
-
resendMessage: '
|
|
20
|
+
resendMessage: '新的验证码已发送至您的手机号码',
|
|
20
21
|
activate: '激活账户',
|
|
21
|
-
resend: '重发'
|
|
22
|
+
resend: '重发',
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
fr: {
|
|
@@ -29,7 +30,7 @@ export const SmsVerificationTranslations = {
|
|
|
29
30
|
smsCodeError: 'Code sms invalide, vous pouvez renvoyer le code',
|
|
30
31
|
resendMessage: 'Un nouveau code de vérification a été envoyé à votre numéro de téléphone.',
|
|
31
32
|
activate: 'Activer le compte',
|
|
32
|
-
resend: 'Renvoyer'
|
|
33
|
+
resend: 'Renvoyer',
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
tr: {
|
|
@@ -38,9 +39,9 @@ export const SmsVerificationTranslations = {
|
|
|
38
39
|
errorTitle: 'Your code was invalid, you can resend the code and try again',
|
|
39
40
|
code: 'Sms code',
|
|
40
41
|
smsCodeError: 'Invalid sms code, you can resend the code',
|
|
41
|
-
resendMessage: '
|
|
42
|
+
resendMessage: 'Telefon numaranıza yeni bir doğrulama kodu gönderildi.',
|
|
42
43
|
activate: 'Activate Account',
|
|
43
|
-
resend: 'Resend'
|
|
44
|
+
resend: 'Resend',
|
|
44
45
|
}
|
|
45
46
|
},
|
|
46
47
|
ro: {
|
|
@@ -49,9 +50,9 @@ export const SmsVerificationTranslations = {
|
|
|
49
50
|
errorTitle: 'Your code was invalid, you can resend the code and try again',
|
|
50
51
|
code: 'Sms code',
|
|
51
52
|
smsCodeError: 'Invalid sms code, you can resend the code',
|
|
52
|
-
resendMessage: '
|
|
53
|
+
resendMessage: 'Un nou cod de verificare a fost trimis catre numarul dumneavoastra.',
|
|
53
54
|
activate: 'Activate Account',
|
|
54
|
-
resend: 'Resend'
|
|
55
|
+
resend: 'Resend',
|
|
55
56
|
}
|
|
56
57
|
},
|
|
57
58
|
es: {
|
|
@@ -60,9 +61,9 @@ export const SmsVerificationTranslations = {
|
|
|
60
61
|
errorTitle: 'Your code was invalid, you can resend the code and try again',
|
|
61
62
|
code: 'Sms code',
|
|
62
63
|
smsCodeError: 'Invalid sms code, you can resend the code',
|
|
63
|
-
resendMessage: '
|
|
64
|
+
resendMessage: 'Se ha enviado un nuevo código de verificación a su número de teléfono.',
|
|
64
65
|
activate: 'Activate Account',
|
|
65
|
-
resend: 'Resend'
|
|
66
|
+
resend: 'Resend',
|
|
66
67
|
}
|
|
67
68
|
},
|
|
68
69
|
pt: {
|
|
@@ -71,9 +72,9 @@ export const SmsVerificationTranslations = {
|
|
|
71
72
|
errorTitle: 'Your code was invalid, you can resend the code and try again',
|
|
72
73
|
code: 'Sms code',
|
|
73
74
|
smsCodeError: 'Invalid sms code, you can resend the code',
|
|
74
|
-
resendMessage: '
|
|
75
|
+
resendMessage: 'Um novo código de verificação foi enviado para o seu número de telefone.',
|
|
75
76
|
activate: 'Activate Account',
|
|
76
|
-
resend: 'Resend'
|
|
77
|
+
resend: 'Resend',
|
|
77
78
|
}
|
|
78
79
|
},
|
|
79
80
|
};
|