@saltcorn/server 0.7.3-beta.6 → 0.7.4-beta.0
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/auth/admin.js +9 -5
- package/auth/routes.js +19 -9
- package/errors.js +51 -48
- package/locales/en.json +12 -1
- package/locales/zh.json +187 -187
- package/markup/admin.js +4 -3
- package/package.json +7 -7
- package/public/jquery-menu-editor.min.js +11 -1
- package/public/saltcorn-common.js +26 -10
- package/public/saltcorn.css +17 -0
- package/public/saltcorn.js +5 -1
- package/routes/admin.js +296 -23
- package/routes/api.js +9 -1
- package/routes/eventlog.js +24 -22
- package/routes/files.js +5 -5
- package/routes/infoarch.js +6 -3
- package/routes/page.js +5 -1
- package/routes/pageedit.js +9 -1
- package/routes/plugins.js +77 -11
- package/routes/search.js +4 -2
- package/routes/tables.js +4 -3
- package/routes/tenant.js +4 -2
- package/routes/utils.js +4 -0
- package/routes/view.js +18 -1
- package/routes/viewedit.js +16 -3
- package/serve.js +54 -38
- package/tests/api.test.js +17 -0
- package/tests/clientjs.test.js +11 -1
package/auth/admin.js
CHANGED
|
@@ -381,7 +381,8 @@ router.post(
|
|
|
381
381
|
} else {
|
|
382
382
|
await save_config_from_form(form);
|
|
383
383
|
req.flash("success", req.__("User settings updated"));
|
|
384
|
-
res.redirect("/useradmin/settings");
|
|
384
|
+
if (!req.xhr) res.redirect("/useradmin/settings");
|
|
385
|
+
else res.json({ success: "ok" });
|
|
385
386
|
}
|
|
386
387
|
})
|
|
387
388
|
);
|
|
@@ -530,7 +531,7 @@ router.get(
|
|
|
530
531
|
send_users_page({
|
|
531
532
|
res,
|
|
532
533
|
req,
|
|
533
|
-
active_sub: "
|
|
534
|
+
active_sub: "SSL",
|
|
534
535
|
contents: {
|
|
535
536
|
type: "card",
|
|
536
537
|
title: req.__("Authentication settings"),
|
|
@@ -556,7 +557,7 @@ router.post(
|
|
|
556
557
|
send_users_page({
|
|
557
558
|
res,
|
|
558
559
|
req,
|
|
559
|
-
active_sub: "
|
|
560
|
+
active_sub: "SSL",
|
|
560
561
|
contents: {
|
|
561
562
|
type: "card",
|
|
562
563
|
title: req.__("Authentication settings"),
|
|
@@ -572,7 +573,9 @@ router.post(
|
|
|
572
573
|
" " +
|
|
573
574
|
a({ href: "/admin/system" }, req.__("Restart here"))
|
|
574
575
|
);
|
|
575
|
-
|
|
576
|
+
if (!req.xhr) {
|
|
577
|
+
res.redirect("/useradmin/ssl");
|
|
578
|
+
} else res.json({ success: "ok" });
|
|
576
579
|
}
|
|
577
580
|
})
|
|
578
581
|
);
|
|
@@ -690,7 +693,8 @@ router.post(
|
|
|
690
693
|
} = form.values;
|
|
691
694
|
if (id) {
|
|
692
695
|
try {
|
|
693
|
-
await
|
|
696
|
+
const u = await User.findOne({ id });
|
|
697
|
+
await u.update({ email, role_id, ...rest });
|
|
694
698
|
req.flash("success", req.__(`User %s saved`, email));
|
|
695
699
|
} catch (e) {
|
|
696
700
|
req.flash("error", req.__(`Error editing user: %s`, e.message));
|
package/auth/routes.js
CHANGED
|
@@ -199,24 +199,33 @@ const getAuthLinks = (current, noMethods) => {
|
|
|
199
199
|
return links;
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
-
const loginWithJwt = async (
|
|
203
|
-
const { email, password } = req.query;
|
|
202
|
+
const loginWithJwt = async (email, password, res) => {
|
|
204
203
|
const user = await User.findOne({ email });
|
|
205
204
|
if (user && user.checkPassword(password)) {
|
|
206
|
-
const now = new Date()
|
|
205
|
+
const now = new Date();
|
|
207
206
|
const jwt_secret = db.connectObj.jwt_secret;
|
|
208
207
|
const token = jwt.sign(
|
|
209
208
|
{
|
|
210
209
|
sub: email,
|
|
211
|
-
|
|
210
|
+
user: {
|
|
211
|
+
id: user.id,
|
|
212
|
+
email: user.email,
|
|
213
|
+
role_id: user.role_id,
|
|
214
|
+
language: user.language ? user.language : "en",
|
|
215
|
+
disabled: user.disabled,
|
|
216
|
+
},
|
|
212
217
|
iss: "saltcorn@saltcorn",
|
|
213
218
|
aud: "saltcorn-mobile-app",
|
|
214
|
-
iat: now,
|
|
219
|
+
iat: now.valueOf(),
|
|
215
220
|
},
|
|
216
221
|
jwt_secret
|
|
217
222
|
);
|
|
218
|
-
if (!user.last_mobile_login) user.updateLastMobileLogin(now);
|
|
223
|
+
if (!user.last_mobile_login) await user.updateLastMobileLogin(now);
|
|
219
224
|
res.json(token);
|
|
225
|
+
} else {
|
|
226
|
+
res.json({
|
|
227
|
+
alerts: [{ type: "danger", msg: "Incorrect user or password" }],
|
|
228
|
+
});
|
|
220
229
|
}
|
|
221
230
|
};
|
|
222
231
|
|
|
@@ -900,8 +909,8 @@ router.post(
|
|
|
900
909
|
} else {
|
|
901
910
|
const u = await User.create({ email, password });
|
|
902
911
|
await send_verification_email(u, req);
|
|
903
|
-
|
|
904
|
-
signup_login_with_user(u, req, res);
|
|
912
|
+
if (req.smr) await loginWithJwt(email, password, res);
|
|
913
|
+
else signup_login_with_user(u, req, res);
|
|
905
914
|
}
|
|
906
915
|
}
|
|
907
916
|
})
|
|
@@ -1008,7 +1017,8 @@ router.get(
|
|
|
1008
1017
|
error_catcher(async (req, res, next) => {
|
|
1009
1018
|
const { method } = req.params;
|
|
1010
1019
|
if (method === "jwt") {
|
|
1011
|
-
|
|
1020
|
+
const { email, password } = req.query;
|
|
1021
|
+
await loginWithJwt(email, password, res);
|
|
1012
1022
|
} else {
|
|
1013
1023
|
const auth = getState().auth_methods[method];
|
|
1014
1024
|
if (auth) {
|
package/errors.js
CHANGED
|
@@ -7,55 +7,58 @@ const { pre, p, text, h3 } = require("@saltcorn/markup/tags");
|
|
|
7
7
|
const Crash = require("@saltcorn/data/models/crash");
|
|
8
8
|
const { getState } = require("@saltcorn/data/db/state");
|
|
9
9
|
|
|
10
|
-
module.exports =
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
async function (err, req, res, next) {
|
|
20
|
-
|
|
10
|
+
module.exports =
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {object} err
|
|
14
|
+
* @param {object} req
|
|
15
|
+
* @param {object} res
|
|
16
|
+
* @param {*} next
|
|
17
|
+
* @returns {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
async function (err, req, res, next) {
|
|
20
|
+
if (!req.__) req.__ = (s) => s;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const devmode = getState().getConfig("development_mode", false);
|
|
23
|
+
const log_sql = getState().getConfig("log_sql", false);
|
|
24
|
+
const role = (req.user || {}).role_id || 10;
|
|
25
|
+
if (err.message && err.message.includes("invalid csrf token")) {
|
|
26
|
+
console.error(err.message);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
req.flash("error", req.__("Invalid form data, try again"));
|
|
29
|
+
if (req.url && req.url.includes("/auth/login"))
|
|
30
|
+
res.redirect("/auth/login");
|
|
31
|
+
else res.redirect("/");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const code = err.httpCode || 500;
|
|
35
|
+
const headline = err.headline || "An error occurred";
|
|
36
|
+
const severity = err.severity || 2;
|
|
37
|
+
const createCrash = severity <= 3;
|
|
38
|
+
//console.error(err.stack);
|
|
39
|
+
if (!(devmode && log_sql) && createCrash) await Crash.create(err, req);
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
?
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
if (req.xhr) {
|
|
42
|
+
res
|
|
43
|
+
.status(code)
|
|
44
|
+
.send(
|
|
45
|
+
devmode || role === 1
|
|
46
|
+
? text(err.message)
|
|
47
|
+
: req.__("An error occurred")
|
|
48
|
+
);
|
|
49
|
+
} else
|
|
50
|
+
res
|
|
51
|
+
.status(code)
|
|
52
|
+
.sendWrap(
|
|
53
|
+
req.__(headline),
|
|
54
|
+
devmode ? pre(text(err.stack)) : h3(req.__(headline)),
|
|
55
|
+
role === 1 && !devmode ? pre(text(err.message)) : "",
|
|
56
|
+
createCrash
|
|
57
|
+
? p(
|
|
58
|
+
req.__(
|
|
59
|
+
`A report has been logged and a team of bug-squashing squirrels has been dispatched to deal with the situation.`
|
|
60
|
+
)
|
|
57
61
|
)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
+
: ""
|
|
63
|
+
);
|
|
64
|
+
};
|
package/locales/en.json
CHANGED
|
@@ -919,5 +919,16 @@
|
|
|
919
919
|
"Build Result": "Build Result",
|
|
920
920
|
"Download automated backup": "Download automated backup",
|
|
921
921
|
"Restoring automated backup": "Restoring automated backup",
|
|
922
|
-
"No errors detected during configuration check": "No errors detected during configuration check"
|
|
922
|
+
"No errors detected during configuration check": "No errors detected during configuration check",
|
|
923
|
+
"%s view - %s on %s": "%s view - %s on %s",
|
|
924
|
+
"Please select at least one platform (android or iOS).": "Please select at least one platform (android or iOS).",
|
|
925
|
+
"Back": "Back",
|
|
926
|
+
"Periodic snapshots enabled": "Periodic snapshots enabled",
|
|
927
|
+
"Snapshot will be made every hour if there are changes": "Snapshot will be made every hour if there are changes",
|
|
928
|
+
"Snapshots": "Snapshots",
|
|
929
|
+
"Snapshot settings updated": "Snapshot settings updated",
|
|
930
|
+
"Download snapshots": "Download snapshots",
|
|
931
|
+
"Snapshot successful": "Snapshot successful",
|
|
932
|
+
"System logging verbosity": "System logging verbosity",
|
|
933
|
+
"Destination URL Formula": "Destination URL Formula"
|
|
923
934
|
}
|