express-sweet-generator 1.0.0 → 1.0.3
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/CHANGELOG.md +31 -1
- package/README.md +16 -43
- package/bin/express-sweet-cli.js +220 -214
- package/package.json +1 -1
- package/templates/{.env → cjs/.env} +0 -0
- package/templates/{app.js → cjs/app.js} +0 -0
- package/templates/{bin → cjs/bin}/www.ejs +0 -0
- package/templates/{config → cjs/config}/authentication.js +1 -1
- package/templates/{config → cjs/config}/config.js +0 -0
- package/templates/{config → cjs/config}/database.js +6 -12
- package/templates/{config → cjs/config}/view.js +0 -0
- package/templates/{ecosystem.config.js.ejs → cjs/ecosystem.config.js.ejs} +5 -1
- package/templates/{models → cjs/models}/BookModel.js +0 -0
- package/templates/{models → cjs/models}/CommentModel.js +0 -0
- package/templates/{models → cjs/models}/ProfileModel.js +0 -0
- package/templates/{models → cjs/models}/UserModel.js +0 -0
- package/templates/{nginx.sample.conf.ejs → cjs/nginx.sample.conf.ejs} +0 -0
- package/templates/{package.json.ejs → cjs/package.json.ejs} +2 -7
- package/templates/{views/partials/.gitkeep → cjs/public/assets/home.css} +0 -0
- package/templates/cjs/public/assets/home.js +0 -0
- package/templates/{public/assets/styles → cjs/public/assets}/login.css +0 -2
- package/templates/{public/assets/scripts → cjs/public/assets}/login.js +0 -3
- package/templates/{public/assets/images → cjs/public/assets}/logo.svg +0 -0
- package/templates/cjs/public/assets/user.css +0 -0
- package/templates/{public/assets/scripts → cjs/public/assets}/user.js +0 -3
- package/templates/cjs/public/assets/users.css +0 -0
- package/templates/{public/assets/scripts → cjs/public/assets}/users.js +11 -9
- package/templates/{public → cjs/public}/favicon.ico +0 -0
- package/templates/{public → cjs/public}/rekognition-test-image/add-face-to-collection.jpg +0 -0
- package/templates/{public → cjs/public}/rekognition-test-image/compare-faces-source.jpg +0 -0
- package/templates/{public → cjs/public}/rekognition-test-image/compare-faces-target.jpg +0 -0
- package/templates/{public → cjs/public}/rekognition-test-image/detect-faces.jpg +0 -0
- package/templates/{routes → cjs/routes}/api/users.js +7 -33
- package/templates/{routes → cjs/routes}/home.js +0 -3
- package/templates/{routes → cjs/routes}/login.js +0 -3
- package/templates/{routes → cjs/routes}/users.js +3 -9
- package/templates/{views → cjs/views}/error.hbs +1 -2
- package/templates/cjs/views/home.hbs +5 -0
- package/templates/{views → cjs/views}/layout/default.hbs +13 -18
- package/templates/cjs/views/login.hbs +16 -0
- package/templates/cjs/views/partials/.gitkeep +0 -0
- package/templates/cjs/views/user.hbs +35 -0
- package/templates/cjs/views/users.hbs +18 -0
- package/templates/esm/.env +1 -0
- package/templates/esm/app.js +10 -0
- package/templates/esm/bin/www.ejs +67 -0
- package/templates/esm/config/authentication.js +81 -0
- package/templates/esm/config/config.js +78 -0
- package/templates/esm/config/database.js +35 -0
- package/templates/esm/config/view.js +36 -0
- package/templates/esm/ecosystem.config.js.ejs +35 -0
- package/templates/esm/models/BookModel.js +30 -0
- package/templates/esm/models/CommentModel.js +30 -0
- package/templates/esm/models/ProfileModel.js +49 -0
- package/templates/esm/models/UserModel.js +113 -0
- package/templates/esm/nginx.sample.conf.ejs +48 -0
- package/templates/esm/package.json.ejs +21 -0
- package/templates/esm/public/assets/home.css +0 -0
- package/templates/esm/public/assets/home.js +0 -0
- package/templates/esm/public/assets/login.css +16 -0
- package/templates/esm/public/assets/login.js +29 -0
- package/templates/{public/assets/images/logo-dark.svg → esm/public/assets/logo.svg} +2 -2
- package/templates/esm/public/assets/user.css +0 -0
- package/templates/esm/public/assets/user.js +50 -0
- package/templates/esm/public/assets/users.css +0 -0
- package/templates/esm/public/assets/users.js +85 -0
- package/templates/esm/public/favicon.ico +0 -0
- package/templates/esm/public/rekognition-test-image/add-face-to-collection.jpg +0 -0
- package/templates/esm/public/rekognition-test-image/compare-faces-source.jpg +0 -0
- package/templates/esm/public/rekognition-test-image/compare-faces-target.jpg +0 -0
- package/templates/esm/public/rekognition-test-image/detect-faces.jpg +0 -0
- package/templates/esm/routes/api/users.js +98 -0
- package/templates/esm/routes/home.js +8 -0
- package/templates/esm/routes/login.js +8 -0
- package/templates/esm/routes/users.js +31 -0
- package/templates/esm/views/error.hbs +4 -0
- package/templates/esm/views/home.hbs +5 -0
- package/templates/esm/views/layout/default.hbs +57 -0
- package/templates/esm/views/login.hbs +16 -0
- package/templates/esm/views/partials/.gitkeep +0 -0
- package/templates/esm/views/user.hbs +35 -0
- package/templates/esm/views/users.hbs +18 -0
- package/templates/public/assets/scripts/docs.js +0 -1
- package/templates/public/assets/scripts/home.js +0 -3
- package/templates/public/assets/styles/docs.css +0 -2200
- package/templates/public/assets/styles/home.css +0 -1
- package/templates/public/assets/styles/user.css +0 -1
- package/templates/public/assets/styles/users.css +0 -1
- package/templates/views/home.hbs +0 -11
- package/templates/views/login.hbs +0 -27
- package/templates/views/user.hbs +0 -42
- package/templates/views/users.hbs +0 -30
|
@@ -4,38 +4,32 @@
|
|
|
4
4
|
module.exports = {
|
|
5
5
|
development: {
|
|
6
6
|
username: 'root',
|
|
7
|
-
password:
|
|
8
|
-
database: '
|
|
7
|
+
password: 'password',
|
|
8
|
+
database: 'mydb',
|
|
9
9
|
host: 'localhost',
|
|
10
10
|
port: undefined,
|
|
11
11
|
dialect: 'mariadb',
|
|
12
12
|
timezone: '+09:00',
|
|
13
13
|
logging: false
|
|
14
|
-
//,timezone: 'Etc/GMT-9'
|
|
15
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
16
14
|
},
|
|
17
15
|
test: {
|
|
18
16
|
username: 'root',
|
|
19
|
-
password:
|
|
20
|
-
database: '
|
|
17
|
+
password: 'password',
|
|
18
|
+
database: 'mydb',
|
|
21
19
|
host: 'localhost',
|
|
22
20
|
port: undefined,
|
|
23
21
|
dialect: 'mariadb',
|
|
24
22
|
timezone: '+09:00',
|
|
25
23
|
logging: false
|
|
26
|
-
//,timezone: 'Etc/GMT-9'
|
|
27
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
28
24
|
},
|
|
29
25
|
production: {
|
|
30
26
|
username: 'root',
|
|
31
|
-
password:
|
|
32
|
-
database: '
|
|
27
|
+
password: 'password',
|
|
28
|
+
database: 'mydb',
|
|
33
29
|
host: 'localhost',
|
|
34
30
|
port: undefined,
|
|
35
31
|
dialect: 'mariadb',
|
|
36
32
|
timezone: '+09:00',
|
|
37
33
|
logging: false
|
|
38
|
-
//,timezone: 'Etc/GMT-9'
|
|
39
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
40
34
|
}
|
|
41
35
|
}
|
|
File without changes
|
|
@@ -8,7 +8,11 @@ module.exports = {
|
|
|
8
8
|
exec_mode: 'cluster_mode',
|
|
9
9
|
watch: '.',
|
|
10
10
|
watch_delay: 3000,
|
|
11
|
-
ignore_watch : [
|
|
11
|
+
ignore_watch : [
|
|
12
|
+
'node_modules',
|
|
13
|
+
'public',
|
|
14
|
+
'views'
|
|
15
|
+
],
|
|
12
16
|
watch_options: {
|
|
13
17
|
followSymlinks: false,
|
|
14
18
|
usePolling: true
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -9,17 +9,12 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"aws-sdk": "^2.888.0",
|
|
12
|
-
"cookie-parser": "~1.4.4",
|
|
13
12
|
"debug": "~2.6.9",
|
|
14
13
|
"express": "~4.16.1",
|
|
15
|
-
"express-
|
|
16
|
-
"express-session": "^1.17.1",
|
|
17
|
-
"express-sweet": "~1.0.0",
|
|
18
|
-
"express-validator": "^6.10.0",
|
|
14
|
+
"express-sweet": "~1",
|
|
19
15
|
"http-errors": "~1.6.3",
|
|
20
|
-
"morgan": "~1.9.1",
|
|
21
16
|
"passport": "^0.4.1",
|
|
22
17
|
"passport-local": "^1.0.0",
|
|
23
|
-
"sequelize": "^
|
|
18
|
+
"sequelize": "^5.22.4"
|
|
24
19
|
}
|
|
25
20
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/*User list page script*/
|
|
2
|
-
|
|
3
|
-
// Main processing.
|
|
4
1
|
// Set up data table.
|
|
5
2
|
const dt = $('#table')
|
|
6
3
|
.on('draw.dt', () => {
|
|
@@ -14,23 +11,28 @@ const dt = $('#table')
|
|
|
14
11
|
// URL to get list data.
|
|
15
12
|
url: '/api/users',
|
|
16
13
|
// Set action column elements.
|
|
17
|
-
dataSrc: res =>
|
|
14
|
+
dataSrc: res => {
|
|
15
|
+
return res.data.map(row => Object.assign(row, {actions: ''}));
|
|
16
|
+
},
|
|
18
17
|
// For Ajax, send a cookie.
|
|
19
|
-
xhrFields: {
|
|
18
|
+
xhrFields: {
|
|
19
|
+
withCredentials: true
|
|
20
|
+
}
|
|
20
21
|
},
|
|
21
22
|
columns: [
|
|
22
|
-
{data: 'id', width:
|
|
23
|
+
{data: 'id', width: 100},
|
|
23
24
|
{data: 'email'},
|
|
24
25
|
{data: 'name'},
|
|
25
26
|
{data: 'modified', width: 200},
|
|
26
|
-
{data: 'actions', width:
|
|
27
|
+
{data: 'actions', width: 200}
|
|
27
28
|
],
|
|
28
29
|
columnDefs: [
|
|
29
30
|
{
|
|
30
31
|
targets: -1,
|
|
31
32
|
orderable: false,
|
|
32
|
-
render: (data, type, row) =>
|
|
33
|
-
|
|
33
|
+
render: (data, type, row) =>
|
|
34
|
+
`<a href="/users/${row.id}" class="btn btn-success">Edit</a>
|
|
35
|
+
<button on-delete data-id="${row.id}" type="button" class="btn btn-danger mx-2">Delete</button>`
|
|
34
36
|
}
|
|
35
37
|
],
|
|
36
38
|
dom: `<'row'<'col-12'f>><'row'<'col-12'tr>><'row'<'col-12 dataTables_pager'p>>`,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,34 +3,19 @@ const router = express.Router();
|
|
|
3
3
|
const UserModel = require('../../models/UserModel');
|
|
4
4
|
const Authentication = require('express-sweet').services.Authentication;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* Login.
|
|
8
|
-
*/
|
|
6
|
+
// Login.
|
|
9
7
|
router.post('/login', async (req, res, next) => {
|
|
10
|
-
// Authenticate with username and password.
|
|
11
8
|
const isAuthenticated = await Authentication.authenticate(req, res, next);
|
|
12
|
-
|
|
13
|
-
// For asynchronous requests.Returns the authentication result and executes subsequent processing on the front end.
|
|
14
9
|
res.json(isAuthenticated);
|
|
15
|
-
|
|
16
|
-
// // For sync request.If the authentication is successful, you will be redirected to the authentication success page, and if it is unsuccessful, you will be redirected to the login page.
|
|
17
|
-
// if (isAuthenticated)
|
|
18
|
-
// Authentication.successRedirect(res);
|
|
19
|
-
// else
|
|
20
|
-
// Authentication.failureRedirect(res);
|
|
21
10
|
});
|
|
22
11
|
|
|
23
|
-
|
|
24
|
-
* Logout.
|
|
25
|
-
*/
|
|
12
|
+
// Logout.
|
|
26
13
|
router.get('/logout', (req, res) => {
|
|
27
14
|
Authentication.logout(req);
|
|
28
15
|
res.redirect('/');
|
|
29
16
|
});
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
* List Users.
|
|
33
|
-
*/
|
|
18
|
+
// Get a list of users.
|
|
34
19
|
router.get('/', async (req, res) => {
|
|
35
20
|
const data = await UserModel.paginate({
|
|
36
21
|
offset: req.query.offset,
|
|
@@ -43,9 +28,7 @@ router.get('/', async (req, res) => {
|
|
|
43
28
|
res.json(data);
|
|
44
29
|
});
|
|
45
30
|
|
|
46
|
-
|
|
47
|
-
* Create a User.
|
|
48
|
-
*/
|
|
31
|
+
// Create User.
|
|
49
32
|
router.post('/', async (req, res) => {
|
|
50
33
|
// Email duplication check.
|
|
51
34
|
const emailExists = (await UserModel.count({
|
|
@@ -69,9 +52,7 @@ router.post('/', async (req, res) => {
|
|
|
69
52
|
res.json({id: result.id});
|
|
70
53
|
});
|
|
71
54
|
|
|
72
|
-
|
|
73
|
-
* Update a User.
|
|
74
|
-
*/
|
|
55
|
+
// Update User.
|
|
75
56
|
router.put('/:id(\\d+)', async (req, res) => {
|
|
76
57
|
// Email duplication check.
|
|
77
58
|
const emailExists = (await UserModel.count({
|
|
@@ -107,16 +88,9 @@ router.put('/:id(\\d+)', async (req, res) => {
|
|
|
107
88
|
res.json(true);
|
|
108
89
|
});
|
|
109
90
|
|
|
110
|
-
|
|
111
|
-
* Delete a User.
|
|
112
|
-
*/
|
|
91
|
+
// Delete user.
|
|
113
92
|
router.delete('/:id(\\d+)', async (req, res) => {
|
|
114
|
-
|
|
115
|
-
await UserModel.destroy({
|
|
116
|
-
where: {
|
|
117
|
-
id: req.params.id
|
|
118
|
-
}
|
|
119
|
-
});
|
|
93
|
+
await UserModel.destroy({where: {id: req.params.id}});
|
|
120
94
|
res.json(true);
|
|
121
95
|
});
|
|
122
96
|
|
|
@@ -2,9 +2,7 @@ const express = require('express');
|
|
|
2
2
|
const router = express.Router();
|
|
3
3
|
const UserModel = require('../models/UserModel');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* User edit page.
|
|
7
|
-
*/
|
|
5
|
+
// Edit User.
|
|
8
6
|
router.get('/:id(\\d+)', async (req, res) => {
|
|
9
7
|
// Find a user that matches your ID.
|
|
10
8
|
const user = await UserModel.findByPk(req.params.id, {
|
|
@@ -20,16 +18,12 @@ router.get('/:id(\\d+)', async (req, res) => {
|
|
|
20
18
|
res.render('user', {user, edit: true});
|
|
21
19
|
});
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
* User addition page.
|
|
25
|
-
*/
|
|
21
|
+
// Create User.
|
|
26
22
|
router.get('/new', async (req, res) => {
|
|
27
23
|
res.render('user', {edit: false});
|
|
28
24
|
});
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
* Users page.
|
|
32
|
-
*/
|
|
26
|
+
// User List.
|
|
33
27
|
router.get('/', async (req, res) => {
|
|
34
28
|
res.render('users');
|
|
35
29
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}Home{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}<link rel="stylesheet" type="text/css" href="{{cache_busting '/assets/home.css' baseUrl}}">{{/contentFor}}
|
|
4
|
+
{{#contentFor 'script'}}<script src="{{cache_busting '/assets/home.js' baseUrl}}"></script>{{/contentFor}}
|
|
5
|
+
<h1 class="mt-5 text-center">Welcome to Express Sweet</h1>
|
|
@@ -3,27 +3,25 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>{{{block "title"}}} |
|
|
7
|
-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.
|
|
8
|
-
<link rel="stylesheet" type="text/css" href="
|
|
9
|
-
<!-- <link rel="stylesheet" type="text/css" href="{{baseUrl}}/assets/styles/docs.css"> -->
|
|
6
|
+
<title>{{{block "title"}}} | Exspress Sweet Template</title>
|
|
7
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
|
8
|
+
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/dataTables.bootstrap5.min.css">
|
|
10
9
|
{{{block "style"}}}
|
|
11
10
|
</head>
|
|
12
11
|
<body>
|
|
13
12
|
{{#if session}}
|
|
14
|
-
<header class="navbar navbar-expand-md navbar-
|
|
15
|
-
<!-- <header class="navbar navbar-expand-md navbar-light bg-light"> -->
|
|
13
|
+
<header class="navbar navbar-expand-md navbar-light">
|
|
16
14
|
<nav class="container-xxl flex-wrap flex-md-nowrap" aria-label="Main navigation">
|
|
17
|
-
<a class="navbar-brand p-0 me-2" href="
|
|
18
|
-
<img src="{{baseUrl}}/assets/
|
|
15
|
+
<a class="navbar-brand p-0 me-2" href="/">
|
|
16
|
+
<img src="{{baseUrl}}/assets/logo.svg" height="32">
|
|
19
17
|
</a>
|
|
20
18
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#bdNavbar" aria-controls="bdNavbar" aria-expanded="false" aria-label="Toggle navigation">
|
|
21
19
|
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" class="bi" fill="currentColor" viewBox="0 0 16 16">
|
|
22
|
-
<path fill-rule="evenodd" d="M2.5 11.5A.5.5 0 0 1 3 11h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 3h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"
|
|
20
|
+
<path fill-rule="evenodd" d="M2.5 11.5A.5.5 0 0 1 3 11h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 3h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"></path>
|
|
23
21
|
</svg>
|
|
24
22
|
</button>
|
|
25
23
|
<div class="collapse navbar-collapse" id="bdNavbar">
|
|
26
|
-
<ul class="navbar-nav flex-row flex-wrap
|
|
24
|
+
<ul class="navbar-nav flex-row flex-wrap pt-2 py-md-0">
|
|
27
25
|
<li class="nav-item col-6 col-md-auto">
|
|
28
26
|
<a class="nav-link p-2 {{#if (eq currentPath '/')}}active{{/if}}" href="{{baseUrl}}">Home</a>
|
|
29
27
|
</li>
|
|
@@ -31,7 +29,7 @@
|
|
|
31
29
|
<a class="nav-link p-2 {{#if (eq currentPath '/users')}}active{{/if}}" href="{{baseUrl}}/users">Users</a>
|
|
32
30
|
</li>
|
|
33
31
|
</ul>
|
|
34
|
-
<a class="
|
|
32
|
+
<a class="my-md-0 ms-md-auto" href="{{baseUrl}}/api/users/logout">Logout</a>
|
|
35
33
|
</div>
|
|
36
34
|
</nav>
|
|
37
35
|
</header>
|
|
@@ -41,22 +39,19 @@
|
|
|
41
39
|
{{else}}
|
|
42
40
|
{{{body}}}
|
|
43
41
|
{{/if}}
|
|
44
|
-
|
|
45
42
|
<script>
|
|
46
43
|
// Application base URL.
|
|
47
44
|
globalThis.baseUrl = '{{baseUrl}}';
|
|
48
|
-
|
|
49
45
|
// User session.
|
|
50
46
|
{{#if session}}
|
|
51
47
|
globalThis.$$session = {{{json_stringify session}}};
|
|
52
48
|
{{/if}}
|
|
53
49
|
</script>
|
|
54
|
-
|
|
55
50
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
|
56
|
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.
|
|
57
|
-
<script src="
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
|
52
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js" integrity="sha512-UdIMMlVx0HEynClOIFSyOrPggomfhBKJE28LKl8yR3ghkgugPnG6iLfRfHwushZl1MOPSY6TsuBDGPK2X4zYKg==" crossorigin="anonymous"></script>
|
|
53
|
+
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
|
|
54
|
+
<script src="https://cdn.datatables.net/1.10.24/js/dataTables.bootstrap5.min.js"></script>
|
|
60
55
|
{{{block "script"}}}
|
|
61
56
|
</body>
|
|
62
57
|
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}Login{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}<link rel="stylesheet" type="text/css" href="{{cache_busting '/assets/login.css' baseUrl}}">{{/contentFor}}
|
|
4
|
+
{{#contentFor 'script'}}<script src="{{cache_busting '/assets/login.js' baseUrl}}"></script>{{/contentFor}}
|
|
5
|
+
<form id="form" class="w-100 mx-auto my-0 login-form">
|
|
6
|
+
<h1 class="h3 mb-3 font-weight-normal text-center">Please login</h1>
|
|
7
|
+
<div class="mb-3">
|
|
8
|
+
<label class="form-label">Email address</label>
|
|
9
|
+
<input type="email" class="form-control" name="email" required autofocus value="robin@example.com">
|
|
10
|
+
</div>
|
|
11
|
+
<div class="mb-3">
|
|
12
|
+
<label class="form-label">Password</label>
|
|
13
|
+
<input type="password" class="form-control" name="password" required value="password">
|
|
14
|
+
</div>
|
|
15
|
+
<button class="btn btn-primary d-block w-100" type="submit">Login</button>
|
|
16
|
+
</form>
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}User Information{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}<link rel="stylesheet" type="text/css" href="{{cache_busting '/assets/user.css' baseUrl}}">{{/contentFor}}
|
|
4
|
+
{{#contentFor 'script'}}<script src="{{cache_busting '/assets/user.js' baseUrl}}"></script>{{/contentFor}}
|
|
5
|
+
<div class="row justify-content-center">
|
|
6
|
+
<div class="col-12 col-md-7">
|
|
7
|
+
<h3 class="font-weight-bold">
|
|
8
|
+
{{ifx edit 'Edit a user' 'Create a new user'}}
|
|
9
|
+
</h3>
|
|
10
|
+
<form id="form">
|
|
11
|
+
<div class="mb-3">
|
|
12
|
+
<label class="form-label">Email</label>
|
|
13
|
+
<input type="email" class="form-control" name="email" value="{{user.email}}" required autofocus>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="mb-3">
|
|
16
|
+
<label class="form-label">Name</label>
|
|
17
|
+
<input type="text" class="form-control" name="name" value="{{user.name}}" required>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="mb-3">
|
|
20
|
+
<label class="form-label">Password</label>
|
|
21
|
+
<input type="password" class="form-control" name="password" aria-describedby="passwordHelp" {{#unless edit}}required{{/unless}}>
|
|
22
|
+
{{#if edit}}
|
|
23
|
+
<div id="passwordHelp" class="form-text">Enter only if you want to change the password.</div>
|
|
24
|
+
{{/if}}
|
|
25
|
+
</div>
|
|
26
|
+
<div class="d-flex justify-content-between mt-3">
|
|
27
|
+
<a href="{{baseUrl}}/users" class="btn btn-secondary">Back to User List</a>
|
|
28
|
+
<button type="submit" class="btn btn-primary">Save user information</button>
|
|
29
|
+
</div>
|
|
30
|
+
</form>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
{{#if edit}}<input type="hidden" id="id" value="{{user.id}}">{{/if}}
|
|
35
|
+
<input type="hidden" id="edit" value="{{ifx edit 1 0}}">
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{{!< default}}
|
|
2
|
+
{{#contentFor 'title'}}User Management{{/contentFor}}
|
|
3
|
+
{{#contentFor 'style'}}<link rel="stylesheet" type="text/css" href="{{cache_busting '/assets/users.css' baseUrl}}">{{/contentFor}}
|
|
4
|
+
{{#contentFor 'script'}}<script src="{{cache_busting '/assets/users.js' baseUrl}}"></script>{{/contentFor}}
|
|
5
|
+
<div class="d-flex mb-4">
|
|
6
|
+
<a href="/users/new" class="btn btn-primary ms-auto">Create new user</a>
|
|
7
|
+
</div>
|
|
8
|
+
<table class="table w-100" id="table">
|
|
9
|
+
<thead>
|
|
10
|
+
<tr>
|
|
11
|
+
<th scope="col">User ID</th>
|
|
12
|
+
<th scope="col">Email</th>
|
|
13
|
+
<th scope="col">Name</th>
|
|
14
|
+
<th scope="col">Modified</th>
|
|
15
|
+
<th scope="col">#</th>
|
|
16
|
+
</tr>
|
|
17
|
+
</thead>
|
|
18
|
+
</table>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NODE_ENV=development
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
import app from '../app';
|
|
6
|
+
import Debug from 'debug';
|
|
7
|
+
import http from 'http';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Normalize a port into a number, string, or false.
|
|
11
|
+
*/
|
|
12
|
+
function normalizePort(val) {
|
|
13
|
+
var port = parseInt(val, 10);
|
|
14
|
+
// named pipe
|
|
15
|
+
if (isNaN(port)) return val;
|
|
16
|
+
|
|
17
|
+
// port number
|
|
18
|
+
if (port >= 0) return port;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Event listener for HTTP server "error" event.
|
|
24
|
+
*/
|
|
25
|
+
function onError(error) {
|
|
26
|
+
if (error.syscall !== 'listen')
|
|
27
|
+
throw error;
|
|
28
|
+
const bind = typeof port === 'string' ? `Pipe ${port}` : `Port ${port}`;
|
|
29
|
+
|
|
30
|
+
// handle specific listen errors with friendly messages
|
|
31
|
+
switch (error.code) {
|
|
32
|
+
case 'EACCES':
|
|
33
|
+
console.error(`${bind} requires elevated privileges`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
break;
|
|
36
|
+
case 'EADDRINUSE':
|
|
37
|
+
console.error(`${bind} is already in use`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Event listener for HTTP server "listening" event.
|
|
47
|
+
*/
|
|
48
|
+
function onListening() {
|
|
49
|
+
const addr = server.address();
|
|
50
|
+
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
|
|
51
|
+
debug(`Listening on ${bind}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Get port from environment and store in Express.
|
|
55
|
+
const port = normalizePort(process.env.PORT || '3000');
|
|
56
|
+
app.set('port', port);
|
|
57
|
+
|
|
58
|
+
// Create HTTP server.
|
|
59
|
+
const server = http.createServer(app);
|
|
60
|
+
|
|
61
|
+
// Debugger
|
|
62
|
+
const debug = Debug('<%- name %>:server');
|
|
63
|
+
|
|
64
|
+
// Listen on provided port, on all network interfaces.
|
|
65
|
+
server.listen(port);
|
|
66
|
+
server.on('error', onError);
|
|
67
|
+
server.on('listening', onListening);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import UserModel from '../models/UserModel';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* User authentication configuration interface.
|
|
5
|
+
*/
|
|
6
|
+
export default {
|
|
7
|
+
/**
|
|
8
|
+
* Enable user authentication, defaults to disabled (false).
|
|
9
|
+
* @type {boolean}
|
|
10
|
+
*/
|
|
11
|
+
enabled: true,
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Authentication user ID field name, defaults to `username`.
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
username: 'email',
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Authentication password field name, defaults to `password`.
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
password: 'password',
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* URL to redirect after successful authentication, defaults to `/`.
|
|
27
|
+
* @type {string}
|
|
28
|
+
*/
|
|
29
|
+
success_redirect: '/',
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* URL to redirect after log off, defaults to `/login`.
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
failure_redirect: '/login',
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This hook is called when authenticating a user.
|
|
39
|
+
* Please find the user information that owns the credentials based on the user name and password you received and return it.
|
|
40
|
+
* If the user who owns the credentials cannot be found, return null.
|
|
41
|
+
*
|
|
42
|
+
* Note that the user information must include an ID value that can identify the user.
|
|
43
|
+
*
|
|
44
|
+
* @type {(username: string, password: string) => Promise<{[key: string]: any}|null>}
|
|
45
|
+
*/
|
|
46
|
+
authenticate_user: async (username, password) => {
|
|
47
|
+
return UserModel.findOne({
|
|
48
|
+
where: {
|
|
49
|
+
email: username,
|
|
50
|
+
password: password
|
|
51
|
+
},
|
|
52
|
+
raw: true
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This hook is called when user authentication is successful.
|
|
58
|
+
* Please search and return the authenticated user information to be set in the session based on the user ID of the parameter.
|
|
59
|
+
* The returned data will be set in the req.user property and the view's session variable.
|
|
60
|
+
*
|
|
61
|
+
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
62
|
+
*/
|
|
63
|
+
subscribe_user: async (id) => {
|
|
64
|
+
return UserModel.findOne({
|
|
65
|
+
where: {id},
|
|
66
|
+
raw: true
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
|
|
72
|
+
* @type {(string|RegExp)[]}
|
|
73
|
+
*/
|
|
74
|
+
allow_unauthenticated: ['/api'],
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
|
|
78
|
+
* @type {number}
|
|
79
|
+
*/
|
|
80
|
+
expiration: 24 * 3600000
|
|
81
|
+
}
|