mdkcontroller 1.4.6 → 1.4.7
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/close.png +0 -0
- package/Cores/file/dk.css +8 -5
- package/Cores/file/dk.js +109 -3
- package/Cores/login/iconAuthen.png +0 -0
- package/Cores/login/index.html +15 -31
- package/Cores/login/register.html +1 -1
- package/dk_modules/users.js +52 -0
- package/package.json +2 -2
|
Binary file
|
package/Cores/file/dk.css
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
0% {
|
|
12
12
|
transform: rotate(0deg);
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
100% {
|
|
15
16
|
transform: rotate(360deg);
|
|
16
17
|
}
|
|
@@ -72,21 +73,22 @@
|
|
|
72
73
|
justify-content: center;
|
|
73
74
|
align-items: center;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
|
|
77
|
+
.dk-overlay .dk-overlay_boder>strong {
|
|
76
78
|
z-index: 10;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
.dk-overlay .dk-overlay_boder .dk-overlay_box {
|
|
80
|
-
border: 2px solid #
|
|
82
|
+
border: 2px solid #7df3ff7a;
|
|
81
83
|
border-radius: 10px;
|
|
82
|
-
box-shadow: 0 0
|
|
84
|
+
box-shadow: 0 0 16px 11px #7df3ff7a;
|
|
83
85
|
padding: 15px;
|
|
84
86
|
background-color: white;
|
|
85
87
|
min-width: 380px;
|
|
86
88
|
min-height: 200px;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
.dk-overlay .dk-overlay_boder
|
|
91
|
+
.dk-overlay .dk-overlay_boder>span {
|
|
90
92
|
font-size: 40px;
|
|
91
93
|
cursor: pointer;
|
|
92
94
|
}
|
|
@@ -94,6 +96,7 @@
|
|
|
94
96
|
.dk-transiton500 {
|
|
95
97
|
transition: all ease 0.5s;
|
|
96
98
|
}
|
|
99
|
+
|
|
97
100
|
.dk-transiton300 {
|
|
98
101
|
transition: all ease 0.3s;
|
|
99
|
-
}
|
|
102
|
+
}
|
package/Cores/file/dk.js
CHANGED
|
@@ -84,15 +84,15 @@ const DK = {
|
|
|
84
84
|
overlay_box.classList.add('dk-overlay_box');
|
|
85
85
|
if (overlay_box) {
|
|
86
86
|
const closeX = document.createElement('span');
|
|
87
|
-
closeX.
|
|
87
|
+
closeX.innerHTML = '<img src="' + (DK.varHide.currentScriptPath + '/close.png') + '" style="width:40px; height: 40px; object-fit: cover; position: absolute; margin: -15px;"/>';
|
|
88
88
|
closeX.onclick = () => {
|
|
89
89
|
document.body.removeChild(dk_overlay);
|
|
90
90
|
};
|
|
91
|
-
closeX.style.cssText = `
|
|
91
|
+
closeX.style.cssText = `cursor: pointer;float: right;`;
|
|
92
92
|
|
|
93
93
|
const divImage = document.createElement('div');
|
|
94
94
|
divImage.style.cssText = `height: 100%;display: flex;flex-direction: column;align-items: center;justify-content: center;`;
|
|
95
|
-
divImage.innerHTML = `<img style='position: fixed;opacity: 0.1;' src='${(DK.varHide.currentScriptPath + '/' + imageName)}'/>`;
|
|
95
|
+
divImage.innerHTML = `<img style='position: fixed;opacity: 0.1; width: 200px;' src='${(DK.varHide.currentScriptPath + '/' + imageName)}'/>`;
|
|
96
96
|
const overlay_inner = document.createElement('span');
|
|
97
97
|
overlay_inner.style.cssText = 'font-weight: bold;overflow-wrap: anywhere;max-width: 500px;z-index: 1;overflow: auto;';
|
|
98
98
|
overlay_inner.classList.add('dk-overlay_inner');
|
|
@@ -163,6 +163,112 @@ const DK = {
|
|
|
163
163
|
scriptJS.src = src;
|
|
164
164
|
if (isModule) scriptJS.type = "module";
|
|
165
165
|
document.getElementsByTagName("head")[0].appendChild(scriptJS);
|
|
166
|
+
},
|
|
167
|
+
Login: (username, password) => {
|
|
168
|
+
let realHost = DK.realHost();
|
|
169
|
+
fetch(realHost + '/api/users/login', {
|
|
170
|
+
method: 'POST',
|
|
171
|
+
headers: {
|
|
172
|
+
'Content-Type': 'application/json'
|
|
173
|
+
},
|
|
174
|
+
body: JSON.stringify({ userName: username, password: password })
|
|
175
|
+
})
|
|
176
|
+
.then((response) => response.json())
|
|
177
|
+
.then((data) => {
|
|
178
|
+
if (data.success) {
|
|
179
|
+
window.location.href = realHost + '/';
|
|
180
|
+
} else {
|
|
181
|
+
DK.showMessage(data.message, 3);
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
.catch(error => {
|
|
185
|
+
console.error('Login error:', error);
|
|
186
|
+
DK.showMessage('Login failed. Please try again.', 4);
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
RequestLoginBySW: () => {
|
|
190
|
+
try {
|
|
191
|
+
let realHost = DK.realHost();
|
|
192
|
+
DK.showBusy(true, "Connecting to WebSocket service...");
|
|
193
|
+
let socket = new WebSocket("ws://localhost:6899");
|
|
194
|
+
socket.onopen = () => {
|
|
195
|
+
const url = new URL(window.location.href);
|
|
196
|
+
socket.send(JSON.stringify({
|
|
197
|
+
action: "login",
|
|
198
|
+
app: url.origin
|
|
199
|
+
}));
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
socket.onmessage = (event) => {
|
|
203
|
+
const data = JSON.parse(event.data);
|
|
204
|
+
if (data.success) {
|
|
205
|
+
fetch(realHost + "/api/users/loginByCenter", {
|
|
206
|
+
method: "POST",
|
|
207
|
+
headers: {
|
|
208
|
+
'Content-Type': 'application/json'
|
|
209
|
+
},
|
|
210
|
+
body: JSON.stringify({ tokenWS: data.token })
|
|
211
|
+
})
|
|
212
|
+
.then(response => {
|
|
213
|
+
if (response.ok) {
|
|
214
|
+
return response.json();
|
|
215
|
+
} else {
|
|
216
|
+
throw new Error('API request failed');
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
.then(data => {
|
|
220
|
+
if (data.success) {
|
|
221
|
+
window.location.href = realHost + '/';
|
|
222
|
+
} else {
|
|
223
|
+
DK.showMessage(data.message, 3);
|
|
224
|
+
DK.showBusy(false, "Connecting to WebSocket service...");
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
.catch(error => {
|
|
228
|
+
DK.showMessage(error, 4);
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
DK.showMessage(data.message, 3);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
socket.onclose = () => {
|
|
236
|
+
console.log("Disconnected.");
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
socket.onerror = (error) => {
|
|
240
|
+
console.error("WebSocket error:", error);
|
|
241
|
+
DK.showMessage("WebSocket error: " + error.message, 4);
|
|
242
|
+
DK.showBusy(false, "Connecting to WebSocket service...");
|
|
243
|
+
};
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error("Error in WebSocket connection:", error);
|
|
246
|
+
DK.showMessage("Error connecting to WebSocket service.", 4);
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
Logout: () => {
|
|
250
|
+
// /users/logout
|
|
251
|
+
let realHost = DK.realHost();
|
|
252
|
+
|
|
253
|
+
fetch(realHost + '/api/users/logout', {
|
|
254
|
+
method: 'GET',
|
|
255
|
+
headers: {
|
|
256
|
+
'Content-Type': 'application/json'
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
.then((response) => {
|
|
260
|
+
window.location.reload();
|
|
261
|
+
})
|
|
262
|
+
.catch(error => {
|
|
263
|
+
console.error('Logout error:', error);
|
|
264
|
+
DK.showMessage('Logout failed. Please try again.', 4);
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
realHost: () => {
|
|
268
|
+
let realHost = window.location.href;
|
|
269
|
+
realHost = realHost.substring(0, realHost.toLowerCase().indexOf('/cores/'));
|
|
270
|
+
realHost = realHost.substring(0, realHost.toLowerCase().indexOf('/pages'));
|
|
271
|
+
return realHost;
|
|
166
272
|
}
|
|
167
273
|
}
|
|
168
274
|
Object.prototype.forEachExt = function (work) {
|
|
Binary file
|
package/Cores/login/index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
<head>
|
|
5
5
|
<!-- Design by foolishdeveloper.com -->
|
|
6
|
-
<title>
|
|
6
|
+
<title>DK FORM LOGIN</title>
|
|
7
7
|
<meta charset="UTF-8">
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
9
9
|
<link rel="icon" href="../file/iconlogin.png" type="image/x-icon">
|
|
@@ -143,11 +143,11 @@
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
button {
|
|
146
|
-
margin-top:
|
|
146
|
+
margin-top: 30px;
|
|
147
|
+
height: 54px;
|
|
147
148
|
width: 100%;
|
|
148
149
|
background-color: #ffffff;
|
|
149
150
|
color: #080710;
|
|
150
|
-
padding: 15px 0;
|
|
151
151
|
font-size: 18px;
|
|
152
152
|
font-weight: 600;
|
|
153
153
|
border-radius: 5px;
|
|
@@ -197,44 +197,28 @@
|
|
|
197
197
|
<label for="password">Password</label>
|
|
198
198
|
<input type="password" placeholder="Password" id="password" name="password">
|
|
199
199
|
|
|
200
|
-
<button>
|
|
200
|
+
<button>Login</button>
|
|
201
|
+
|
|
201
202
|
<div class="social">
|
|
202
|
-
<div><a href="register.html"><i
|
|
203
|
-
|
|
203
|
+
<div style="display: flex; align-items: center; justify-content: center;"><a href="register.html"><i
|
|
204
|
+
class="fas fa-user-plus"></i> SignUp</a></div>
|
|
205
|
+
<div style="display: flex; align-items: center; justify-content: center;" onclick="loginWithDKService()">
|
|
206
|
+
<img src="iconAuthen.png" width="40" height="40" /><span>Login WS</span>
|
|
207
|
+
</div>
|
|
204
208
|
</div>
|
|
205
209
|
</form>
|
|
210
|
+
|
|
206
211
|
<script src="../file/dk.js"></script>
|
|
207
212
|
<script src="../file/jquery-3.2.1.min.js"></script>
|
|
208
213
|
<script>
|
|
214
|
+
function loginWithDKService() {
|
|
215
|
+
DK.RequestLoginBySW();
|
|
216
|
+
}
|
|
209
217
|
$('#formLogin').on('submit', function (event) {
|
|
210
218
|
if (true) {
|
|
211
219
|
const form = event.currentTarget;
|
|
212
220
|
const formData = new FormData(form);
|
|
213
|
-
|
|
214
|
-
fetch(form.action, {
|
|
215
|
-
method: "POST",
|
|
216
|
-
headers: {
|
|
217
|
-
'Content-Type': 'application/json'
|
|
218
|
-
},
|
|
219
|
-
body: JSON.stringify(Object.fromEntries(formData.entries()))
|
|
220
|
-
})
|
|
221
|
-
.then(response => {
|
|
222
|
-
if (response.ok) {
|
|
223
|
-
return response.json();
|
|
224
|
-
} else {
|
|
225
|
-
throw new Error('API request failed');
|
|
226
|
-
}
|
|
227
|
-
})
|
|
228
|
-
.then(data => {
|
|
229
|
-
if (data.success) {
|
|
230
|
-
window.location.href = "../../";
|
|
231
|
-
} else {
|
|
232
|
-
DK.showMessage(data.message, 3);
|
|
233
|
-
}
|
|
234
|
-
})
|
|
235
|
-
.catch(error => {
|
|
236
|
-
DK.showMessage(error, 4);
|
|
237
|
-
});
|
|
221
|
+
DK.Login(formData.get('userName'), formData.get('password'));
|
|
238
222
|
}
|
|
239
223
|
return false;
|
|
240
224
|
});
|
package/dk_modules/users.js
CHANGED
|
@@ -48,6 +48,58 @@ export default (router, db) => {
|
|
|
48
48
|
res.json({ message: `Không đủ thông tin để đăng nhập.`, success: false });
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
+
router.post("/users/loginByCenter", async (req, res) => {
|
|
52
|
+
const bodyParser = req.body;
|
|
53
|
+
if (bodyParser.tokenWS) {
|
|
54
|
+
fetch(`https://kkvalidatecenter.khanhnbd.io.vn/validateForApp`, {
|
|
55
|
+
method: "GET",
|
|
56
|
+
headers: {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
'Authorization': "Bearer " + bodyParser.tokenWS
|
|
59
|
+
}
|
|
60
|
+
}).then(response => {
|
|
61
|
+
if (response.ok) {
|
|
62
|
+
return response.json()
|
|
63
|
+
}
|
|
64
|
+
return { success: false, message: "Yêu cầu tới server không thành công." };
|
|
65
|
+
})
|
|
66
|
+
.then(data => {
|
|
67
|
+
if (data.userName) {
|
|
68
|
+
{
|
|
69
|
+
let userLoging = tbUser.find(f => f.username == data.userName.toLowerCase().trim());
|
|
70
|
+
if (!userLoging) {
|
|
71
|
+
userLoging = {
|
|
72
|
+
id: getNumber('users'),
|
|
73
|
+
username: data.userName.toLowerCase().trim(),
|
|
74
|
+
email: "",
|
|
75
|
+
password: auth.encrypt(global.generateRandomString(100)),
|
|
76
|
+
active: true,
|
|
77
|
+
amount: 0,
|
|
78
|
+
signcode: global.generateRandomString(100),
|
|
79
|
+
};
|
|
80
|
+
tbUser.push(userLoging);
|
|
81
|
+
db.write();
|
|
82
|
+
}
|
|
83
|
+
const userIdCode = auth.encrypt(userLoging.username);
|
|
84
|
+
const accessToken = auth.createJWT(userLoging);
|
|
85
|
+
const expiredValue = new Date();
|
|
86
|
+
expiredValue.setMonth(expiredValue.getMonth() + 1);
|
|
87
|
+
res.cookie('access_token', accessToken, { httpOnly: true, expires: expiredValue });
|
|
88
|
+
res.cookie('sessionUExt', userIdCode, { expires: expiredValue });
|
|
89
|
+
res.cookie('username', userLoging.username, { expires: expiredValue });
|
|
90
|
+
if (bodyParser.attacktoh) {
|
|
91
|
+
res.header('access_token', accessToken);
|
|
92
|
+
}
|
|
93
|
+
res.json({ message: `Đăng nhập thành công.`, success: true });
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
res.json({ message: `Token không hợp lệ hoặc đã hết hạn.`, success: false })
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
res.json({ message: `Không đủ thông tin để đăng nhập.`, success: false });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
51
103
|
router.get("/users/tryGetAccess", (req, res) => {
|
|
52
104
|
const isLogin = auth.validateBool(req, res);
|
|
53
105
|
if (isLogin == 1) {
|
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.
|
|
11
|
+
"version": "1.4.7",
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "KHANHNBD <khanh272421@gmail.com>",
|
|
14
14
|
"license": "ISC",
|
|
@@ -25,4 +25,4 @@
|
|
|
25
25
|
"Cores/",
|
|
26
26
|
"dk_modules/"
|
|
27
27
|
]
|
|
28
|
-
}
|
|
28
|
+
}
|