@saltcorn/server 0.7.3-beta.3 → 0.7.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/app.js CHANGED
@@ -227,7 +227,11 @@ const getApp = async (opts = {}) => {
227
227
  passport.use(
228
228
  new JwtStrategy(jwtOpts, (jwt_payload, done) => {
229
229
  User.findOne({ email: jwt_payload.sub }).then((u) => {
230
- if (u) {
230
+ if (
231
+ u &&
232
+ u.last_mobile_login &&
233
+ u.last_mobile_login <= jwt_payload.iat
234
+ ) {
231
235
  return done(null, {
232
236
  email: u.email,
233
237
  id: u.id,
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: "Settings",
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: "Settings",
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
- res.redirect("/useradmin/ssl");
576
+ if (!req.xhr) {
577
+ res.redirect("/useradmin/ssl");
578
+ } else res.json({ success: "ok" });
576
579
  }
577
580
  })
578
581
  );
package/auth/routes.js CHANGED
@@ -203,6 +203,7 @@ const loginWithJwt = async (req, res) => {
203
203
  const { email, password } = req.query;
204
204
  const user = await User.findOne({ email });
205
205
  if (user && user.checkPassword(password)) {
206
+ const now = new Date();
206
207
  const jwt_secret = db.connectObj.jwt_secret;
207
208
  const token = jwt.sign(
208
209
  {
@@ -210,9 +211,11 @@ const loginWithJwt = async (req, res) => {
210
211
  role_id: user.role_id,
211
212
  iss: "saltcorn@saltcorn",
212
213
  aud: "saltcorn-mobile-app",
214
+ iat: now.valueOf(),
213
215
  },
214
216
  jwt_secret
215
217
  );
218
+ if (!user.last_mobile_login) await user.updateLastMobileLogin(now);
216
219
  res.json(token);
217
220
  }
218
221
  };
@@ -249,18 +252,24 @@ router.get(
249
252
  * @function
250
253
  * @memberof module:auth/routes~routesRouter
251
254
  */
252
- router.get("/logout", (req, res, next) => {
253
- req.logout();
254
- if (req.session.destroy)
255
- req.session.destroy((err) => {
256
- if (err) return next(err);
255
+ router.get("/logout", async (req, res, next) => {
256
+ if (req.smr && req.user?.id) {
257
+ const user = await User.findOne({ id: req.user.id });
258
+ await user.updateLastMobileLogin(null);
259
+ res.json({ success: true });
260
+ } else if (req.logout) {
261
+ req.logout();
262
+ if (req.session.destroy)
263
+ req.session.destroy((err) => {
264
+ if (err) return next(err);
265
+ req.logout();
266
+ res.redirect("/auth/login");
267
+ });
268
+ else {
257
269
  req.logout();
270
+ req.session = null;
258
271
  res.redirect("/auth/login");
259
- });
260
- else {
261
- req.logout();
262
- req.session = null;
263
- res.redirect("/auth/login");
272
+ }
264
273
  }
265
274
  });
266
275
 
@@ -978,6 +987,11 @@ router.post(
978
987
  }
979
988
  Trigger.emitEvent("Login", null, req.user);
980
989
  req.flash("success", req.__("Welcome, %s!", req.user.email));
990
+ if (req.smr) {
991
+ const dbUser = await User.findOne({ id: req.user.id });
992
+ if (!dbUser.last_mobile_login)
993
+ await dbUser.updateLastMobileLogin(new Date());
994
+ }
981
995
  if (getState().get2FApolicy(req.user) === "Mandatory") {
982
996
  res.redirect("/auth/twofa/setup/totp");
983
997
  } else res.redirect("/");
@@ -1010,6 +1024,17 @@ router.get(
1010
1024
  })
1011
1025
  );
1012
1026
 
1027
+ /*
1028
+ returns if 'req.user' is an authenticated user
1029
+ */
1030
+ router.get(
1031
+ "/authenticated",
1032
+ error_catcher((req, res, next) => {
1033
+ const isAuth = req.user && req.user.id ? true : false;
1034
+ res.json({ authenticated: isAuth });
1035
+ })
1036
+ );
1037
+
1013
1038
  /**
1014
1039
  * @name post/login-with/:method
1015
1040
  * @function
@@ -1195,6 +1220,7 @@ const userSettings = async ({ req, res, pwform, user }) => {
1195
1220
  ? [
1196
1221
  {
1197
1222
  type: "card",
1223
+ class: "mt-0",
1198
1224
  title: userSetsName,
1199
1225
  contents: usersets,
1200
1226
  },
@@ -1203,6 +1229,7 @@ const userSettings = async ({ req, res, pwform, user }) => {
1203
1229
  {
1204
1230
  type: "card",
1205
1231
  title: req.__("User"),
1232
+ class: !usersets && "mt-0",
1206
1233
  contents: table(
1207
1234
  tbody(
1208
1235
  tr(
package/locales/en.json CHANGED
@@ -916,5 +916,10 @@
916
916
  "Delete old backup files in this directory after the set number of days": "Delete old backup files in this directory after the set number of days",
917
917
  "Mobile app": "Mobile app",
918
918
  "Build mobile app": "Build mobile app",
919
- "Build Result": "Build Result"
919
+ "Build Result": "Build Result",
920
+ "Download automated backup": "Download automated backup",
921
+ "Restoring automated backup": "Restoring automated backup",
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
+ "Back": "Back"
920
925
  }