express-sweet-generator 2.0.4 → 2.0.6
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/README.md +6 -6
- package/bin/express-sweet-cli.js +4 -4
- package/package.json +1 -1
- package/screencaps/404-error.jpeg +0 -0
- package/screencaps/500-error.jpeg +0 -0
- package/templates/cjs/config/config.js +14 -9
- package/templates/cjs/models/UserModel.js +4 -4
- package/templates/cjs/public/build/editPersonal.js +7 -7
- package/templates/cjs/public/build/login.js +7 -7
- package/templates/cjs/public/build/users.js +26 -17
- package/templates/cjs/routes/api/users.js +28 -26
- package/templates/cjs/routes/login.js +2 -0
- package/templates/cjs/routes/users.js +2 -0
- package/templates/cjs/views/errors/404.hbs +44 -0
- package/templates/cjs/views/errors/500.hbs +44 -0
- package/templates/cjs/views/layout/default.hbs +2 -2
- package/templates/client/src/api/UserApi.js +1 -1
- package/templates/client/src/editPersonal.js +2 -2
- package/templates/client/src/login.js +2 -2
- package/templates/client/src/modals/UserModal.js +4 -4
- package/templates/client/src/shared/Api.js +4 -4
- package/templates/client/src/shared/reloadDataTableWithDelay.js +12 -0
- package/templates/client/src/users.js +4 -8
- package/templates/esm/config/config.js +14 -9
- package/templates/esm/models/UserModel.js +4 -4
- package/templates/esm/public/build/editPersonal.js +7 -7
- package/templates/esm/public/build/login.js +7 -7
- package/templates/esm/public/build/users.js +26 -17
- package/templates/esm/routes/api/users.js +28 -26
- package/templates/esm/routes/login.js +2 -0
- package/templates/esm/routes/users.js +2 -0
- package/templates/esm/views/errors/404.hbs +44 -0
- package/templates/esm/views/errors/500.hbs +44 -0
- package/templates/esm/views/layout/default.hbs +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
A comprehensive list of changes in each version may be found in the [CHANGELOG](CHANGELOG.md).
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
8
|
npm install -g express-sweet-generator
|
|
9
9
|
```
|
|
10
10
|
|
|
@@ -14,11 +14,11 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
|
|
|
14
14
|

|
|
15
15
|
|
|
16
16
|
1. For example, the following creates an Express app named `myapp`. The app will be created in a folder named `myapp` in the current working directory.
|
|
17
|
-
```
|
|
17
|
+
```bash
|
|
18
18
|
express-sweet -o esm myapp
|
|
19
19
|
```
|
|
20
20
|
1. Then install dependencies.
|
|
21
|
-
```
|
|
21
|
+
```bash
|
|
22
22
|
cd myapp/
|
|
23
23
|
npm install
|
|
24
24
|
```
|
|
@@ -116,16 +116,16 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
|
|
|
116
116
|
}
|
|
117
117
|
```
|
|
118
118
|
1. The DB to be accessed can be defined for each environment. Specify the environment in the `.env` file
|
|
119
|
-
```
|
|
119
|
+
```bash
|
|
120
120
|
NODE_ENV=development
|
|
121
121
|
```
|
|
122
122
|
1. Run the application with the following command.
|
|
123
|
-
```
|
|
123
|
+
```bash
|
|
124
124
|
npm start
|
|
125
125
|
```
|
|
126
126
|
1. Then, load `http://localhost:3000/` in your browser to access the app.
|
|
127
127
|
The generated app has the following directory structure:
|
|
128
|
-
```
|
|
128
|
+
```bash
|
|
129
129
|
.
|
|
130
130
|
├── .env
|
|
131
131
|
├── app.js
|
package/bin/express-sweet-cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
const ejs = require('ejs');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
4
|
const path = require('path');
|
|
@@ -112,9 +112,9 @@ function getAppName(installDir) {
|
|
|
112
112
|
* @param {Function} fn
|
|
113
113
|
*/
|
|
114
114
|
function existsInstallationDirectory(dir, fn) {
|
|
115
|
-
fs.readdir(dir, (
|
|
116
|
-
if (
|
|
117
|
-
throw
|
|
115
|
+
fs.readdir(dir, (error, files) => {
|
|
116
|
+
if (error && error.code !== 'ENOENT')
|
|
117
|
+
throw error;
|
|
118
118
|
fn(!files || !files.length);
|
|
119
119
|
});
|
|
120
120
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -65,17 +65,22 @@ module.exports = {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Hooks the default behavior on request errors.
|
|
68
|
-
* If unset, simply returns an error HTTP status. (<code>res.status(
|
|
69
|
-
* @type {(
|
|
68
|
+
* If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
|
|
69
|
+
* @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
|
|
70
70
|
* @example
|
|
71
|
-
* hook_handle_error: (
|
|
72
|
-
* if (
|
|
73
|
-
* // If the URL cannot be found, a 404 error screen (views/
|
|
74
|
-
* res.render('
|
|
71
|
+
* hook_handle_error: (error, req, res, next) => {
|
|
72
|
+
* if (error.status === 404)
|
|
73
|
+
* // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
|
|
74
|
+
* res.render('errors/404');
|
|
75
75
|
* else
|
|
76
|
-
* // For other errors, unknown error screen (views/error
|
|
77
|
-
* res.render('error
|
|
76
|
+
* // For other errors, unknown error screen (views/error/500.hbs) is displayed.
|
|
77
|
+
* res.render('error/500');
|
|
78
78
|
* },
|
|
79
79
|
*/
|
|
80
|
-
hook_handle_error:
|
|
80
|
+
hook_handle_error: (error, req, res, next) => {
|
|
81
|
+
if (error.status === 404)
|
|
82
|
+
res.status(404).render('errors/404', {isErrorPage: true});
|
|
83
|
+
else
|
|
84
|
+
res.status(500).render('errors/500', {isErrorPage: true});
|
|
85
|
+
},
|
|
81
86
|
}
|
|
@@ -105,10 +105,10 @@ module.exports = class extends expressExtension.database.Model {
|
|
|
105
105
|
}, {transaction});
|
|
106
106
|
await this.#updateUserIcon(user, set.icon, transaction);
|
|
107
107
|
await transaction.commit();
|
|
108
|
-
} catch (
|
|
108
|
+
} catch (error) {
|
|
109
109
|
if (transaction)
|
|
110
110
|
await transaction.rollback();
|
|
111
|
-
throw
|
|
111
|
+
throw error;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -133,10 +133,10 @@ module.exports = class extends expressExtension.database.Model {
|
|
|
133
133
|
await user.save({transaction});
|
|
134
134
|
await this.#updateUserIcon(user, set.icon, transaction);
|
|
135
135
|
await transaction.commit();
|
|
136
|
-
} catch (
|
|
136
|
+
} catch (error) {
|
|
137
137
|
if (transaction)
|
|
138
138
|
await transaction.rollback();
|
|
139
|
-
throw
|
|
139
|
+
throw error;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
|
|
|
124
124
|
/**
|
|
125
125
|
* Handles API errors.
|
|
126
126
|
* @param {number} code The HTTP status code.
|
|
127
|
-
* @param {Error}
|
|
127
|
+
* @param {Error} error The error object.
|
|
128
128
|
* @return {void}
|
|
129
129
|
*/
|
|
130
|
-
errorHook(code,
|
|
130
|
+
errorHook(code, error) {
|
|
131
131
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
132
|
-
if (
|
|
133
|
-
const {pathname} = new URL(
|
|
132
|
+
if (error && error.request && error.request.responseURL) {
|
|
133
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
134
134
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
135
135
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
136
136
|
location.replace('/');
|
|
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
|
|
|
141
141
|
;// CONCATENATED MODULE: ./src/api/UserApi.js
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
/* harmony default export */ const UserApi = (class extends
|
|
144
|
+
/* harmony default export */ const UserApi = (class extends Api {
|
|
145
145
|
constructor() {
|
|
146
146
|
super('/api/users');
|
|
147
147
|
}
|
|
@@ -238,10 +238,10 @@ function initForm() {
|
|
|
238
238
|
await build.components.Dialog.info('Email address has been changed. Please re-login.');
|
|
239
239
|
return void userApi.logout();
|
|
240
240
|
}
|
|
241
|
-
} catch (
|
|
241
|
+
} catch (error) {
|
|
242
242
|
validation.offIndicator();
|
|
243
243
|
build.components.Dialog.unknownError();
|
|
244
|
-
throw
|
|
244
|
+
throw error;
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
ref.personalForm
|
|
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
|
|
|
124
124
|
/**
|
|
125
125
|
* Handles API errors.
|
|
126
126
|
* @param {number} code The HTTP status code.
|
|
127
|
-
* @param {Error}
|
|
127
|
+
* @param {Error} error The error object.
|
|
128
128
|
* @return {void}
|
|
129
129
|
*/
|
|
130
|
-
errorHook(code,
|
|
130
|
+
errorHook(code, error) {
|
|
131
131
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
132
|
-
if (
|
|
133
|
-
const {pathname} = new URL(
|
|
132
|
+
if (error && error.request && error.request.responseURL) {
|
|
133
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
134
134
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
135
135
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
136
136
|
location.replace('/');
|
|
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
|
|
|
141
141
|
;// CONCATENATED MODULE: ./src/api/UserApi.js
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
/* harmony default export */ const UserApi = (class extends
|
|
144
|
+
/* harmony default export */ const UserApi = (class extends Api {
|
|
145
145
|
constructor() {
|
|
146
146
|
super('/api/users');
|
|
147
147
|
}
|
|
@@ -205,10 +205,10 @@ function initForm() {
|
|
|
205
205
|
if (!data)
|
|
206
206
|
return void validation.setError('email', 'userNotFound');
|
|
207
207
|
location.href = '/';
|
|
208
|
-
} catch (
|
|
208
|
+
} catch (error) {
|
|
209
209
|
validation.offIndicator();
|
|
210
210
|
build.components.Dialog.unknownError();
|
|
211
|
-
throw
|
|
211
|
+
throw error;
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
214
|
}
|
|
@@ -262,6 +262,19 @@ var dist_build = __webpack_require__(236);
|
|
|
262
262
|
}
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
+
;// CONCATENATED MODULE: ./src/shared/reloadDataTableWithDelay.js
|
|
266
|
+
/**
|
|
267
|
+
* Reloads a DataTable after a specified delay.
|
|
268
|
+
* @param {object} dataTable The DataTable instance to reload.
|
|
269
|
+
* @param {number} delay The delay in milliseconds before reloading.
|
|
270
|
+
*/
|
|
271
|
+
/* harmony default export */ const reloadDataTableWithDelay = ((dataTable, delay = 500) => {
|
|
272
|
+
let timer;
|
|
273
|
+
return function() { // Preserve the timer using a closure
|
|
274
|
+
clearTimeout(timer);
|
|
275
|
+
timer = setTimeout(() => dataTable.reload(), delay);
|
|
276
|
+
};
|
|
277
|
+
});
|
|
265
278
|
;// CONCATENATED MODULE: ./src/shared/Api.js
|
|
266
279
|
|
|
267
280
|
|
|
@@ -300,13 +313,13 @@ var dist_build = __webpack_require__(236);
|
|
|
300
313
|
/**
|
|
301
314
|
* Handles API errors.
|
|
302
315
|
* @param {number} code The HTTP status code.
|
|
303
|
-
* @param {Error}
|
|
316
|
+
* @param {Error} error The error object.
|
|
304
317
|
* @return {void}
|
|
305
318
|
*/
|
|
306
|
-
errorHook(code,
|
|
319
|
+
errorHook(code, error) {
|
|
307
320
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
308
|
-
if (
|
|
309
|
-
const {pathname} = new URL(
|
|
321
|
+
if (error && error.request && error.request.responseURL) {
|
|
322
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
310
323
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
311
324
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
312
325
|
location.replace('/');
|
|
@@ -317,7 +330,7 @@ var dist_build = __webpack_require__(236);
|
|
|
317
330
|
;// CONCATENATED MODULE: ./src/api/UserApi.js
|
|
318
331
|
|
|
319
332
|
|
|
320
|
-
/* harmony default export */ const UserApi = (class extends
|
|
333
|
+
/* harmony default export */ const UserApi = (class extends Api {
|
|
321
334
|
constructor() {
|
|
322
335
|
super('/api/users');
|
|
323
336
|
}
|
|
@@ -603,10 +616,10 @@ var dist_build = __webpack_require__(236);
|
|
|
603
616
|
this.#validator.offIndicator();
|
|
604
617
|
dist_build.components.Toast.success('User created.');
|
|
605
618
|
super.hide(true);
|
|
606
|
-
} catch (
|
|
619
|
+
} catch (error) {
|
|
607
620
|
this.#validator.offIndicator();
|
|
608
621
|
dist_build.components.Dialog.unknownError();
|
|
609
|
-
throw
|
|
622
|
+
throw error;
|
|
610
623
|
}
|
|
611
624
|
});
|
|
612
625
|
}
|
|
@@ -628,10 +641,10 @@ var dist_build = __webpack_require__(236);
|
|
|
628
641
|
}
|
|
629
642
|
dist_build.components.Toast.success('User updated.');
|
|
630
643
|
super.hide(true);
|
|
631
|
-
} catch (
|
|
644
|
+
} catch (error) {
|
|
632
645
|
this.#validator.offIndicator();
|
|
633
646
|
dist_build.components.Dialog.unknownError();
|
|
634
|
-
throw
|
|
647
|
+
throw error;
|
|
635
648
|
}
|
|
636
649
|
});
|
|
637
650
|
}
|
|
@@ -718,6 +731,7 @@ var dist_build = __webpack_require__(236);
|
|
|
718
731
|
|
|
719
732
|
|
|
720
733
|
|
|
734
|
+
|
|
721
735
|
function initTable() {
|
|
722
736
|
userTable = new Datatable(ref.userTable, {
|
|
723
737
|
ajax: {
|
|
@@ -800,23 +814,18 @@ function initForm() {
|
|
|
800
814
|
throw Error('Unknown error');
|
|
801
815
|
dist_build.components.Toast.success(`${name} was deleted.`);
|
|
802
816
|
userTable.reload();
|
|
803
|
-
} catch (
|
|
817
|
+
} catch (error) {
|
|
804
818
|
dist_build.components.Dialog.unknownError();
|
|
805
|
-
throw
|
|
819
|
+
throw error;
|
|
806
820
|
}
|
|
807
821
|
})
|
|
808
|
-
.on('input', '[data-on-search-change]' ,
|
|
809
|
-
if (searchTimer)
|
|
810
|
-
clearTimeout(searchTimer);
|
|
811
|
-
searchTimer = setTimeout(() => userTable.reload(), 300);
|
|
812
|
-
});
|
|
822
|
+
.on('input', '[data-on-search-change]' , reloadDataTableWithDelay(userTable));
|
|
813
823
|
}
|
|
814
824
|
|
|
815
825
|
const userApi = new UserApi();
|
|
816
826
|
const userModal = new UserModal();
|
|
817
827
|
const ref = dist_build.components.selectRef('#kt_app_content_container');
|
|
818
828
|
let userTable;
|
|
819
|
-
let searchTimer;
|
|
820
829
|
initTable();
|
|
821
830
|
initForm();
|
|
822
831
|
})();
|
|
@@ -6,13 +6,14 @@ const UserNotFound = require('../../exceptions/UserNotFound');
|
|
|
6
6
|
const CustomValidation = require('../../shared/CustomValidation');
|
|
7
7
|
|
|
8
8
|
const router = express.Router();
|
|
9
|
+
|
|
9
10
|
router.post('/login', [
|
|
10
11
|
body('email').trim().not().isEmpty().isEmail(),
|
|
11
12
|
body('password').trim().not().isEmpty()
|
|
12
13
|
], async (req, res, next) => {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
return void res.status(400).json({errors:
|
|
14
|
+
const result = validationResult(req);
|
|
15
|
+
if (!result.isEmpty())
|
|
16
|
+
return void res.status(400).json({errors: result.array()});
|
|
16
17
|
const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
|
|
17
18
|
res.json(isAuthenticated);
|
|
18
19
|
});
|
|
@@ -30,9 +31,9 @@ router.get('/', [
|
|
|
30
31
|
query('dir').optional({nullable: true, checkFalsy: true}).isIn(['asc', 'desc']),
|
|
31
32
|
query('search').trim().optional({nullable: true, checkFalsy: true}).trim()
|
|
32
33
|
], async (req, res) => {
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
return void res.status(400).json({errors:
|
|
34
|
+
const result = validationResult(req);
|
|
35
|
+
if (!result.isEmpty())
|
|
36
|
+
return void res.status(400).json({errors: result.array()});
|
|
36
37
|
const data = await UserModel.paginate(req.query);
|
|
37
38
|
data.draw = req.query.draw;
|
|
38
39
|
res.json(data);
|
|
@@ -42,9 +43,9 @@ router.get('/email-exists', [
|
|
|
42
43
|
query('user.email').trim().not().isEmpty(),
|
|
43
44
|
query('excludeUserId').optional({nullable: true, checkFalsy: true}).isInt({min: 1})
|
|
44
45
|
], async (req, res) => {
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
47
|
-
return void res.status(400).json({errors:
|
|
46
|
+
const result = validationResult(req);
|
|
47
|
+
if (!result.isEmpty())
|
|
48
|
+
return void res.status(400).json({errors: result.array()});
|
|
48
49
|
const emailExists = await UserModel.emailExists(req.query.user.email, req.query.excludeUserId || null);
|
|
49
50
|
res.json({valid: !emailExists});
|
|
50
51
|
});
|
|
@@ -55,9 +56,9 @@ router.post('/', [
|
|
|
55
56
|
body('user.password').trim().not().isEmpty().isLength({max: 128}),
|
|
56
57
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
57
58
|
], async (req, res) => {
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
60
|
-
return void res.status(400).json({errors:
|
|
59
|
+
const result = validationResult(req);
|
|
60
|
+
if (!result.isEmpty())
|
|
61
|
+
return void res.status(400).json({errors: result.array()});
|
|
61
62
|
await UserModel.createUser(req.body.user);
|
|
62
63
|
res.json(true);
|
|
63
64
|
});
|
|
@@ -74,16 +75,16 @@ router.put('/:userId(\\d+)', [
|
|
|
74
75
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
75
76
|
], async (req, res, next) => {
|
|
76
77
|
try {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
return void res.status(400).json({errors:
|
|
78
|
+
const result = validationResult(req);
|
|
79
|
+
if (!result.isEmpty())
|
|
80
|
+
return void res.status(400).json({errors: result.array()});
|
|
80
81
|
await UserModel.updateUser(req.params.userId, req.body.user);
|
|
81
82
|
res.json(true);
|
|
82
|
-
} catch (
|
|
83
|
-
if (
|
|
84
|
-
res.json({error:
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof UserNotFound)
|
|
85
|
+
res.json({error: error.name});
|
|
85
86
|
else
|
|
86
|
-
next(
|
|
87
|
+
next(error);
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
|
|
@@ -99,16 +100,17 @@ router.put('/profile', [
|
|
|
99
100
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
100
101
|
], async (req, res, next) => {
|
|
101
102
|
try {
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
return void res.status(400).json({errors:
|
|
103
|
+
const result = validationResult(req);
|
|
104
|
+
if (!result.isEmpty())
|
|
105
|
+
return void res.status(400).json({errors: result.array()});
|
|
105
106
|
await UserModel.updateUser(req.user.id, req.body.user);
|
|
106
107
|
res.json(true);
|
|
107
|
-
} catch (
|
|
108
|
-
if (
|
|
109
|
-
res.json({error:
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof UserNotFound)
|
|
110
|
+
res.json({error: error.name});
|
|
110
111
|
else
|
|
111
|
-
next(
|
|
112
|
+
next(error);
|
|
112
113
|
}
|
|
113
114
|
});
|
|
115
|
+
|
|
114
116
|
module.exports = router;
|
|
@@ -2,6 +2,7 @@ const express = require('express');
|
|
|
2
2
|
const UserModel = require('../models/UserModel');
|
|
3
3
|
|
|
4
4
|
const router = express.Router();
|
|
5
|
+
|
|
5
6
|
router.get('/', (req, res) => {
|
|
6
7
|
res.render('users');
|
|
7
8
|
});
|
|
@@ -15,4 +16,5 @@ router.get('/edit-personal', async (req, res) => {
|
|
|
15
16
|
const user = await UserModel.getUser(req.user.id);
|
|
16
17
|
res.render('edit-personal', {user: user.toJSON()});
|
|
17
18
|
});
|
|
19
|
+
|
|
18
20
|
module.exports = router;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}404 Error: Page Not Found{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}
|
|
4
|
+
<style>
|
|
5
|
+
body {
|
|
6
|
+
background-image: url('/build/theme/media/auth/bg6.jpg');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
[data-bs-theme="dark"] body {
|
|
10
|
+
background-image: url('/build/theme/media/auth/bg6-dark.jpg');
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
{{/contentFor}}
|
|
14
|
+
<!--begin::Authentication - Signup Welcome Message -->
|
|
15
|
+
<div class="d-flex flex-column flex-center flex-column-fluid">
|
|
16
|
+
<!--begin::Content-->
|
|
17
|
+
<div class="d-flex flex-column flex-center text-center p-10">
|
|
18
|
+
<!--begin::Wrapper-->
|
|
19
|
+
<div class="card card-flush w-lg-650px py-5">
|
|
20
|
+
<div class="card-body py-15 py-lg-20">
|
|
21
|
+
<!--begin::Title-->
|
|
22
|
+
<h1 class="fw-bolder fs-2hx mb-4">404 Error: Page Not Found</h1>
|
|
23
|
+
<!--end::Title-->
|
|
24
|
+
<!--begin::Text-->
|
|
25
|
+
<div class="fw-semibold fs-6 mb-7">The page you requested could not be found. Please check the URL and try again. If the problem persists, please contact us.</div>
|
|
26
|
+
<!--end::Text-->
|
|
27
|
+
<!--begin::Illustration-->
|
|
28
|
+
<div class="mb-3">
|
|
29
|
+
<img src="/build/theme/media/auth/404-error.png" class="mw-100 mh-300px theme-light-show" alt="" />
|
|
30
|
+
<img src="/build/theme/media/auth/404-error-dark.png" class="mw-100 mh-300px theme-dark-show" alt="" />
|
|
31
|
+
</div>
|
|
32
|
+
<!--end::Illustration-->
|
|
33
|
+
<!--begin::Link-->
|
|
34
|
+
<div class="mb-0">
|
|
35
|
+
<a href="/" class="btn btn-sm btn-primary">Back to Home</a>
|
|
36
|
+
</div>
|
|
37
|
+
<!--end::Link-->
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
<!--end::Wrapper-->
|
|
41
|
+
</div>
|
|
42
|
+
<!--end::Content-->
|
|
43
|
+
</div>
|
|
44
|
+
<!--end::Authentication - Signup Welcome Message-->
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}500 Error: Server Error{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}
|
|
4
|
+
<style>
|
|
5
|
+
body {
|
|
6
|
+
background-image: url('/build/theme/media/auth/bg6.jpg');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
[data-bs-theme="dark"] body {
|
|
10
|
+
background-image: url('/build/theme/media/auth/bg6-dark.jpg');
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
{{/contentFor}}
|
|
14
|
+
<!--begin::Authentication - Signup Welcome Message -->
|
|
15
|
+
<div class="d-flex flex-column flex-center flex-column-fluid">
|
|
16
|
+
<!--begin::Content-->
|
|
17
|
+
<div class="d-flex flex-column flex-center text-center p-10">
|
|
18
|
+
<!--begin::Wrapper-->
|
|
19
|
+
<div class="card card-flush w-lg-650px py-5">
|
|
20
|
+
<div class="card-body py-15 py-lg-20">
|
|
21
|
+
<!--begin::Title-->
|
|
22
|
+
<h1 class="fw-bolder fs-2hx mb-4">500 Error: Server Error</h1>
|
|
23
|
+
<!--end::Title-->
|
|
24
|
+
<!--begin::Text-->
|
|
25
|
+
<div class="fw-semibold fs-6 mb-7">We're sorry, a server error has occurred. Please try again later. If the problem persists, please contact us.</div>
|
|
26
|
+
<!--end::Text-->
|
|
27
|
+
<!--begin::Illustration-->
|
|
28
|
+
<div class="mb-3">
|
|
29
|
+
<img src="/build/theme/media/auth/500-error.png" class="mw-100 mh-300px theme-light-show" alt="" />
|
|
30
|
+
<img src="/build/theme/media/auth/500-error-dark.png" class="mw-100 mh-300px theme-dark-show" alt="" />
|
|
31
|
+
</div>
|
|
32
|
+
<!--end::Illustration-->
|
|
33
|
+
<!--begin::Link-->
|
|
34
|
+
<div class="mb-0">
|
|
35
|
+
<a href="/" class="btn btn-sm btn-primary">Back to Home</a>
|
|
36
|
+
</div>
|
|
37
|
+
<!--end::Link-->
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
<!--end::Wrapper-->
|
|
41
|
+
</div>
|
|
42
|
+
<!--end::Content-->
|
|
43
|
+
</div>
|
|
44
|
+
<!--end::Authentication - Signup Welcome Message-->
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<!--begin::Body-->
|
|
24
24
|
<body
|
|
25
25
|
id="kt_app_body"
|
|
26
|
-
{{#if session}}
|
|
26
|
+
{{#if (and (notEmpty session) (neq isErrorPage true))}}
|
|
27
27
|
data-kt-app-layout="light-sidebar"
|
|
28
28
|
data-kt-app-header-fixed="true"
|
|
29
29
|
data-kt-app-sidebar-enabled="true"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
</script>
|
|
57
57
|
<!--end::Theme mode setup on page load-->
|
|
58
|
-
{{#if session}}
|
|
58
|
+
{{#if (and (notEmpty session) (neq isErrorPage true))}}
|
|
59
59
|
<!--begin::App-->
|
|
60
60
|
<div class="d-flex flex-column flex-root app-root" id="kt_app_root">
|
|
61
61
|
<!--begin::Page-->
|
|
@@ -61,10 +61,10 @@ function initForm() {
|
|
|
61
61
|
await components.Dialog.info('Email address has been changed. Please re-login.');
|
|
62
62
|
return void userApi.logout();
|
|
63
63
|
}
|
|
64
|
-
} catch (
|
|
64
|
+
} catch (error) {
|
|
65
65
|
validation.offIndicator();
|
|
66
66
|
components.Dialog.unknownError();
|
|
67
|
-
throw
|
|
67
|
+
throw error;
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
ref.personalForm
|
|
@@ -28,10 +28,10 @@ function initForm() {
|
|
|
28
28
|
if (!data)
|
|
29
29
|
return void validation.setError('email', 'userNotFound');
|
|
30
30
|
location.href = '/';
|
|
31
|
-
} catch (
|
|
31
|
+
} catch (error) {
|
|
32
32
|
validation.offIndicator();
|
|
33
33
|
components.Dialog.unknownError();
|
|
34
|
-
throw
|
|
34
|
+
throw error;
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -250,10 +250,10 @@ export default class extends components.Modal {
|
|
|
250
250
|
this.#validator.offIndicator();
|
|
251
251
|
components.Toast.success('User created.');
|
|
252
252
|
super.hide(true);
|
|
253
|
-
} catch (
|
|
253
|
+
} catch (error) {
|
|
254
254
|
this.#validator.offIndicator();
|
|
255
255
|
components.Dialog.unknownError();
|
|
256
|
-
throw
|
|
256
|
+
throw error;
|
|
257
257
|
}
|
|
258
258
|
});
|
|
259
259
|
}
|
|
@@ -275,10 +275,10 @@ export default class extends components.Modal {
|
|
|
275
275
|
}
|
|
276
276
|
components.Toast.success('User updated.');
|
|
277
277
|
super.hide(true);
|
|
278
|
-
} catch (
|
|
278
|
+
} catch (error) {
|
|
279
279
|
this.#validator.offIndicator();
|
|
280
280
|
components.Dialog.unknownError();
|
|
281
|
-
throw
|
|
281
|
+
throw error;
|
|
282
282
|
}
|
|
283
283
|
});
|
|
284
284
|
}
|
|
@@ -35,13 +35,13 @@ export default class extends components.Api {
|
|
|
35
35
|
/**
|
|
36
36
|
* Handles API errors.
|
|
37
37
|
* @param {number} code The HTTP status code.
|
|
38
|
-
* @param {Error}
|
|
38
|
+
* @param {Error} error The error object.
|
|
39
39
|
* @return {void}
|
|
40
40
|
*/
|
|
41
|
-
errorHook(code,
|
|
41
|
+
errorHook(code, error) {
|
|
42
42
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
43
|
-
if (
|
|
44
|
-
const {pathname} = new URL(
|
|
43
|
+
if (error && error.request && error.request.responseURL) {
|
|
44
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
45
45
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
46
46
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
47
47
|
location.replace('/');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reloads a DataTable after a specified delay.
|
|
3
|
+
* @param {object} dataTable The DataTable instance to reload.
|
|
4
|
+
* @param {number} delay The delay in milliseconds before reloading.
|
|
5
|
+
*/
|
|
6
|
+
export default (dataTable, delay = 500) => {
|
|
7
|
+
let timer;
|
|
8
|
+
return function() { // Preserve the timer using a closure
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
timer = setTimeout(() => dataTable.reload(), delay);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -2,6 +2,7 @@ import '~/users.css';
|
|
|
2
2
|
import hbs from 'handlebars-extd';
|
|
3
3
|
import {components} from 'metronic-extension';
|
|
4
4
|
import Datatable from '~/shared/Datatable';
|
|
5
|
+
import reloadDataTableWithDelay from '~/shared/reloadDataTableWithDelay';
|
|
5
6
|
import UserApi from '~/api/UserApi';
|
|
6
7
|
import UserModal from '~/modals/UserModal';
|
|
7
8
|
|
|
@@ -87,22 +88,17 @@ function initForm() {
|
|
|
87
88
|
throw Error('Unknown error');
|
|
88
89
|
components.Toast.success(`${name} was deleted.`);
|
|
89
90
|
userTable.reload();
|
|
90
|
-
} catch (
|
|
91
|
+
} catch (error) {
|
|
91
92
|
components.Dialog.unknownError();
|
|
92
|
-
throw
|
|
93
|
+
throw error;
|
|
93
94
|
}
|
|
94
95
|
})
|
|
95
|
-
.on('input', '[data-on-search-change]' ,
|
|
96
|
-
if (searchTimer)
|
|
97
|
-
clearTimeout(searchTimer);
|
|
98
|
-
searchTimer = setTimeout(() => userTable.reload(), 300);
|
|
99
|
-
});
|
|
96
|
+
.on('input', '[data-on-search-change]' , reloadDataTableWithDelay(userTable));
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
const userApi = new UserApi();
|
|
103
100
|
const userModal = new UserModal();
|
|
104
101
|
const ref = components.selectRef('#kt_app_content_container');
|
|
105
102
|
let userTable;
|
|
106
|
-
let searchTimer;
|
|
107
103
|
initTable();
|
|
108
104
|
initForm();
|
|
@@ -65,17 +65,22 @@ export default {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Hooks the default behavior on request errors.
|
|
68
|
-
* If unset, simply returns an error HTTP status. (<code>res.status(
|
|
69
|
-
* @type {(
|
|
68
|
+
* If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
|
|
69
|
+
* @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
|
|
70
70
|
* @example
|
|
71
|
-
* hook_handle_error: (
|
|
72
|
-
* if (
|
|
73
|
-
* // If the URL cannot be found, a 404 error screen (views/
|
|
74
|
-
* res.render('
|
|
71
|
+
* hook_handle_error: (error, req, res, next) => {
|
|
72
|
+
* if (error.status === 404)
|
|
73
|
+
* // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
|
|
74
|
+
* res.render('errors/404');
|
|
75
75
|
* else
|
|
76
|
-
* // For other errors, unknown error screen (views/error
|
|
77
|
-
* res.render('error
|
|
76
|
+
* // For other errors, unknown error screen (views/error/500.hbs) is displayed.
|
|
77
|
+
* res.render('error/500');
|
|
78
78
|
* },
|
|
79
79
|
*/
|
|
80
|
-
hook_handle_error:
|
|
80
|
+
hook_handle_error: (error, req, res, next) => {
|
|
81
|
+
if (error.status === 404)
|
|
82
|
+
res.status(404).render('errors/404', {isErrorPage: true});
|
|
83
|
+
else
|
|
84
|
+
res.status(500).render('errors/500', {isErrorPage: true});
|
|
85
|
+
},
|
|
81
86
|
}
|
|
@@ -105,10 +105,10 @@ export default class extends expressExtension.database.Model {
|
|
|
105
105
|
}, {transaction});
|
|
106
106
|
await this.#updateUserIcon(user, set.icon, transaction);
|
|
107
107
|
await transaction.commit();
|
|
108
|
-
} catch (
|
|
108
|
+
} catch (error) {
|
|
109
109
|
if (transaction)
|
|
110
110
|
await transaction.rollback();
|
|
111
|
-
throw
|
|
111
|
+
throw error;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -133,10 +133,10 @@ export default class extends expressExtension.database.Model {
|
|
|
133
133
|
await user.save({transaction});
|
|
134
134
|
await this.#updateUserIcon(user, set.icon, transaction);
|
|
135
135
|
await transaction.commit();
|
|
136
|
-
} catch (
|
|
136
|
+
} catch (error) {
|
|
137
137
|
if (transaction)
|
|
138
138
|
await transaction.rollback();
|
|
139
|
-
throw
|
|
139
|
+
throw error;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
|
|
|
124
124
|
/**
|
|
125
125
|
* Handles API errors.
|
|
126
126
|
* @param {number} code The HTTP status code.
|
|
127
|
-
* @param {Error}
|
|
127
|
+
* @param {Error} error The error object.
|
|
128
128
|
* @return {void}
|
|
129
129
|
*/
|
|
130
|
-
errorHook(code,
|
|
130
|
+
errorHook(code, error) {
|
|
131
131
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
132
|
-
if (
|
|
133
|
-
const {pathname} = new URL(
|
|
132
|
+
if (error && error.request && error.request.responseURL) {
|
|
133
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
134
134
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
135
135
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
136
136
|
location.replace('/');
|
|
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
|
|
|
141
141
|
;// CONCATENATED MODULE: ./src/api/UserApi.js
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
/* harmony default export */ const UserApi = (class extends
|
|
144
|
+
/* harmony default export */ const UserApi = (class extends Api {
|
|
145
145
|
constructor() {
|
|
146
146
|
super('/api/users');
|
|
147
147
|
}
|
|
@@ -238,10 +238,10 @@ function initForm() {
|
|
|
238
238
|
await build.components.Dialog.info('Email address has been changed. Please re-login.');
|
|
239
239
|
return void userApi.logout();
|
|
240
240
|
}
|
|
241
|
-
} catch (
|
|
241
|
+
} catch (error) {
|
|
242
242
|
validation.offIndicator();
|
|
243
243
|
build.components.Dialog.unknownError();
|
|
244
|
-
throw
|
|
244
|
+
throw error;
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
ref.personalForm
|
|
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
|
|
|
124
124
|
/**
|
|
125
125
|
* Handles API errors.
|
|
126
126
|
* @param {number} code The HTTP status code.
|
|
127
|
-
* @param {Error}
|
|
127
|
+
* @param {Error} error The error object.
|
|
128
128
|
* @return {void}
|
|
129
129
|
*/
|
|
130
|
-
errorHook(code,
|
|
130
|
+
errorHook(code, error) {
|
|
131
131
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
132
|
-
if (
|
|
133
|
-
const {pathname} = new URL(
|
|
132
|
+
if (error && error.request && error.request.responseURL) {
|
|
133
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
134
134
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
135
135
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
136
136
|
location.replace('/');
|
|
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
|
|
|
141
141
|
;// CONCATENATED MODULE: ./src/api/UserApi.js
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
/* harmony default export */ const UserApi = (class extends
|
|
144
|
+
/* harmony default export */ const UserApi = (class extends Api {
|
|
145
145
|
constructor() {
|
|
146
146
|
super('/api/users');
|
|
147
147
|
}
|
|
@@ -205,10 +205,10 @@ function initForm() {
|
|
|
205
205
|
if (!data)
|
|
206
206
|
return void validation.setError('email', 'userNotFound');
|
|
207
207
|
location.href = '/';
|
|
208
|
-
} catch (
|
|
208
|
+
} catch (error) {
|
|
209
209
|
validation.offIndicator();
|
|
210
210
|
build.components.Dialog.unknownError();
|
|
211
|
-
throw
|
|
211
|
+
throw error;
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
214
|
}
|
|
@@ -262,6 +262,19 @@ var dist_build = __webpack_require__(236);
|
|
|
262
262
|
}
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
+
;// CONCATENATED MODULE: ./src/shared/reloadDataTableWithDelay.js
|
|
266
|
+
/**
|
|
267
|
+
* Reloads a DataTable after a specified delay.
|
|
268
|
+
* @param {object} dataTable The DataTable instance to reload.
|
|
269
|
+
* @param {number} delay The delay in milliseconds before reloading.
|
|
270
|
+
*/
|
|
271
|
+
/* harmony default export */ const reloadDataTableWithDelay = ((dataTable, delay = 500) => {
|
|
272
|
+
let timer;
|
|
273
|
+
return function() { // Preserve the timer using a closure
|
|
274
|
+
clearTimeout(timer);
|
|
275
|
+
timer = setTimeout(() => dataTable.reload(), delay);
|
|
276
|
+
};
|
|
277
|
+
});
|
|
265
278
|
;// CONCATENATED MODULE: ./src/shared/Api.js
|
|
266
279
|
|
|
267
280
|
|
|
@@ -300,13 +313,13 @@ var dist_build = __webpack_require__(236);
|
|
|
300
313
|
/**
|
|
301
314
|
* Handles API errors.
|
|
302
315
|
* @param {number} code The HTTP status code.
|
|
303
|
-
* @param {Error}
|
|
316
|
+
* @param {Error} error The error object.
|
|
304
317
|
* @return {void}
|
|
305
318
|
*/
|
|
306
|
-
errorHook(code,
|
|
319
|
+
errorHook(code, error) {
|
|
307
320
|
// Check if the error object and request properties exist to avoid runtime errors
|
|
308
|
-
if (
|
|
309
|
-
const {pathname} = new URL(
|
|
321
|
+
if (error && error.request && error.request.responseURL) {
|
|
322
|
+
const {pathname} = new URL(error.request.responseURL);
|
|
310
323
|
if (pathname !== '/api/users/login' && code === 401) {
|
|
311
324
|
// Redirect to the login page if an authentication error occurs on a non-login request.
|
|
312
325
|
location.replace('/');
|
|
@@ -317,7 +330,7 @@ var dist_build = __webpack_require__(236);
|
|
|
317
330
|
;// CONCATENATED MODULE: ./src/api/UserApi.js
|
|
318
331
|
|
|
319
332
|
|
|
320
|
-
/* harmony default export */ const UserApi = (class extends
|
|
333
|
+
/* harmony default export */ const UserApi = (class extends Api {
|
|
321
334
|
constructor() {
|
|
322
335
|
super('/api/users');
|
|
323
336
|
}
|
|
@@ -603,10 +616,10 @@ var dist_build = __webpack_require__(236);
|
|
|
603
616
|
this.#validator.offIndicator();
|
|
604
617
|
dist_build.components.Toast.success('User created.');
|
|
605
618
|
super.hide(true);
|
|
606
|
-
} catch (
|
|
619
|
+
} catch (error) {
|
|
607
620
|
this.#validator.offIndicator();
|
|
608
621
|
dist_build.components.Dialog.unknownError();
|
|
609
|
-
throw
|
|
622
|
+
throw error;
|
|
610
623
|
}
|
|
611
624
|
});
|
|
612
625
|
}
|
|
@@ -628,10 +641,10 @@ var dist_build = __webpack_require__(236);
|
|
|
628
641
|
}
|
|
629
642
|
dist_build.components.Toast.success('User updated.');
|
|
630
643
|
super.hide(true);
|
|
631
|
-
} catch (
|
|
644
|
+
} catch (error) {
|
|
632
645
|
this.#validator.offIndicator();
|
|
633
646
|
dist_build.components.Dialog.unknownError();
|
|
634
|
-
throw
|
|
647
|
+
throw error;
|
|
635
648
|
}
|
|
636
649
|
});
|
|
637
650
|
}
|
|
@@ -718,6 +731,7 @@ var dist_build = __webpack_require__(236);
|
|
|
718
731
|
|
|
719
732
|
|
|
720
733
|
|
|
734
|
+
|
|
721
735
|
function initTable() {
|
|
722
736
|
userTable = new Datatable(ref.userTable, {
|
|
723
737
|
ajax: {
|
|
@@ -800,23 +814,18 @@ function initForm() {
|
|
|
800
814
|
throw Error('Unknown error');
|
|
801
815
|
dist_build.components.Toast.success(`${name} was deleted.`);
|
|
802
816
|
userTable.reload();
|
|
803
|
-
} catch (
|
|
817
|
+
} catch (error) {
|
|
804
818
|
dist_build.components.Dialog.unknownError();
|
|
805
|
-
throw
|
|
819
|
+
throw error;
|
|
806
820
|
}
|
|
807
821
|
})
|
|
808
|
-
.on('input', '[data-on-search-change]' ,
|
|
809
|
-
if (searchTimer)
|
|
810
|
-
clearTimeout(searchTimer);
|
|
811
|
-
searchTimer = setTimeout(() => userTable.reload(), 300);
|
|
812
|
-
});
|
|
822
|
+
.on('input', '[data-on-search-change]' , reloadDataTableWithDelay(userTable));
|
|
813
823
|
}
|
|
814
824
|
|
|
815
825
|
const userApi = new UserApi();
|
|
816
826
|
const userModal = new UserModal();
|
|
817
827
|
const ref = dist_build.components.selectRef('#kt_app_content_container');
|
|
818
828
|
let userTable;
|
|
819
|
-
let searchTimer;
|
|
820
829
|
initTable();
|
|
821
830
|
initForm();
|
|
822
831
|
})();
|
|
@@ -6,13 +6,14 @@ import UserNotFound from '../../exceptions/UserNotFound.js';
|
|
|
6
6
|
import * as CustomValidation from '../../shared/CustomValidation.js';
|
|
7
7
|
|
|
8
8
|
const router = Router();
|
|
9
|
+
|
|
9
10
|
router.post('/login', [
|
|
10
11
|
body('email').trim().not().isEmpty().isEmail(),
|
|
11
12
|
body('password').trim().not().isEmpty()
|
|
12
13
|
], async (req, res, next) => {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
return void res.status(400).json({errors:
|
|
14
|
+
const result = validationResult(req);
|
|
15
|
+
if (!result.isEmpty())
|
|
16
|
+
return void res.status(400).json({errors: result.array()});
|
|
16
17
|
const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
|
|
17
18
|
res.json(isAuthenticated);
|
|
18
19
|
});
|
|
@@ -30,9 +31,9 @@ router.get('/', [
|
|
|
30
31
|
query('dir').optional({nullable: true, checkFalsy: true}).isIn(['asc', 'desc']),
|
|
31
32
|
query('search').trim().optional({nullable: true, checkFalsy: true}).trim()
|
|
32
33
|
], async (req, res) => {
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
return void res.status(400).json({errors:
|
|
34
|
+
const result = validationResult(req);
|
|
35
|
+
if (!result.isEmpty())
|
|
36
|
+
return void res.status(400).json({errors: result.array()});
|
|
36
37
|
const data = await UserModel.paginate(req.query);
|
|
37
38
|
data.draw = req.query.draw;
|
|
38
39
|
res.json(data);
|
|
@@ -42,9 +43,9 @@ router.get('/email-exists', [
|
|
|
42
43
|
query('user.email').trim().not().isEmpty(),
|
|
43
44
|
query('excludeUserId').optional({nullable: true, checkFalsy: true}).isInt({min: 1})
|
|
44
45
|
], async (req, res) => {
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
47
|
-
return void res.status(400).json({errors:
|
|
46
|
+
const result = validationResult(req);
|
|
47
|
+
if (!result.isEmpty())
|
|
48
|
+
return void res.status(400).json({errors: result.array()});
|
|
48
49
|
const emailExists = await UserModel.emailExists(req.query.user.email, req.query.excludeUserId || null);
|
|
49
50
|
res.json({valid: !emailExists});
|
|
50
51
|
});
|
|
@@ -55,9 +56,9 @@ router.post('/', [
|
|
|
55
56
|
body('user.password').trim().not().isEmpty().isLength({max: 128}),
|
|
56
57
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
57
58
|
], async (req, res) => {
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
60
|
-
return void res.status(400).json({errors:
|
|
59
|
+
const result = validationResult(req);
|
|
60
|
+
if (!result.isEmpty())
|
|
61
|
+
return void res.status(400).json({errors: result.array()});
|
|
61
62
|
await UserModel.createUser(req.body.user);
|
|
62
63
|
res.json(true);
|
|
63
64
|
});
|
|
@@ -74,16 +75,16 @@ router.put('/:userId(\\d+)', [
|
|
|
74
75
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
75
76
|
], async (req, res, next) => {
|
|
76
77
|
try {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
return void res.status(400).json({errors:
|
|
78
|
+
const result = validationResult(req);
|
|
79
|
+
if (!result.isEmpty())
|
|
80
|
+
return void res.status(400).json({errors: result.array()});
|
|
80
81
|
await UserModel.updateUser(req.params.userId, req.body.user);
|
|
81
82
|
res.json(true);
|
|
82
|
-
} catch (
|
|
83
|
-
if (
|
|
84
|
-
res.json({error:
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof UserNotFound)
|
|
85
|
+
res.json({error: error.name});
|
|
85
86
|
else
|
|
86
|
-
next(
|
|
87
|
+
next(error);
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
|
|
@@ -99,16 +100,17 @@ router.put('/profile', [
|
|
|
99
100
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
100
101
|
], async (req, res, next) => {
|
|
101
102
|
try {
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
return void res.status(400).json({errors:
|
|
103
|
+
const result = validationResult(req);
|
|
104
|
+
if (!result.isEmpty())
|
|
105
|
+
return void res.status(400).json({errors: result.array()});
|
|
105
106
|
await UserModel.updateUser(req.user.id, req.body.user);
|
|
106
107
|
res.json(true);
|
|
107
|
-
} catch (
|
|
108
|
-
if (
|
|
109
|
-
res.json({error:
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof UserNotFound)
|
|
110
|
+
res.json({error: error.name});
|
|
110
111
|
else
|
|
111
|
-
next(
|
|
112
|
+
next(error);
|
|
112
113
|
}
|
|
113
114
|
});
|
|
115
|
+
|
|
114
116
|
export default router;
|
|
@@ -2,6 +2,7 @@ import {Router} from 'express';
|
|
|
2
2
|
import UserModel from '../models/UserModel.js';
|
|
3
3
|
|
|
4
4
|
const router = Router();
|
|
5
|
+
|
|
5
6
|
router.get('/', (req, res) => {
|
|
6
7
|
res.render('users');
|
|
7
8
|
});
|
|
@@ -15,4 +16,5 @@ router.get('/edit-personal', async (req, res) => {
|
|
|
15
16
|
const user = await UserModel.getUser(req.user.id);
|
|
16
17
|
res.render('edit-personal', {user: user.toJSON()});
|
|
17
18
|
});
|
|
19
|
+
|
|
18
20
|
export default router;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}404 Error: Page Not Found{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}
|
|
4
|
+
<style>
|
|
5
|
+
body {
|
|
6
|
+
background-image: url('/build/theme/media/auth/bg6.jpg');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
[data-bs-theme="dark"] body {
|
|
10
|
+
background-image: url('/build/theme/media/auth/bg6-dark.jpg');
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
{{/contentFor}}
|
|
14
|
+
<!--begin::Authentication - Signup Welcome Message -->
|
|
15
|
+
<div class="d-flex flex-column flex-center flex-column-fluid">
|
|
16
|
+
<!--begin::Content-->
|
|
17
|
+
<div class="d-flex flex-column flex-center text-center p-10">
|
|
18
|
+
<!--begin::Wrapper-->
|
|
19
|
+
<div class="card card-flush w-lg-650px py-5">
|
|
20
|
+
<div class="card-body py-15 py-lg-20">
|
|
21
|
+
<!--begin::Title-->
|
|
22
|
+
<h1 class="fw-bolder fs-2hx mb-4">404 Error: Page Not Found</h1>
|
|
23
|
+
<!--end::Title-->
|
|
24
|
+
<!--begin::Text-->
|
|
25
|
+
<div class="fw-semibold fs-6 mb-7">The page you requested could not be found. Please check the URL and try again. If the problem persists, please contact us.</div>
|
|
26
|
+
<!--end::Text-->
|
|
27
|
+
<!--begin::Illustration-->
|
|
28
|
+
<div class="mb-3">
|
|
29
|
+
<img src="/build/theme/media/auth/404-error.png" class="mw-100 mh-300px theme-light-show" alt="" />
|
|
30
|
+
<img src="/build/theme/media/auth/404-error-dark.png" class="mw-100 mh-300px theme-dark-show" alt="" />
|
|
31
|
+
</div>
|
|
32
|
+
<!--end::Illustration-->
|
|
33
|
+
<!--begin::Link-->
|
|
34
|
+
<div class="mb-0">
|
|
35
|
+
<a href="/" class="btn btn-sm btn-primary">Back to Home</a>
|
|
36
|
+
</div>
|
|
37
|
+
<!--end::Link-->
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
<!--end::Wrapper-->
|
|
41
|
+
</div>
|
|
42
|
+
<!--end::Content-->
|
|
43
|
+
</div>
|
|
44
|
+
<!--end::Authentication - Signup Welcome Message-->
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}500 Error: Server Error{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}
|
|
4
|
+
<style>
|
|
5
|
+
body {
|
|
6
|
+
background-image: url('/build/theme/media/auth/bg6.jpg');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
[data-bs-theme="dark"] body {
|
|
10
|
+
background-image: url('/build/theme/media/auth/bg6-dark.jpg');
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
{{/contentFor}}
|
|
14
|
+
<!--begin::Authentication - Signup Welcome Message -->
|
|
15
|
+
<div class="d-flex flex-column flex-center flex-column-fluid">
|
|
16
|
+
<!--begin::Content-->
|
|
17
|
+
<div class="d-flex flex-column flex-center text-center p-10">
|
|
18
|
+
<!--begin::Wrapper-->
|
|
19
|
+
<div class="card card-flush w-lg-650px py-5">
|
|
20
|
+
<div class="card-body py-15 py-lg-20">
|
|
21
|
+
<!--begin::Title-->
|
|
22
|
+
<h1 class="fw-bolder fs-2hx mb-4">500 Error: Server Error</h1>
|
|
23
|
+
<!--end::Title-->
|
|
24
|
+
<!--begin::Text-->
|
|
25
|
+
<div class="fw-semibold fs-6 mb-7">We're sorry, a server error has occurred. Please try again later. If the problem persists, please contact us.</div>
|
|
26
|
+
<!--end::Text-->
|
|
27
|
+
<!--begin::Illustration-->
|
|
28
|
+
<div class="mb-3">
|
|
29
|
+
<img src="/build/theme/media/auth/500-error.png" class="mw-100 mh-300px theme-light-show" alt="" />
|
|
30
|
+
<img src="/build/theme/media/auth/500-error-dark.png" class="mw-100 mh-300px theme-dark-show" alt="" />
|
|
31
|
+
</div>
|
|
32
|
+
<!--end::Illustration-->
|
|
33
|
+
<!--begin::Link-->
|
|
34
|
+
<div class="mb-0">
|
|
35
|
+
<a href="/" class="btn btn-sm btn-primary">Back to Home</a>
|
|
36
|
+
</div>
|
|
37
|
+
<!--end::Link-->
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
<!--end::Wrapper-->
|
|
41
|
+
</div>
|
|
42
|
+
<!--end::Content-->
|
|
43
|
+
</div>
|
|
44
|
+
<!--end::Authentication - Signup Welcome Message-->
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<!--begin::Body-->
|
|
24
24
|
<body
|
|
25
25
|
id="kt_app_body"
|
|
26
|
-
{{#if session}}
|
|
26
|
+
{{#if (and (notEmpty session) (neq isErrorPage true))}}
|
|
27
27
|
data-kt-app-layout="light-sidebar"
|
|
28
28
|
data-kt-app-header-fixed="true"
|
|
29
29
|
data-kt-app-sidebar-enabled="true"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
</script>
|
|
57
57
|
<!--end::Theme mode setup on page load-->
|
|
58
|
-
{{#if session}}
|
|
58
|
+
{{#if (and (notEmpty session) (neq isErrorPage true))}}
|
|
59
59
|
<!--begin::App-->
|
|
60
60
|
<div class="d-flex flex-column flex-root app-root" id="kt_app_root">
|
|
61
61
|
<!--begin::Page-->
|