zet-lib 1.3.41 → 1.3.42

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/zTester.js CHANGED
@@ -1,93 +1,93 @@
1
- const connection = require('./connection');
2
- const Util = require("./Util");
3
- const moment = require('moment');
4
- const zRoute = require('./zRoute');
5
- const io = require("./io");
6
- const fs = require("fs");
7
- const qs = require('qs');
8
- const axios = require('axios');
9
- const nodemailer = require('nodemailer')
10
- const myCache = require("./cache");
11
- const moduleLib = require("./moduleLib");
12
- const cForm = require("./Form");
13
- const zFunction = require("./zFunction");
14
- const zCache = require("./zCache");
15
- require('dotenv').config();
16
-
17
- const zTester = {}
18
-
19
- zTester.page = async(req,res,scripts) => {
20
- const MYMODELS = zRoute.MYMODELS();
21
- let csrf = req.csrfToken();
22
- let email = req.query.email || "";
23
- let json = {
24
- error:false,
25
- status : 1,
26
- message:"Success"
27
- };
28
- let stringParams = "";
29
- let CALL = {
30
- req:req,
31
- res:res,
32
- Util: Util,
33
- connection: connection,
34
- fs: fs,
35
- io: io,
36
- qs: qs,
37
- moment:moment,
38
- myCache:myCache,
39
- moduleLib:moduleLib,
40
- zRoute:zRoute,
41
- zCache:zCache,
42
- zFunction:zFunction,
43
- MYMODELS:MYMODELS,
44
- renderData:{},
45
- emptyFn : function () {}
46
- };
47
-
48
- var arr = ['res.json','res.send'];
49
- var newScript = '';
50
- for(var i = 0; i < arr.length; i++) {
51
- scripts = Util.replaceAll(scripts,arr[i],'emptyFn');
52
- }
53
-
54
- scripts += `
55
- return 1`;
56
- stringParams = "";
57
- for (var keys in CALL) {
58
- stringParams += `var ${keys} = this.${keys};`
59
- }
60
- const AsyncFunction = Object.getPrototypeOf(async function () {
61
- }).constructor;
62
-
63
- return new Promise(async function (resolve, reject) {
64
- try {
65
- var t = AsyncFunction(`
66
- ${stringParams};
67
- ${scripts};
68
- `).call(CALL);
69
- let me = await t;
70
- if(me == 1) {
71
- resolve({
72
- error:false,
73
- status : 1,
74
- message:"Success"
75
- })
76
- } else {
77
- resolve({
78
- error:true,
79
- status : 0,
80
- message:"Error"
81
- })
82
- }
83
- } catch (e) {
84
- resolve({
85
- error:true,
86
- status : 0,
87
- message:e.toString()
88
- })
89
- }
90
- })
91
- }
92
-
93
- module.exports = zTester;
1
+ const connection = require('./connection');
2
+ const Util = require("./Util");
3
+ const moment = require('moment');
4
+ const zRoute = require('./zRoute');
5
+ const io = require("./io");
6
+ const fs = require("fs");
7
+ const qs = require('qs');
8
+ const axios = require('axios');
9
+ const nodemailer = require('nodemailer')
10
+ const myCache = require("./cache");
11
+ const moduleLib = require("./moduleLib");
12
+ const cForm = require("./Form");
13
+ const zFunction = require("./zFunction");
14
+ const zCache = require("./zCache");
15
+ require('dotenv').config();
16
+
17
+ const zTester = {}
18
+
19
+ zTester.page = async(req,res,scripts) => {
20
+ const MYMODELS = zRoute.MYMODELS();
21
+ let csrf = req.csrfToken();
22
+ let email = req.query.email || "";
23
+ let json = {
24
+ error:false,
25
+ status : 1,
26
+ message:"Success"
27
+ };
28
+ let stringParams = "";
29
+ let CALL = {
30
+ req:req,
31
+ res:res,
32
+ Util: Util,
33
+ connection: connection,
34
+ fs: fs,
35
+ io: io,
36
+ qs: qs,
37
+ moment:moment,
38
+ myCache:myCache,
39
+ moduleLib:moduleLib,
40
+ zRoute:zRoute,
41
+ zCache:zCache,
42
+ zFunction:zFunction,
43
+ MYMODELS:MYMODELS,
44
+ renderData:{},
45
+ emptyFn : function () {}
46
+ };
47
+
48
+ var arr = ['res.json','res.send'];
49
+ var newScript = '';
50
+ for(var i = 0; i < arr.length; i++) {
51
+ scripts = Util.replaceAll(scripts,arr[i],'emptyFn');
52
+ }
53
+
54
+ scripts += `
55
+ return 1`;
56
+ stringParams = "";
57
+ for (var keys in CALL) {
58
+ stringParams += `var ${keys} = this.${keys};`
59
+ }
60
+ const AsyncFunction = Object.getPrototypeOf(async function () {
61
+ }).constructor;
62
+
63
+ return new Promise(async function (resolve, reject) {
64
+ try {
65
+ var t = AsyncFunction(`
66
+ ${stringParams};
67
+ ${scripts};
68
+ `).call(CALL);
69
+ let me = await t;
70
+ if(me == 1) {
71
+ resolve({
72
+ error:false,
73
+ status : 1,
74
+ message:"Success"
75
+ })
76
+ } else {
77
+ resolve({
78
+ error:true,
79
+ status : 0,
80
+ message:"Error"
81
+ })
82
+ }
83
+ } catch (e) {
84
+ resolve({
85
+ error:true,
86
+ status : 0,
87
+ message:e.toString()
88
+ })
89
+ }
90
+ })
91
+ }
92
+
93
+ module.exports = zTester;
package/lib/zapp.js CHANGED
@@ -1,65 +1,65 @@
1
- module.exports = (req,res,next) => {
2
- res.locals.renderHead = "";
3
- res.locals.renderBody = "";
4
- res.locals.renderEnd = "";
5
- res.locals.headHTML = '';
6
- res.locals.bodyHTML = '';
7
- res.locals.endHTML = '';
8
- res.locals.titleApp = process.env.APP_TITLE;
9
- res.locals.descriptionApp = process.env.APP_DESCRIPTION;
10
- res.locals.moduleHead = "";
11
- res.locals.relationsVariable = "";
12
- res.locals.moduleEnd = "";
13
- res.locals.menuApp = "home";
14
- res.locals.routeName = "index";
15
- res.locals.userId = -1;
16
- res.locals.csrfToken = "";
17
- res.locals.roleId = 0;
18
- res.locals.token = "guest";
19
- res.locals.companyId = 0;
20
- res.locals.userId = 0;
21
- res.locals.userAvatar = "/img/user.png";
22
- res.locals.zuser = {
23
- fullname: 'test'
24
- };
25
- res.locals.frameworkcss = "bootstrap5";
26
- res.locals.startup = 0;
27
- global.frameworkcss = "bootstrap5";
28
- global.LANGUAGE = require('./languages/lang_en');
29
- res.locals.socketUrl = process.env.APP_URL;
30
- res.locals.zcompanies = [];
31
- res.locals.isLogin = false;
32
- res.locals.objectStores = {};
33
- if (req.session) {
34
- let reqSession = req.session;
35
- if (reqSession.hasOwnProperty('user')) {
36
- const tUser = req.session.user;
37
- if (tUser && Object.prototype.hasOwnProperty.call(tUser, "id")) {
38
- res.locals.isLogin = true;
39
- res.locals.token = tUser.token;
40
- res.locals.roleId = tUser.role_id;
41
- res.locals.isLogin = true;
42
- res.locals.zuser = tUser;
43
- res.locals.userId = tUser.id;
44
- res.locals.companyId = tUser.company.id;
45
- res.locals.userAvatar = tUser.image ? tUser.image.indexOf("http") > -1 ? tUser.image : "/uploads/zuser/" + tUser.image : "/img/user.png";
46
- res.locals.zcompanies = tUser.companies;
47
- if(tUser.language){
48
- let objLanguage = {
49
- 1 : "lang_en",
50
- 2 : "lang_id",
51
- 3 : "lang_jp",
52
- 4 : "lang_fr"
53
- };
54
- global.LANGUAGE = require(`./languages/${objLanguage[tUser.language]}`);
55
- }
56
- global.layout = "two";
57
- }
58
- }
59
- }
60
- global.COMPANY_ID = res.locals.companyId;
61
- global.USER_ID = res.locals.userId;
62
- res.locals.LANGUAGE = global.LANGUAGE;
63
-
64
- next();
65
- };
1
+ module.exports = (req,res,next) => {
2
+ res.locals.renderHead = "";
3
+ res.locals.renderBody = "";
4
+ res.locals.renderEnd = "";
5
+ res.locals.headHTML = '';
6
+ res.locals.bodyHTML = '';
7
+ res.locals.endHTML = '';
8
+ res.locals.titleApp = process.env.APP_TITLE;
9
+ res.locals.descriptionApp = process.env.APP_DESCRIPTION;
10
+ res.locals.moduleHead = "";
11
+ res.locals.relationsVariable = "";
12
+ res.locals.moduleEnd = "";
13
+ res.locals.menuApp = "home";
14
+ res.locals.routeName = "index";
15
+ res.locals.userId = -1;
16
+ res.locals.csrfToken = "";
17
+ res.locals.roleId = 0;
18
+ res.locals.token = "guest";
19
+ res.locals.companyId = 0;
20
+ res.locals.userId = 0;
21
+ res.locals.userAvatar = "/img/user.png";
22
+ res.locals.zuser = {
23
+ fullname: 'test'
24
+ };
25
+ res.locals.frameworkcss = "bootstrap5";
26
+ res.locals.startup = 0;
27
+ global.frameworkcss = "bootstrap5";
28
+ global.LANGUAGE = require('./languages/lang_en');
29
+ res.locals.socketUrl = process.env.APP_URL;
30
+ res.locals.zcompanies = [];
31
+ res.locals.isLogin = false;
32
+ res.locals.objectStores = {};
33
+ if (req.session) {
34
+ let reqSession = req.session;
35
+ if (reqSession.hasOwnProperty('user')) {
36
+ const tUser = req.session.user;
37
+ if (tUser && Object.prototype.hasOwnProperty.call(tUser, "id")) {
38
+ res.locals.isLogin = true;
39
+ res.locals.token = tUser.token;
40
+ res.locals.roleId = tUser.role_id;
41
+ res.locals.isLogin = true;
42
+ res.locals.zuser = tUser;
43
+ res.locals.userId = tUser.id;
44
+ res.locals.companyId = tUser.company.id;
45
+ res.locals.userAvatar = tUser.image ? tUser.image.indexOf("http") > -1 ? tUser.image : "/uploads/zuser/" + tUser.image : "/img/user.png";
46
+ res.locals.zcompanies = tUser.companies;
47
+ if(tUser.language){
48
+ let objLanguage = {
49
+ 1 : "lang_en",
50
+ 2 : "lang_id",
51
+ 3 : "lang_jp",
52
+ 4 : "lang_fr"
53
+ };
54
+ global.LANGUAGE = require(`./languages/${objLanguage[tUser.language]}`);
55
+ }
56
+ global.layout = "two";
57
+ }
58
+ }
59
+ }
60
+ global.COMPANY_ID = res.locals.companyId;
61
+ global.USER_ID = res.locals.userId;
62
+ res.locals.LANGUAGE = global.LANGUAGE;
63
+
64
+ next();
65
+ };