mdkcontroller 1.4.6 → 1.4.8

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.
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
- .dk-overlay .dk-overlay_boder > strong {
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 #8f32b0ba;
82
+ border: 2px solid #7df3ff7a;
81
83
  border-radius: 10px;
82
- box-shadow: 0 0 9px 6px #8f32b0a3;
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 > span {
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,17 +84,17 @@ 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.innerText = 'X';
87
+ closeX.innerHTML = '<img src="' + (DK.varHide.currentScriptPath + '/close.png') + '" style="width:40px; height: 40px; object-fit: cover; position: absolute; margin: -20px;"/>';
88
88
  closeX.onclick = () => {
89
89
  document.body.removeChild(dk_overlay);
90
90
  };
91
- closeX.style.cssText = `font-size: 25px;cursor: pointer;float: right;font-weight: bold;color: #157272a6;margin: -18px -8px 0 0;`;
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
- overlay_inner.style.cssText = 'font-weight: bold;overflow-wrap: anywhere;max-width: 500px;z-index: 1;overflow: auto;';
97
+ overlay_inner.style.cssText = 'font-weight: bold;overflow-wrap: anywhere;max-width: 500px;z-index: 1;overflow: auto; font-size: larger;';
98
98
  overlay_inner.classList.add('dk-overlay_inner');
99
99
 
100
100
  overlay_box.appendChild(closeX);
@@ -119,8 +119,6 @@ const DK = {
119
119
  const maxWidthSpan = document.body.clientWidth - 60;
120
120
  dialog.style.maxWidth = (maxWidthSpan > 800 ? 800 : maxWidthSpan) + 'px';
121
121
  dk_overlay.style.display = 'block';
122
- const imgTag = dk_overlay.getElementsByTagName('img')[0];
123
- imgTag.style.height = dialog.parentNode.parentNode.clientHeight + 'px';
124
122
  },
125
123
  DKDataCache: {},
126
124
  buildFormEvent: () => {
@@ -163,6 +161,112 @@ const DK = {
163
161
  scriptJS.src = src;
164
162
  if (isModule) scriptJS.type = "module";
165
163
  document.getElementsByTagName("head")[0].appendChild(scriptJS);
164
+ },
165
+ Login: (username, password, newPassword = '') => {
166
+ let realHost = DK.realHost();
167
+ fetch(realHost + '/api/users/login', {
168
+ method: 'POST',
169
+ headers: {
170
+ 'Content-Type': 'application/json'
171
+ },
172
+ body: JSON.stringify({ userName: username, password: password, newPassword: newPassword })
173
+ })
174
+ .then((response) => response.json())
175
+ .then((data) => {
176
+ if (data.success) {
177
+ window.location.href = realHost + '/';
178
+ } else {
179
+ DK.showMessage(data.message, 3);
180
+ }
181
+ })
182
+ .catch(error => {
183
+ console.error('Login error:', error);
184
+ DK.showMessage('Login failed. Please try again.', 4);
185
+ });
186
+ },
187
+ RequestLoginBySW: () => {
188
+ try {
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 })
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
+ };
242
+ } catch (error) {
243
+ console.error("Error in WebSocket connection:", error);
244
+ DK.showMessage("Error connecting to WebSocket service.", 4);
245
+ }
246
+ },
247
+ Logout: () => {
248
+ // /users/logout
249
+ let realHost = DK.realHost();
250
+
251
+ fetch(realHost + '/api/users/logout', {
252
+ method: 'GET',
253
+ headers: {
254
+ 'Content-Type': 'application/json'
255
+ }
256
+ })
257
+ .then((response) => {
258
+ window.location.reload();
259
+ })
260
+ .catch(error => {
261
+ console.error('Logout error:', error);
262
+ DK.showMessage('Logout failed. Please try again.', 4);
263
+ });
264
+ },
265
+ realHost: () => {
266
+ let realHost = window.location.href;
267
+ realHost = realHost.substring(0, realHost.toLowerCase().indexOf('/cores/'));
268
+ realHost = realHost.substring(0, realHost.toLowerCase().indexOf('/pages'));
269
+ return realHost;
166
270
  }
167
271
  }
168
272
  Object.prototype.forEachExt = function (work) {
Binary file
@@ -3,7 +3,7 @@
3
3
 
4
4
  <head>
5
5
  <!-- Design by foolishdeveloper.com -->
6
- <title>Glassmorphism login Form Tutorial in html css</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">
@@ -90,7 +90,6 @@
90
90
  }
91
91
 
92
92
  form {
93
- height: 520px;
94
93
  width: 400px;
95
94
  background-color: rgba(255, 255, 255, 0.13);
96
95
  position: absolute;
@@ -101,7 +100,7 @@
101
100
  backdrop-filter: blur(10px);
102
101
  border: 2px solid rgba(255, 255, 255, 0.1);
103
102
  box-shadow: 0 0 40px rgba(8, 7, 16, 0.6);
104
- padding: 50px 35px;
103
+ padding: 22px 35px;
105
104
  }
106
105
 
107
106
  form * {
@@ -121,12 +120,12 @@
121
120
 
122
121
  label {
123
122
  display: block;
124
- margin-top: 30px;
125
123
  font-size: 16px;
126
124
  font-weight: 500;
127
125
  }
128
126
 
129
- input {
127
+ input[type="text"],
128
+ input[type="password"] {
130
129
  display: block;
131
130
  height: 50px;
132
131
  width: 100%;
@@ -143,11 +142,11 @@
143
142
  }
144
143
 
145
144
  button {
146
- margin-top: 50px;
145
+ margin-top: 10px;
146
+ height: 54px;
147
147
  width: 100%;
148
148
  background-color: #ffffff;
149
149
  color: #080710;
150
- padding: 15px 0;
151
150
  font-size: 18px;
152
151
  font-weight: 600;
153
152
  border-radius: 5px;
@@ -155,7 +154,7 @@
155
154
  }
156
155
 
157
156
  .social {
158
- margin-top: 30px;
157
+ margin-top: 10px;
159
158
  display: flex;
160
159
  }
161
160
 
@@ -197,44 +196,41 @@
197
196
  <label for="password">Password</label>
198
197
  <input type="password" placeholder="Password" id="password" name="password">
199
198
 
200
- <button>Log In</button>
199
+ <label for="requestChangePW">Request Change</label>
200
+ <input type="checkbox" placeholder="requestChangePW" id="requestChangePW" name="requestChangePW">
201
+ <script>
202
+ document.getElementById('requestChangePW').addEventListener('change', function () {
203
+ document.getElementById('changePasswordSection').hidden = !this.checked;
204
+ });
205
+ </script>
206
+ <div hidden id="changePasswordSection">
207
+ <label for="passwordChange">New Password</label>
208
+ <input type="password" placeholder="New Password (after login)" id="passwordChange" name="passwordChange">
209
+ </div>
210
+
211
+
212
+ <button>Login</button>
213
+
201
214
  <div class="social">
202
- <div><a href="register.html"><i class="fas fa-user-plus"></i> SignUp</a></div>
203
- <div><i class="fas fa-user-md"></i>Forgot ?</div>
215
+ <div style="display: flex; align-items: center; justify-content: center;"><a href="register.html"><i
216
+ class="fas fa-user-plus"></i> SignUp</a></div>
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>
219
+ </div>
204
220
  </div>
205
221
  </form>
222
+
206
223
  <script src="../file/dk.js"></script>
207
224
  <script src="../file/jquery-3.2.1.min.js"></script>
208
225
  <script>
226
+ function loginWithDKService() {
227
+ DK.RequestLoginBySW();
228
+ }
209
229
  $('#formLogin').on('submit', function (event) {
210
230
  if (true) {
211
231
  const form = event.currentTarget;
212
232
  const formData = new FormData(form);
213
- debugger;
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
- });
233
+ DK.Login(formData.get('userName'), formData.get('password'), formData.get('passwordChange') || '');
238
234
  }
239
235
  return false;
240
236
  });
@@ -3,7 +3,7 @@
3
3
 
4
4
  <head>
5
5
  <!-- Design by foolishdeveloper.com -->
6
- <title>Glassmorphism login Form Tutorial in html css</title>
6
+ <title>DK FORM SIGNIN</title>
7
7
 
8
8
  <meta charset="UTF-8">
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -30,6 +30,11 @@ export default (router, db) => {
30
30
  if (bodyParser.userName && bodyParser.password) {
31
31
  let userLoging = tbUser.find(f => f.username == bodyParser.userName.toLowerCase().trim() && auth.decrypt(f.password) == bodyParser.password);
32
32
  if (userLoging) {
33
+ if (bodyParser.newPassword) {
34
+ userLoging.password = auth.encrypt(bodyParser.newPassword);
35
+ await db.write();
36
+ }
37
+
33
38
  const userIdCode = auth.encrypt(userLoging.username);
34
39
  const accessToken = auth.createJWT(userLoging);
35
40
  const expiredValue = new Date();
@@ -48,6 +53,58 @@ export default (router, db) => {
48
53
  res.json({ message: `Không đủ thông tin để đăng nhập.`, success: false });
49
54
  }
50
55
  });
56
+ router.post("/users/loginByCenter", async (req, res) => {
57
+ const bodyParser = req.body;
58
+ if (bodyParser.tokenWS) {
59
+ fetch(`https://kkvalidatecenter.khanhnbd.io.vn/validateForApp`, {
60
+ method: "GET",
61
+ headers: {
62
+ 'Content-Type': 'application/json',
63
+ 'Authorization': "Bearer " + bodyParser.tokenWS
64
+ }
65
+ }).then(response => {
66
+ if (response.ok) {
67
+ return response.json()
68
+ }
69
+ return { success: false, message: "Yêu cầu tới server không thành công." };
70
+ })
71
+ .then(data => {
72
+ if (data.userName) {
73
+ {
74
+ let userLoging = tbUser.find(f => f.username == data.userName.toLowerCase().trim());
75
+ if (!userLoging) {
76
+ userLoging = {
77
+ id: getNumber('users'),
78
+ username: data.userName.toLowerCase().trim(),
79
+ email: "",
80
+ password: auth.encrypt(global.generateRandomString(100)),
81
+ active: true,
82
+ amount: 0,
83
+ signcode: global.generateRandomString(100),
84
+ };
85
+ tbUser.push(userLoging);
86
+ db.write();
87
+ }
88
+ const userIdCode = auth.encrypt(userLoging.username);
89
+ const accessToken = auth.createJWT(userLoging);
90
+ const expiredValue = new Date();
91
+ expiredValue.setMonth(expiredValue.getMonth() + 1);
92
+ res.cookie('access_token', accessToken, { httpOnly: true, expires: expiredValue });
93
+ res.cookie('sessionUExt', userIdCode, { expires: expiredValue });
94
+ res.cookie('username', userLoging.username, { expires: expiredValue });
95
+ if (bodyParser.attacktoh) {
96
+ res.header('access_token', accessToken);
97
+ }
98
+ res.json({ message: `Đăng nhập thành công.`, success: true });
99
+ }
100
+ } else {
101
+ res.json({ message: `Token không hợp lệ hoặc đã hết hạn.`, success: false })
102
+ }
103
+ });
104
+ } else {
105
+ res.json({ message: `Không đủ thông tin để đăng nhập.`, success: false });
106
+ }
107
+ });
51
108
  router.get("/users/tryGetAccess", (req, res) => {
52
109
  const isLogin = auth.validateBool(req, res);
53
110
  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.6",
11
+ "version": "1.4.8",
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
+ }