mdkcontroller 1.4.17 → 1.5.0

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/Cores/file/dk.css CHANGED
@@ -76,6 +76,8 @@
76
76
 
77
77
  .dk-overlay .dk-overlay_boder>strong {
78
78
  z-index: 10;
79
+ max-width: 280px;
80
+ text-align: center;
79
81
  }
80
82
 
81
83
  .dk-overlay .dk-overlay_boder .dk-overlay_box {
package/Cores/file/dk.js CHANGED
@@ -184,61 +184,44 @@ const DK = {
184
184
  DK.showMessage('Login failed. Please try again.', 4);
185
185
  });
186
186
  },
187
- RequestLoginBySW: (newpass) => {
187
+ RequestLoginByAuthenticator: (username, newpass) => {
188
188
  try {
189
189
  let realHost = DK.realHost();
190
- DK.showBusy(true, "Connecting to WebSocket service...");
191
- let socket = new WebSocket("ws://localhost:6899");
192
- socket.onopen = () => {
193
- const url = new URL(window.location.href);
194
- socket.send(JSON.stringify({
195
- action: "login",
196
- app: url.origin
197
- }));
198
- };
199
-
200
- socket.onmessage = (event) => {
201
- const data = JSON.parse(event.data);
202
- if (data.success) {
203
- fetch(realHost + "/api/users/loginByCenter", {
204
- method: "POST",
205
- headers: {
206
- 'Content-Type': 'application/json'
207
- },
208
- body: JSON.stringify({ tokenWS: data.token, newPassword: newpass })
209
- })
210
- .then(response => {
211
- if (response.ok) {
212
- return response.json();
213
- } else {
214
- throw new Error('API request failed');
215
- }
216
- })
217
- .then(data => {
218
- if (data.success) {
219
- window.location.href = realHost + '/';
220
- } else {
221
- DK.showMessage(data.message, 3);
222
- DK.showBusy(false, "Connecting to WebSocket service...");
223
- }
224
- })
225
- .catch(error => {
226
- DK.showMessage(error, 4);
227
- });
228
- } else {
229
- DK.showMessage(data.message, 3);
230
- }
231
- };
232
-
233
- socket.onclose = () => {
234
- console.log("Disconnected.");
235
- };
236
-
237
- socket.onerror = (error) => {
238
- console.error("WebSocket error:", error);
239
- DK.showMessage("WebSocket error: " + error.message, 4);
240
- DK.showBusy(false, "Connecting to WebSocket service...");
241
- };
190
+ //random number 0-99
191
+ const secrectNum = Math.floor(Math.random() * 100);
192
+ const messW = "Đang yêu cầu xác thực đến DKAuthenticator, Vui lòng chọn " + secrectNum + " trên ứng dụng DKAuthenticator để tiếp tục.";
193
+ DK.showBusy(true, messW);
194
+ fetch(realHost + '/api/users/loginByAuthenticator', {
195
+ method: "POST",
196
+ headers: {
197
+ 'Content-Type': 'application/json'
198
+ },
199
+ body: JSON.stringify({
200
+ username: username,
201
+ appname: "web " + realHost,
202
+ number: secrectNum,
203
+ newpass: newpass
204
+ })
205
+ })
206
+ .then(response => {
207
+ if (response.ok) {
208
+ return response.json();
209
+ } else {
210
+ throw new Error('API request failed');
211
+ }
212
+ })
213
+ .then(data => {
214
+ if (data.success) {
215
+ window.location.href = realHost + '/';
216
+ } else {
217
+ DK.showMessage(data.message, 3);
218
+ DK.showBusy(false, messW);
219
+ }
220
+ })
221
+ .catch(error => {
222
+ DK.showBusy(false, messW);
223
+ DK.showMessage(error, 4);
224
+ });
242
225
  } catch (error) {
243
226
  console.error("Error in WebSocket connection:", error);
244
227
  DK.showMessage("Error connecting to WebSocket service.", 4);
@@ -215,7 +215,7 @@
215
215
  <div style="display: flex; align-items: center; justify-content: center;"><a href="register.html"><i
216
216
  class="fas fa-user-plus"></i> SignUp</a></div>
217
217
  <div style="display: flex; align-items: center; justify-content: center;" onclick="loginWithDKService()">
218
- <img src="iconAuthen.png" width="40" height="40" /><span>Login WS</span>
218
+ <img src="iconAuthen.png" width="40" height="40" /><span>Auth App</span>
219
219
  </div>
220
220
  </div>
221
221
  </form>
@@ -227,7 +227,7 @@
227
227
  function loginWithDKService() {
228
228
  const form = el('formLogin');
229
229
  const formData = new FormData(form);
230
- DK.RequestLoginBySW(formData.get('passwordChange') || '');
230
+ DK.RequestLoginByAuthenticator(formData.get('userName'), formData.get('passwordChange') || '');
231
231
  }
232
232
  $('#formLogin').on('submit', function (event) {
233
233
  if (true) {
package/demoApp.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // import { Root } from "./index.js";
2
2
  import { Router } from "express";
3
3
  // import * as socketIO from "socket.io";
4
- import { Root } from "mdkcontroller";
4
+ import { Root, Sequense } from "mdkcontroller";
5
5
 
6
6
  const cfg = {
7
7
  redirectHome: function (req, res) {
@@ -24,7 +24,7 @@ const _sv = await Root("khanhnbd", cfg);
24
24
  // global.generateRandomString
25
25
  // globbal.webAppPath = __parentAppPath;
26
26
  global.db.data.yourTableName = global.db.data.yourTableName ?? [];
27
-
27
+ const userTable = global.db.data.users;
28
28
  const newRouterApi = Router();
29
29
  newRouterApi.get("/demoFunction/gets", global.auth.validate, (req, res) => {
30
30
  res.json({ message: "Get all users" });
@@ -53,30 +53,38 @@ export default (router, db) => {
53
53
  res.json({ message: `Không đủ thông tin để đăng nhập.`, success: false });
54
54
  }
55
55
  });
56
- router.post("/users/loginByCenter", async (req, res) => {
56
+ router.post("/users/loginByAuthenticator", async (req, res) => {
57
57
  const bodyParser = req.body;
58
- if (bodyParser.tokenWS) {
59
- fetch(`https://kkvalidatecenter.khanhnbd.io.vn/loginByToken`, {
58
+ const username = bodyParser.username;
59
+ if (username) {
60
+ fetch(`https://kkvalidatecenter.khanhnbd.io.vn/requestLoginByAuthenticator`, {
60
61
  method: "POST",
61
62
  headers: {
62
63
  'Content-Type': 'application/json',
63
64
  },
64
- body: JSON.stringify({ sign: bodyParser.tokenWS, DatabaseName: global.appName })
65
+ body: JSON.stringify({
66
+ username: bodyParser.username,
67
+ appname: bodyParser.appname || "web " + req.headers.host,
68
+ number: bodyParser.number
69
+ })
65
70
  }).then(async response => {
66
71
  if (response.ok) {
67
- return response.json()
72
+ const text = await response.text();
73
+ const data = JSON.parse(text);
74
+ return data;
68
75
  }
69
76
  const text = await response.text();
70
77
  return { success: false, message: `${response.status}-${text}` };
71
78
  })
72
79
  .then(data => {
73
- if (data.userName) {
80
+ const parsedData = data;
81
+ if (parsedData.success && parsedData.login) {
74
82
  {
75
- let userLoging = tbUser.find(f => f.username == data.userName.toLowerCase().trim());
83
+ let userLoging = tbUser.find(f => f.username == username.toLowerCase().trim());
76
84
  if (!userLoging) {
77
85
  userLoging = {
78
86
  id: getNumber('users'),
79
- username: data.userName.toLowerCase().trim(),
87
+ username: username.toLowerCase().trim(),
80
88
  email: "",
81
89
  password: auth.encrypt(bodyParser.newPassword || global.generateRandomString(100)),
82
90
  active: true,
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "node-cache": "^5.1.2"
9
9
  },
10
10
  "name": "mdkcontroller",
11
- "version": "1.4.17",
11
+ "version": "1.5.0",
12
12
  "keywords": [],
13
13
  "author": "KHANHNBD <khanh272421@gmail.com>",
14
14
  "license": "ISC",