zet-lib 1.0.2 → 1.0.4
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/lib/connection.js +18 -16
- package/lib/index.js +1 -0
- package/lib/views/zrole/index.ejs +121 -0
- package/lib/views/zrole/indexjs.ejs +57 -0
- package/lib/zRole.js +12 -9
- package/lib/zRoleRouter.js +161 -0
- package/lib/zapp.js +73 -72
- package/package.json +1 -1
package/lib/connection.js
CHANGED
|
@@ -156,6 +156,7 @@ connection.insert = async(obj) => {
|
|
|
156
156
|
console.log(sql);
|
|
157
157
|
console.log(arr);
|
|
158
158
|
console.log(e.toString());
|
|
159
|
+
throw e;
|
|
159
160
|
}
|
|
160
161
|
};
|
|
161
162
|
|
|
@@ -196,21 +197,15 @@ connection.update = async(obj) => {
|
|
|
196
197
|
const sql = `UPDATE "${table}" SET ${dataArr.join(", ")} ${wheres} RETURNING *`;
|
|
197
198
|
/* console.log(sql);
|
|
198
199
|
console.log(arr);*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
console.log("Error on Update ");
|
|
209
|
-
console.log(err)
|
|
210
|
-
return {}
|
|
211
|
-
}
|
|
212
|
-
*/
|
|
213
|
-
|
|
200
|
+
try {
|
|
201
|
+
const result = await pool.query(sql, arr);
|
|
202
|
+
return result.rows[0];
|
|
203
|
+
} catch (e) {
|
|
204
|
+
console.log(sql);
|
|
205
|
+
console.log(arr);
|
|
206
|
+
console.log(e.toString());
|
|
207
|
+
throw e;
|
|
208
|
+
}
|
|
214
209
|
};
|
|
215
210
|
|
|
216
211
|
connection.delete = async(obj) => {
|
|
@@ -228,7 +223,14 @@ connection.delete = async(obj) => {
|
|
|
228
223
|
const sql = `DELETE FROM "${table}" ${wheres}`
|
|
229
224
|
/*console.log(sql);
|
|
230
225
|
console.log(arr)*/
|
|
231
|
-
|
|
226
|
+
try {
|
|
227
|
+
return await pool.query(sql, arr);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
console.log(sql);
|
|
230
|
+
console.log(arr);
|
|
231
|
+
console.log(e.toString());
|
|
232
|
+
throw e;
|
|
233
|
+
}
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
connection.driver = config.driver;
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<div class="">
|
|
2
|
+
<div class="page-header"><h1>Roles</h1></div>
|
|
3
|
+
<div class="card panel panel-info boxy">
|
|
4
|
+
<div class="panel-heading">
|
|
5
|
+
<div class="float-end">
|
|
6
|
+
<div class="summary">
|
|
7
|
+
<% if(levels.delete) {%>
|
|
8
|
+
<span
|
|
9
|
+
class="icon-small icons-danger" title="Delete role" onclick="deleterole()"><img class="icons-bg-white icon-image"
|
|
10
|
+
src="/assets/icons/trash.svg"></span>
|
|
11
|
+
<%}%>
|
|
12
|
+
<% if(levels.update) {%>
|
|
13
|
+
<span class="icon-small icons-primary" data-bs-toggle="modal"
|
|
14
|
+
data-bs-target="#renameModal" title="rename"><img
|
|
15
|
+
class="icons-bg-white icon-image" src="/assets/icons/edit.svg"></span>
|
|
16
|
+
<%}%>
|
|
17
|
+
<% if(levels.create) {%>
|
|
18
|
+
<span
|
|
19
|
+
class="icon-small icons-success" title="Add a new role" data-bs-toggle="modal"
|
|
20
|
+
data-bs-target="#addModal"><img class="icons-bg-white icon-image"
|
|
21
|
+
src="/assets/icons/plus.svg"></span>
|
|
22
|
+
<%}%>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
<h3 class="panel-title"><i class="fa fa-cog"></i> Settings</h3>
|
|
28
|
+
<div class="clearfix"></div>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="kv-panel-before">
|
|
31
|
+
<div class="row">
|
|
32
|
+
<form id="role-form" class="form-horizontal kv-form-horizontal" method="post"><input type="hidden"
|
|
33
|
+
name="_csrf"
|
|
34
|
+
value="<%- csrfToken %>">
|
|
35
|
+
<div class="form-group field-role-role_name"><label class="control-label col-md-2"
|
|
36
|
+
for="role-role_name">Role Name</label>
|
|
37
|
+
<div class="col-md-10"><select id="roleName" class="form-control form-select mb-3" name="name">
|
|
38
|
+
<% for(var i = 0;i < results.length;i++){ %>
|
|
39
|
+
<option value="<%- results[i].id %>"
|
|
40
|
+
<% if(id == results[i].id){ %> selected=""
|
|
41
|
+
<% } %>
|
|
42
|
+
><%- results[i].name %></option>
|
|
43
|
+
<% } %>
|
|
44
|
+
</select></div>
|
|
45
|
+
</div>
|
|
46
|
+
<table class="table table-responsive">
|
|
47
|
+
<thead>
|
|
48
|
+
<tr>
|
|
49
|
+
<th>Name</th>
|
|
50
|
+
<% for(var i = 0;i < actions.length;i++) { %>
|
|
51
|
+
<th><%= actions[i] %> <input onclick='checkthis("<%= actions[i] %>")' type="checkbox"
|
|
52
|
+
id="all<%= actions[i] %>"></th>
|
|
53
|
+
<% } %>
|
|
54
|
+
</tr>
|
|
55
|
+
</thead>
|
|
56
|
+
<tbody>
|
|
57
|
+
<% for(var i = 0;i < routes.length;i++) { %>
|
|
58
|
+
<tr>
|
|
59
|
+
<td>
|
|
60
|
+
<% var ename = routes[i] %>
|
|
61
|
+
<%= ename %></td>
|
|
62
|
+
<% for(var x = 0;x < actions.length;x++) { %>
|
|
63
|
+
<td><input name="params[<%= ename %>][<%= actions[x] %>]" class="<%= actions[x] %>"
|
|
64
|
+
<% if(json && json.hasOwnProperty(ename) && json[ename].indexOf(actions[x]) >= 0) { %> <%= 'checked="checked"' %>
|
|
65
|
+
<% } %>
|
|
66
|
+
title="Role for <%= routes[i] %> <%= actions[x] %>" type="checkbox"></td>
|
|
67
|
+
<% } %>
|
|
68
|
+
</tr>
|
|
69
|
+
<% } %>
|
|
70
|
+
</tbody>
|
|
71
|
+
</table>
|
|
72
|
+
<div class="row">
|
|
73
|
+
<div class="col-md-10 col-md-offset-1">
|
|
74
|
+
<% if(levels.update) {%>
|
|
75
|
+
<button type="submit" class="btn btn-primary">Update</button>
|
|
76
|
+
<%}%>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</form>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</div><!-- Modal -->
|
|
84
|
+
<div class="modal fade" id="renameModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
85
|
+
<div class="modal-dialog">
|
|
86
|
+
<div class="modal-content">
|
|
87
|
+
<div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Rename title</h5>
|
|
88
|
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="modal-body"><input type="text" class="form-control" id="rename" name="rename"
|
|
91
|
+
value="<%- model[0].name %>"></div>
|
|
92
|
+
<div class="modal-footer">
|
|
93
|
+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
94
|
+
<button type="button" class="btn btn-primary btn-update">Save changes</button>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</div><!-- Modal -->
|
|
99
|
+
<div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
|
|
100
|
+
<div class="modal-dialog">
|
|
101
|
+
<div class="modal-content">
|
|
102
|
+
<div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Add a New Role</h5>
|
|
103
|
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
104
|
+
</div>
|
|
105
|
+
<div class="modal-body">
|
|
106
|
+
<div class="form-group mb-3"><label for="ruas_sk">Role Name</label> <input type="text"
|
|
107
|
+
class="form-control"
|
|
108
|
+
id="role_name"
|
|
109
|
+
name="role_name"
|
|
110
|
+
placeholder="Role Name">
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
<div class="modal-footer">
|
|
114
|
+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
115
|
+
<button type="button" class="btn btn-primary btn-add">Save changes</button>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
function checkthis(elm) {
|
|
3
|
+
var cElem = $("#all" + elm);
|
|
4
|
+
if (cElem.is(":checked")) {
|
|
5
|
+
$("input." + elm).prop("checked", true);
|
|
6
|
+
} else {
|
|
7
|
+
$("input." + elm).prop("checked", false);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
$("#roleName").on('change', function () {
|
|
11
|
+
location.href = "/zrole?id=" + $(this).val();
|
|
12
|
+
});
|
|
13
|
+
var form = document.getElementById("role-form");
|
|
14
|
+
form.onsubmit = function (ev) {
|
|
15
|
+
ev.preventDefault();
|
|
16
|
+
var url = '/zrole/update/<%= id%>';
|
|
17
|
+
ajaxPost(url, $(this).serialize(), function (data) {
|
|
18
|
+
if (data.status == 1) {
|
|
19
|
+
toastr.success('Success', 'Updated Role');
|
|
20
|
+
} else {
|
|
21
|
+
toastr.error('Error!',data.data);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
$(".btn-update").on("click", function () {
|
|
26
|
+
ajaxPost('/zrole/rename/<%= id%>',{
|
|
27
|
+
rename : $("#rename").val()
|
|
28
|
+
}, function (data) {
|
|
29
|
+
toastrForm(data);
|
|
30
|
+
setTimeout(function () {
|
|
31
|
+
location.href= '';
|
|
32
|
+
},2000);
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
$(".btn-add").on("click", function () {
|
|
37
|
+
ajaxPost('/zrole/create/',{
|
|
38
|
+
name : $("#role_name").val()
|
|
39
|
+
}, function (data) {
|
|
40
|
+
toastrForm(data);
|
|
41
|
+
setTimeout(function () {
|
|
42
|
+
location.href= '';
|
|
43
|
+
},2000);
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
function deleterole() {
|
|
47
|
+
if(window.confirm('delete role selected ? ')) {
|
|
48
|
+
let id = "<%= id%>";
|
|
49
|
+
ajaxDelete('/zrole/delete/<%= id%>',{id:id}, function (data) {
|
|
50
|
+
toastrForm(data);
|
|
51
|
+
setTimeout(function () {
|
|
52
|
+
location.href= '/zrole';
|
|
53
|
+
},2000);
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
</script>
|
package/lib/zRole.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Util = require('./Util');
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const myCache = require("./cache");
|
|
4
|
+
const zRoute = require('./zRoute');
|
|
4
5
|
|
|
5
6
|
const a = {};
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ const a = {};
|
|
|
8
9
|
Please add your routes here
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
const routes =
|
|
12
|
+
const routes = zRoute.ROUTES();
|
|
12
13
|
const cacheRoutes = myCache.get("ROUTES");
|
|
13
14
|
const cacheRoles = myCache.get("ROLES") || {};
|
|
14
15
|
|
|
@@ -18,7 +19,6 @@ if(cacheRoutes && cacheRoutes.length) {
|
|
|
18
19
|
a.routes = process.env.NODE_ENV == "production" ? Util.arrayDeletes(routes,["auth","test"]) : Util.arrayDeletes(routes,["generator","auth","test"]);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
22
|
/*
|
|
23
23
|
Default actions
|
|
24
24
|
you can additional here
|
|
@@ -31,10 +31,10 @@ a.actions = ['index', 'create', 'update', 'delete', 'view', 'import', 'export','
|
|
|
31
31
|
|
|
32
32
|
a.params = function (roleId) {
|
|
33
33
|
let cacheRoles = myCache.get("ROLES");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if(cacheRoles && cacheRoles.hasOwnProperty(roleId)) {
|
|
35
|
+
return roleId ? cacheRoles[roleId].params : {};
|
|
36
|
+
}
|
|
37
|
+
return {}
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
a.rules = function (roleId) {
|
|
@@ -65,10 +65,14 @@ a.levels = (route, params) => {
|
|
|
65
65
|
obj[a.actions[i]] = true;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
|
|
69
68
|
return obj;
|
|
70
69
|
};
|
|
71
70
|
|
|
71
|
+
a.myLevel = (req, res, table) => {
|
|
72
|
+
const levels = a.levels(table, a.routes.includes(table) ? a.rules(res.locals.roleId) : {});
|
|
73
|
+
return levels;
|
|
74
|
+
}
|
|
75
|
+
|
|
72
76
|
a.menuAccess = (res, menu) => {
|
|
73
77
|
if(Array.isArray(menu)) {
|
|
74
78
|
let isTrue = false;
|
|
@@ -129,9 +133,8 @@ a.access = (req, res, next) => {
|
|
|
129
133
|
req.session.sessionFlash = Util.flashError(LANGUAGE.no_access);
|
|
130
134
|
res.redirect(`${process.env.APP_AFTER_LOGIN}?setup=role`)
|
|
131
135
|
} else {
|
|
132
|
-
res.redirect(`${process.env.
|
|
136
|
+
res.redirect(`${process.env.APP_AFTER_LOGIN}`)
|
|
133
137
|
}
|
|
134
|
-
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const router = express.Router();
|
|
3
|
+
// setup route middlewares
|
|
4
|
+
const csrf = require('csurf');
|
|
5
|
+
const bodyParser = require('body-parser');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const parseForm = bodyParser.urlencoded({extended: true});
|
|
8
|
+
const csrfProtection = csrf({cookie: true});
|
|
9
|
+
const pm2 = require('pm2');
|
|
10
|
+
const env = process.env.NODE_ENV || 'development';
|
|
11
|
+
const ejs = require('ejs');
|
|
12
|
+
const Util = require('./Util');
|
|
13
|
+
const access = require('./access');
|
|
14
|
+
const connection = require('./connection');
|
|
15
|
+
const zCache = require('./zCache');
|
|
16
|
+
const zRole = require('./zRole');
|
|
17
|
+
const moduleLib = require('./moduleLib');
|
|
18
|
+
|
|
19
|
+
router.get('/', csrfProtection, async function (req, res, next) {
|
|
20
|
+
let dirname = './';
|
|
21
|
+
let id = req.query.id;
|
|
22
|
+
if (id == undefined) {
|
|
23
|
+
id = 1;
|
|
24
|
+
}
|
|
25
|
+
const model = await connection.results({
|
|
26
|
+
table : "zrole",
|
|
27
|
+
where : {
|
|
28
|
+
id : id
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const json = model[0].params ;
|
|
32
|
+
const routes = zRole.routes;
|
|
33
|
+
const results = await connection.results({table:"zrole"});
|
|
34
|
+
const myLevel = zRole.myLevel(req, res, 'zrole');
|
|
35
|
+
//inject to end body
|
|
36
|
+
let datas = {
|
|
37
|
+
model: model,
|
|
38
|
+
table: "zrole",
|
|
39
|
+
id: id,
|
|
40
|
+
actions: zRole.actions,
|
|
41
|
+
routes: routes,
|
|
42
|
+
levels:myLevel,
|
|
43
|
+
json: json,
|
|
44
|
+
results: results,
|
|
45
|
+
csrfToken: req.csrfToken()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const bodyHTML = ejs.render(Util.readFile(path.join(dirname,'views/zrole/index.ejs')),datas);
|
|
49
|
+
const endBody = ejs.render(Util.readFile(path.join(dirname,'views/zrole/indexjs.ejs')), datas);
|
|
50
|
+
datas.bodyHTML = bodyHTML;
|
|
51
|
+
moduleLib.addModule(req,res,endBody)
|
|
52
|
+
|
|
53
|
+
//moduleLib.addModule(req, res, Util.readFile(path.join(dirname,'views/zrole/indexjs.ejs')));
|
|
54
|
+
res.render("layouts/"+layout, datas);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
router.post('/update/:id',async function (req, res, next) {
|
|
58
|
+
const data = {};
|
|
59
|
+
const name = req.body.name;
|
|
60
|
+
const params = req.body.params;
|
|
61
|
+
const newKey = {};
|
|
62
|
+
Object.keys(params).map( (key) => {
|
|
63
|
+
const arr = [];
|
|
64
|
+
for (const k in params[key]) {
|
|
65
|
+
arr.push(k);
|
|
66
|
+
}
|
|
67
|
+
newKey[key] = arr;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const json = {};
|
|
71
|
+
json.params = JSON.stringify(newKey);
|
|
72
|
+
try {
|
|
73
|
+
await connection.update({
|
|
74
|
+
table : "zrole",
|
|
75
|
+
data : {
|
|
76
|
+
params : json.params
|
|
77
|
+
},
|
|
78
|
+
where : {
|
|
79
|
+
id : req.params.id
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
data.status = 1;
|
|
83
|
+
data.data = 1;
|
|
84
|
+
await zCache.ROLES();
|
|
85
|
+
|
|
86
|
+
if(env == "production") {
|
|
87
|
+
pm2.connect(function (err) {
|
|
88
|
+
if (err) {
|
|
89
|
+
//console.log(err.toString());
|
|
90
|
+
}
|
|
91
|
+
pm2.restart(process.env.PM2_NAME, (err, proc) => {
|
|
92
|
+
//io.to(room).emit("message","Restart done")
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
res.json(data);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
data.status = 0;
|
|
99
|
+
data.data = error;
|
|
100
|
+
res.json(data);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
router.post('/rename/:id', async (req,res) => {
|
|
105
|
+
let json = Util.jsonSuccess();
|
|
106
|
+
try {
|
|
107
|
+
const id = req.params.id;
|
|
108
|
+
const rename = req.body.rename;
|
|
109
|
+
await connection.update({
|
|
110
|
+
table : "zrole",
|
|
111
|
+
where : {
|
|
112
|
+
id : id
|
|
113
|
+
},
|
|
114
|
+
data : {name : rename}
|
|
115
|
+
})
|
|
116
|
+
} catch (e) {
|
|
117
|
+
json = Util.flashError(e.toString())
|
|
118
|
+
}
|
|
119
|
+
res.json(json);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
router.post('/create', async (req,res) => {
|
|
123
|
+
let json = Util.jsonSuccess();
|
|
124
|
+
try {
|
|
125
|
+
const name = req.body.name;
|
|
126
|
+
await connection.insert({
|
|
127
|
+
table : "zrole",
|
|
128
|
+
data : {
|
|
129
|
+
name : name
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
await zCache.ROLES();
|
|
133
|
+
} catch (e) {
|
|
134
|
+
json = Util.flashError(e.toString())
|
|
135
|
+
}
|
|
136
|
+
res.json(json);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
router.delete('/delete/:id', async (req,res) => {
|
|
140
|
+
let json = Util.jsonSuccess();
|
|
141
|
+
let id = parseInt(req.params.id);
|
|
142
|
+
if(id > 3){
|
|
143
|
+
try {
|
|
144
|
+
const name = req.body.name;
|
|
145
|
+
await connection.delete({
|
|
146
|
+
table : "zrole",
|
|
147
|
+
where : {
|
|
148
|
+
id : id
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
await zCache.ROLES();
|
|
152
|
+
} catch (e) {
|
|
153
|
+
json = Util.flashError(e.toString())
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
json = Util.flashError('Delete error, not allowed');
|
|
157
|
+
}
|
|
158
|
+
res.json(json);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
module.exports = router;
|
package/lib/zapp.js
CHANGED
|
@@ -2,78 +2,79 @@ const config = require('dotenv').config();
|
|
|
2
2
|
const dirRoot = process.env.dirRoot;
|
|
3
3
|
const menuGenerator = require('./menuGenerator');
|
|
4
4
|
module.exports = (req,res,next) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
res.locals.renderHead = "";
|
|
6
|
+
res.locals.renderBody = "";
|
|
7
|
+
res.locals.bodyHTML = '';
|
|
8
|
+
res.locals.renderEnd = "";
|
|
9
|
+
res.locals.titleApp = process.env.APP_TITLE;
|
|
10
|
+
res.locals.descriptionApp = process.env.APP_DESCRIPTION;
|
|
11
|
+
res.locals.moduleHead = "";
|
|
12
|
+
res.locals.relationsVariable = "";
|
|
13
|
+
res.locals.moduleEnd = "";
|
|
14
|
+
res.locals.menuApp = "home";
|
|
15
|
+
res.locals.routeName = "index";
|
|
16
|
+
res.locals.userId = -1;
|
|
17
|
+
res.locals.csrfToken = "";
|
|
18
|
+
res.locals.roleId = 0;
|
|
19
|
+
res.locals.token = "guest";
|
|
20
|
+
res.locals.companyId = 0;
|
|
21
|
+
res.locals.userId = 0;
|
|
22
|
+
res.locals.userAvatar = "/img/user.png";
|
|
23
|
+
res.locals.zuser = {
|
|
24
|
+
fullname: 'test',
|
|
25
|
+
role: {name: "test"}
|
|
26
|
+
};
|
|
27
|
+
res.locals.frameworkcss = "bootstrap5";
|
|
28
|
+
res.locals.startup = 0;
|
|
29
|
+
global.frameworkcss = "bootstrap5";
|
|
30
|
+
global.LANGUAGE = require('./languages/lang_en');
|
|
31
|
+
res.locals.socketUrl = process.env.APP_URL;
|
|
32
|
+
res.locals.zcompanies = [];
|
|
33
|
+
res.locals.isLogin = false;
|
|
34
|
+
res.locals.objectStores = {};
|
|
35
|
+
res.locals.MENU = [];
|
|
36
|
+
res.locals.MENU_SYSTEMS = [];
|
|
37
|
+
res.locals.MENU_ALL = [];
|
|
38
|
+
if (req.session) {
|
|
39
|
+
let reqSession = req.session;
|
|
40
|
+
if (reqSession.hasOwnProperty('user')) {
|
|
41
|
+
const tUser = req.session.user;
|
|
42
|
+
if (tUser && Object.prototype.hasOwnProperty.call(tUser, "id")) {
|
|
43
|
+
tUser.role = {
|
|
44
|
+
name: "Admin"
|
|
25
45
|
};
|
|
26
|
-
res.locals.
|
|
27
|
-
res.locals.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
res.locals.
|
|
31
|
-
res.locals.
|
|
32
|
-
res.locals.
|
|
33
|
-
res.locals.
|
|
34
|
-
res.locals.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
name: "Admin"
|
|
44
|
-
};
|
|
45
|
-
res.locals.isLogin = true;
|
|
46
|
-
res.locals.token = tUser.token;
|
|
47
|
-
res.locals.roleId = tUser.role_id;
|
|
48
|
-
res.locals.isLogin = true;
|
|
49
|
-
res.locals.zuser = tUser;
|
|
50
|
-
res.locals.userId = tUser.id;
|
|
51
|
-
res.locals.companyId = tUser.company.id;
|
|
52
|
-
res.locals.userAvatar = tUser.image ? tUser.image.indexOf("http") > -1 ? tUser.image : "/uploads/zuser/" + tUser.image : "/img/user.png";
|
|
53
|
-
res.locals.zcompanies = tUser.companies;
|
|
54
|
-
if(tUser.language){
|
|
55
|
-
let objLanguage = {
|
|
56
|
-
1 : "lang_en",
|
|
57
|
-
2 : "lang_id",
|
|
58
|
-
3 : "lang_jp",
|
|
59
|
-
4 : "lang_fr"
|
|
60
|
-
};
|
|
61
|
-
global.LANGUAGE = require(`./languages/${objLanguage[tUser.language]}`);
|
|
62
|
-
}
|
|
63
|
-
global.layout = "two";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
res.locals.MENU = menuGenerator.menu(req, res);
|
|
67
|
-
res.locals.MENU_SYSTEMS = menuGenerator.systems(req, res);
|
|
68
|
-
res.locals.MENU_ALL = menuGenerator.menuPlus(req, res);
|
|
46
|
+
res.locals.isLogin = true;
|
|
47
|
+
res.locals.token = tUser.token;
|
|
48
|
+
res.locals.roleId = tUser.role_id;
|
|
49
|
+
res.locals.isLogin = true;
|
|
50
|
+
res.locals.zuser = tUser;
|
|
51
|
+
res.locals.userId = tUser.id;
|
|
52
|
+
res.locals.companyId = tUser.company.id;
|
|
53
|
+
res.locals.userAvatar = tUser.image ? tUser.image.indexOf("http") > -1 ? tUser.image : "/uploads/zuser/" + tUser.image : "/img/user.png";
|
|
54
|
+
res.locals.zcompanies = tUser.companies;
|
|
55
|
+
if(tUser.language){
|
|
56
|
+
let objLanguage = {
|
|
57
|
+
1 : "lang_en",
|
|
58
|
+
2 : "lang_id",
|
|
59
|
+
3 : "lang_jp",
|
|
60
|
+
4 : "lang_fr"
|
|
61
|
+
};
|
|
62
|
+
global.LANGUAGE = require(`./languages/${objLanguage[tUser.language]}`);
|
|
69
63
|
}
|
|
70
|
-
global.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
global.layout = "two";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
res.locals.MENU = menuGenerator.menu(req, res);
|
|
68
|
+
res.locals.MENU_SYSTEMS = menuGenerator.systems(req, res);
|
|
69
|
+
res.locals.MENU_ALL = menuGenerator.menuPlus(req, res);
|
|
70
|
+
}
|
|
71
|
+
global.COMPANY_ID = res.locals.companyId;
|
|
72
|
+
global.USER_ID = res.locals.userId;
|
|
73
|
+
res.locals.LANGUAGE = global.LANGUAGE;
|
|
74
|
+
res.locals.currency = {};
|
|
75
|
+
res.locals.settings = {};
|
|
76
|
+
res.locals.sessionFlash = req.session.sessionFlash;
|
|
77
|
+
delete req.session.sessionFlash;
|
|
78
|
+
res.locals.sessionFlashc = req.session.sessionFlashc;
|
|
79
|
+
next();
|
|
79
80
|
};
|