@ozdao/prometheus-framework 0.2.22 → 0.2.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,11 @@
1
1
  <template>
2
2
  <section class="t-center pd-medium">
3
3
  <!-- <img src="@/assets/images/icons/message1.png" class="i-extra mn-b-small"> -->
4
+
4
5
  <h3 class="mn-b-medium">
5
6
  {{ t('verifyNumberTitle') }}
6
7
  </h3>
8
+
7
9
  <p class="mn-b-big t-transp">{{ t('instructions') }}</p>
8
10
 
9
11
  <div class="w-100 mn-b-big flex-nowrap flex">
@@ -26,12 +28,33 @@
26
28
  @keydown="($event) => onKeyDown($event, 1)"
27
29
  class="w-100 h1 pd-small t-center bg-grey radius-small mn-r-small"
28
30
  >
29
- <input type="number" v-model="state.digits[2]" maxlength="1" @input="onInput(2)" @paste="($event) => onPaste($event, 2)" @keydown="($event) => onKeyDown($event, 2)" class="w-100 h1 pd-small t-center bg-grey radius-small mn-r-small">
30
- <input type="number" v-model="state.digits[3]" maxlength="1" @input="onInput(3)" @paste="($event) => onPaste($event, 3)" @keydown="($event) => onKeyDown($event, 3)" class="w-100 h1 pd-small t-center bg-grey radius-small">
31
+ <input
32
+ type="number"
33
+ v-model="state.digits[2]"
34
+ maxlength="1"
35
+ @input="onInput(2)"
36
+ @paste="($event) => onPaste($event, 2)"
37
+ @keydown="($event) => onKeyDown($event, 2)"
38
+ class="w-100 h1 pd-small t-center bg-grey radius-small mn-r-small"
39
+ >
40
+ <input
41
+ type="number"
42
+ v-model="state.digits[3]"
43
+ maxlength="1"
44
+ @input="onInput(3)"
45
+ @paste="($event) => onPaste($event, 3)"
46
+ @keydown="($event) => onKeyDown($event, 3)"
47
+ class="w-100 h1 pd-small t-center bg-grey radius-small"
48
+ >
31
49
  </div>
32
50
 
33
- <a v-if="resendTimer < 1" @click="sendAgain" class="t-blue">{{ t('resendCode') }}</a>
34
- <span v-else>{{resendTimer}} {{ t('secondsResend') }}</span>
51
+ <a v-if="resendTimer < 1" @click="sendAgain" class="t-blue">
52
+ {{ t('resendCode') }}
53
+ </a>
54
+
55
+ <span v-else>
56
+ {{resendTimer}} {{ t('secondsResend') }}
57
+ </span>
35
58
  </section>
36
59
  </template>
37
60
 
@@ -63,9 +86,6 @@
63
86
  watch(
64
87
  () => state.digits[0],
65
88
  (newVal) => {
66
- console.log(String(newVal));
67
- console.log(String(newVal).length);
68
-
69
89
  if (newVal && String(newVal).length > 1) {
70
90
  let newValArray = String(newVal).split('');
71
91
  console.log(newValArray);
@@ -91,20 +111,24 @@
91
111
 
92
112
  async function sendAgain () {
93
113
  try {
94
- await twofa.sendCode(auth.state.user, route.query.type, auth.state.user.phone ? 'phone' : 'email')
95
-
96
- resendTimer.value = 30;
97
-
98
- // Start the timer using `setInterval()`
99
- const timer = setInterval(() => {
100
- if (resendTimer.value > 0) {
101
- // Decrement the timer by 1 second
102
- resendTimer.value -= 1;
103
- } else {
104
- // Stop the timer when it reaches 0 seconds
105
- clearInterval(timer);
106
- }
107
- }, 1000);
114
+ await twofa.sendCode(
115
+ auth.state.user,
116
+ route.query.method,
117
+ route.query.type,
118
+ )
119
+
120
+ resendTimer.value = 30;
121
+
122
+ // Start the timer using `setInterval()`
123
+ const timer = setInterval(() => {
124
+ if (resendTimer.value > 0) {
125
+ // Decrement the timer by 1 second
126
+ resendTimer.value -= 1;
127
+ } else {
128
+ // Stop the timer when it reaches 0 seconds
129
+ clearInterval(timer);
130
+ }
131
+ }, 1000);
108
132
  } catch (error) {
109
133
  setError({ response: {data: { errorCode: "CODE_NOT_SENT"}}})
110
134
  }
@@ -141,44 +165,39 @@
141
165
  // };
142
166
 
143
167
  const onInput = (index) => {
144
- const inputs = document.querySelectorAll('input');
145
- const nextInput = inputs[index + 1];
146
- const prevInput = index > 0 ? inputs[index - 1] : null;
147
-
148
- // Переход на следующий инпут
149
- if (state.digits[index] !== '' && state.digits[index] !== null && state.digits[index] !== undefined && index < 4) {
150
- if (index < 3) nextInput.focus();
151
- else firstInput.value.focus();
152
- }
153
-
154
- // Переход на предыдущий инпут при удалении
155
- if ((state.digits[index] === null || state.digits[index] === undefined || state.digits[index] === '') && index > 0) {
156
- prevInput.focus();
157
- }
158
-
159
- // Проверка введенного кода
160
- if (state.digits.every(digit => digit !== '')) {
161
- const enteredCode = state.digits.join('');
162
- const correctCode = twofa.state.code.code.toString();
163
-
164
- if (enteredCode === correctCode) {
165
- twofa.state.code.isValid = true;
166
-
167
- router.push({
168
- path: '/auth/enter-password',
169
- query: { type: twofa.state.code.type, method: route.query.method }
170
- });
171
-
172
- } else {
173
- setError({ response: {data: { errorCode: "WRONG_CODE"}}})
174
- firstInput.value.focus()
175
- state.digits = ['', '', '', ''];
176
- }
177
- }
178
- };
179
-
180
- </script>
181
-
182
- <style lang="scss">
183
-
184
- </style>
168
+ const inputs = document.querySelectorAll('input');
169
+ const nextInput = inputs[index + 1];
170
+ const prevInput = index > 0 ? inputs[index - 1] : null;
171
+
172
+ // Переход на следующий инпут
173
+ if (state.digits[index] !== '' && state.digits[index] !== null && state.digits[index] !== undefined && index < 4) {
174
+ if (index < 3) nextInput.focus();
175
+ else firstInput.value.focus();
176
+ }
177
+
178
+ // Переход на предыдущий инпут при удалении
179
+ if ((state.digits[index] === null || state.digits[index] === undefined || state.digits[index] === '') && index > 0) {
180
+ prevInput.focus();
181
+ }
182
+
183
+ // Проверка введенного кода
184
+ if (state.digits.every(digit => digit !== '')) {
185
+ const enteredCode = state.digits.join('');
186
+ const correctCode = twofa.state.code.code.toString();
187
+
188
+ if (enteredCode === correctCode) {
189
+ twofa.state.code.isValid = true;
190
+
191
+ router.push({
192
+ path: '/auth/enter-password',
193
+ query: { type: twofa.state.code.type, method: route.query.method }
194
+ });
195
+
196
+ } else {
197
+ setError({ response: {data: { errorCode: "WRONG_CODE"}}})
198
+ firstInput.value.focus()
199
+ state.digits = ['', '', '', ''];
200
+ }
201
+ }
202
+ };
203
+ </script>
@@ -5,7 +5,7 @@ const middlewareFactory = require('@pf/src/modules/middlewares/server');
5
5
  // Routes
6
6
  module.exports = function(app, db) {
7
7
  const controller = controllerFactory(db);
8
- const { verifySignUp } = middlewareFactory(db);
8
+ const { verifySignUp, verifyUser } = middlewareFactory(db);
9
9
 
10
10
  app.use(function(req, res, next) {
11
11
  res.header(
@@ -23,4 +23,12 @@ module.exports = function(app, db) {
23
23
  ],
24
24
  controller.sendcode
25
25
  );
26
+
27
+ app.post(
28
+ "/api/twofa/sendcodereset",
29
+ [
30
+ verifyUser.checkUserExist
31
+ ],
32
+ controller.sendcode
33
+ );
26
34
  };
@@ -19,8 +19,11 @@ const state = reactive({
19
19
  });
20
20
 
21
21
  async function sendCode (user, method, type) {
22
+ let api = '/api/twofa/sendcode'
22
23
 
23
- return await $axios.post('/api/twofa/sendcode', {
24
+ if (method === 'reset-password') api = '/api/twofa/sendcodereset'
25
+
26
+ return await $axios.post(api, {
24
27
  phone: user.phone.number,
25
28
  email: user.email,
26
29
  method: method,
@@ -32,7 +32,7 @@ async function sendEmail(to, subject, text) {
32
32
  }
33
33
 
34
34
  async function sendSms(phone, message) {
35
- const sessionUrl = `https://api.sms.to/sms/send?api_key=${process.env.SMS_API_KEY}&bypass_optout=true&to=${phone}&message=${encodeURIComponent(message)}&sender_id=${process.env.APP_NAME}`;
35
+ const sessionUrl = `https://api.sms.to/sms/send?api_key=${process.env.SMS_API_KEY}&bypass_optout=true&to=${phone}&message=${encodeURIComponent(message)}&sender_id=${encodeURIComponent(process.env.APP_NAME)}`;
36
36
 
37
37
  console.log(`Phone:${phone} message:${message}`);
38
38
 
@@ -20,6 +20,7 @@ const middlewareFactory = (db) => {
20
20
  const user = await User.findOne(query).exec();
21
21
 
22
22
  if (!user) {
23
+ console.log(query)
23
24
  res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
24
25
  return;
25
26
  }