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 +2 -0
- package/Cores/file/dk.js +36 -53
- package/Cores/login/index.html +2 -2
- package/demoApp.js +2 -2
- package/dk_modules/users.js +16 -8
- package/package.json +1 -1
package/Cores/file/dk.css
CHANGED
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
|
-
|
|
187
|
+
RequestLoginByAuthenticator: (username, newpass) => {
|
|
188
188
|
try {
|
|
189
189
|
let realHost = DK.realHost();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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);
|
package/Cores/login/index.html
CHANGED
|
@@ -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>
|
|
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.
|
|
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" });
|
package/dk_modules/users.js
CHANGED
|
@@ -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/
|
|
56
|
+
router.post("/users/loginByAuthenticator", async (req, res) => {
|
|
57
57
|
const bodyParser = req.body;
|
|
58
|
-
|
|
59
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
-
|
|
80
|
+
const parsedData = data;
|
|
81
|
+
if (parsedData.success && parsedData.login) {
|
|
74
82
|
{
|
|
75
|
-
let userLoging = tbUser.find(f => f.username ==
|
|
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:
|
|
87
|
+
username: username.toLowerCase().trim(),
|
|
80
88
|
email: "",
|
|
81
89
|
password: auth.encrypt(bodyParser.newPassword || global.generateRandomString(100)),
|
|
82
90
|
active: true,
|