notherbase-fs 2.0.2 → 3.0.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.
Files changed (59) hide show
  1. package/controllers/creation.js +57 -59
  2. package/controllers/spirit-world.js +55 -72
  3. package/controllers/spirits/contact.js +17 -10
  4. package/controllers/spirits/user.js +144 -112
  5. package/controllers/spirits/util.js +23 -31
  6. package/models/index.js +54 -117
  7. package/models/item.js +80 -0
  8. package/models/send-mail.js +2 -0
  9. package/models/spirit.js +77 -115
  10. package/models/user.js +189 -0
  11. package/notherbase-fs.js +1 -0
  12. package/package.json +1 -1
  13. package/public/styles/main.css +12 -3
  14. package/test/{explorer/coast/tall-beach/nono-cove/styles → coast/tall-beach/nono-cove}/index.css +0 -0
  15. package/test/coast/tall-beach/nono-cove/index.ejs +29 -0
  16. package/test/{explorer/coast/tall-beach/nono-cove/views/nono-og.ejs → coast/tall-beach/nono-cove/nono-og/index.ejs} +2 -2
  17. package/test/{explorer/coast/tall-beach/nono-cove/styles → coast/tall-beach/nono-cove/nono-og}/nono.css +0 -0
  18. package/test/{explorer/coast/tall-beach/nono-cove/local-scripts → coast/tall-beach/nono-cove/nono-og}/nono.js +1 -1
  19. package/test/{explorer/coast/tall-beach/nono-cove/server-scripts → test-page}/emailTime.js +0 -0
  20. package/test/{pages/test.ejs → test-page/index.ejs} +0 -0
  21. package/test/the-front/add-gold.js +35 -0
  22. package/test/the-front/check/add-more-gold.js +3 -0
  23. package/test/the-front/check/emailTime.js +11 -0
  24. package/test/the-front/check/index.ejs +13 -0
  25. package/test/the-front/check/subtract-gold.js +3 -0
  26. package/test/the-front/checks.js +11 -0
  27. package/test/the-front/incTranslation.js +9 -0
  28. package/test/the-front/index.ejs +107 -0
  29. package/test/void/index.ejs +4 -0
  30. package/test/void/void.css +3 -0
  31. package/views/explorer.ejs +32 -41
  32. package/views/menu/account.ejs +39 -0
  33. package/views/menu/inventory.ejs +8 -0
  34. package/views/menu/more.ejs +5 -0
  35. package/views/menu/player.ejs +3 -0
  36. package/views/menu.ejs +20 -62
  37. package/views/scripts/base.js +314 -0
  38. package/controllers/spirits/attribute.js +0 -47
  39. package/controllers/spirits/inventory.js +0 -71
  40. package/controllers/spirits/item.js +0 -41
  41. package/controllers/spirits/serve.js +0 -33
  42. package/public/js/commune.js +0 -22
  43. package/public/js/establishment.js +0 -44
  44. package/public/js/memories.js +0 -44
  45. package/test/explorer/coast/tall-beach/nono-cove/local-scripts/game.js +0 -7
  46. package/test/explorer/coast/tall-beach/nono-cove/local-scripts/items.js +0 -162
  47. package/test/explorer/coast/tall-beach/nono-cove/server-scripts/getTimer.js +0 -31
  48. package/test/explorer/coast/tall-beach/nono-cove/styles/items-floor.css +0 -92
  49. package/test/explorer/coast/tall-beach/nono-cove/views/index.ejs +0 -130
  50. package/test/pages/server-scripts/emailTime.js +0 -15
  51. package/test/the-front/server-scripts/emailTime.js +0 -15
  52. package/test/the-front/server-scripts/getTimer.js +0 -31
  53. package/test/the-front/views/check.ejs +0 -93
  54. package/test/the-front/views/index.ejs +0 -113
  55. package/test/void/styles/void.css +0 -0
  56. package/views/account.ejs +0 -122
  57. package/views/inventory.ejs +0 -117
  58. package/views/more.ejs +0 -16
  59. package/views/player.ejs +0 -60
@@ -5,30 +5,75 @@ export default class Creation {
5
5
  constructor() {
6
6
  this.router = express.Router();
7
7
 
8
+ //home
8
9
  this.router.get("/", function(req, res) { res.redirect("/the-front"); });
9
- this.router.get(`/the-front`, this.front);
10
- this.router.get(`/the-front/:detail`, this.frontDetail);
11
- this.router.get(`/:page`, this.page);
12
- this.router.get(`/:region/:area/:poi`, this.poi);
13
- this.router.get(`/:region/:area/:poi/:detail`, this.detail);
14
- this.router.use(this.void);
10
+ //the-front
11
+ this.router.get(`/the-front`, this.explore);
12
+ this.router.get(`/the-front/:frontDetail`, this.explore);
13
+ //pages
14
+ this.router.get(`/:page`, this.explore);
15
+ //explorer
16
+ this.router.get(`/:region/:area/:poi`, this.lock, this.explore);
17
+ this.router.get(`/:region/:area/:poi/:detail`, this.lock, this.explore);
18
+ //void
19
+ this.router.use(function(req, res) {
20
+ console.log(req.path);
21
+ res.redirect("/void");
22
+ });
23
+ }
24
+
25
+ lock = (req, res, next) => {
26
+ req.lock = true;
27
+ next();
15
28
  }
16
29
 
17
- explore = async (main, siteTitle, reqUser, req, res, next) => {
30
+ explore = async (req, res, next) => {
31
+ let main = `${req.contentPath}`;
32
+ let siteTitle = `NotherBase - `;
33
+
34
+ if (req.params.frontDetail) {
35
+ main += `/the-front/${req.params.frontDetail}/index`;
36
+ siteTitle += req.params.frontDetail;
37
+ }
38
+ else if (req.params.detail) {
39
+ main += `/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/index`;
40
+ siteTitle += req.params.detail;
41
+ }
42
+ else if (req.params.poi) {
43
+ main += `/${req.params.region}/${req.params.area}/${req.params.poi}/index`;
44
+ siteTitle += req.params.poi;
45
+ }
46
+ else if (req.params.page) {
47
+ main += `/${req.params.page}/index`;
48
+ siteTitle = req.params.page;
49
+ }
50
+ else {
51
+ main += `/the-front/index`;
52
+ siteTitle += "the-front";
53
+ }
54
+
18
55
  try {
19
56
  if (fs.existsSync(main + ".ejs")) {
20
- let user = new req.db.User("user", req.session.currentUser);
21
- let userData = await user.recall();
57
+ let user = await req.db.User.recallOne(req.session.currentUser);
58
+
59
+ let userStuff = {
60
+ userID: null,
61
+ user: null,
62
+ };
63
+
64
+ if (user) userStuff = {
65
+ userID: user.id,
66
+ user: user.memory.data,
67
+ };
22
68
 
23
69
  let context = {
70
+ ...userStuff,
24
71
  siteTitle: siteTitle,
25
- userID: user._ID,
26
- user: userData,
27
72
  main: main,
28
73
  query: req.query,
29
74
  dir: req.frontDir,
30
75
  route: req.path,
31
- requireUser: reqUser
76
+ requireUser: req.lock
32
77
  }
33
78
 
34
79
  res.render(`explorer`, context);
@@ -40,51 +85,4 @@ export default class Creation {
40
85
  res.status(500).end();
41
86
  }
42
87
  }
43
-
44
- page = async (req, res, next) => {
45
- if (fs.existsSync(`${req.contentPath}/pages/${req.params.page}.ejs`)) {
46
- let user = new req.db.User("user", req.session.currentUser);
47
- let userData = await user.recall();
48
-
49
- res.render(`${req.contentPath}/pages/${req.params.page}.ejs`, {
50
- user: userData,
51
- query: req.query
52
- });
53
- }
54
- else {
55
- next();
56
- }
57
- }
58
-
59
- front = async (req, res, next) => {
60
- let main = `${req.contentPath}/the-front/views/index`;
61
- this.explore(main, `NotherBase - The Front`, false, req, res, next);
62
- }
63
-
64
- frontDetail = async (req, res, next) => {
65
- let main = `${req.contentPath}/the-front/views/${req.params.detail}`;
66
- this.explore(main, `NotherBase - ${req.params.detail}`, false, req, res, next);
67
- }
68
-
69
- poi = async (req, res, next) => {
70
- let main = `${req.contentPath}/explorer${req.path}/views/index`;
71
- this.explore(main, `NotherBase - ${req.params.poi}`, true, req, res, next);
72
- }
73
-
74
- detail = async (req, res, next) => {
75
- let main = `${req.contentPath}/explorer/${req.params.region}/${req.params.area}/${req.params.poi}/views/${req.params.detail}`;
76
- this.explore(main, `NotherBase - ${req.params.detail}`, true, req, res, next);
77
- }
78
-
79
- void = async (req, res) => {
80
- res.render(`explorer`,
81
- {
82
- siteTitle: "NotherBase | The Void",
83
- user: null,
84
- inventory: null,
85
- main: `${req.contentPath}/void/index`,
86
- route: `/void`,
87
- requireUser: false
88
- });
89
- }
90
88
  }
@@ -1,60 +1,12 @@
1
1
  import express from "express";
2
2
  import { stripHtml } from "string-strip-html";
3
- import contact from "./spirits/contact.js";
4
- import inventory from "./spirits/inventory.js";
5
- import item from "./spirits/item.js";
6
- import serve from "./spirits/serve.js";
7
- import attribute from "./spirits/attribute.js";
8
- import user from "./spirits/user.js";
9
- import { check, findUser, loginCheck, success } from "./spirits/util.js";
3
+ import User from "./spirits/user.js";
4
+ import Contact from "./spirits/contact.js";
5
+ import { success, fail } from "./spirits/util.js";
6
+ import fs from 'fs';
10
7
 
11
8
  export default class SpiritWorld {
12
- constructor(io) {
13
- this.io = io;
14
- this.router = express.Router();
15
-
16
- this.router.post(`/`, this.do);
17
-
18
- this.io.on('connection', this.setupChat);
19
-
20
- Object.assign(this, contact);
21
- Object.assign(this, inventory);
22
- Object.assign(this, item);
23
- Object.assign(this, serve);
24
- Object.assign(this, attribute);
25
- Object.assign(this, user);
26
- }
27
-
28
- do = async (req, res) => {
29
- let result = null;
30
-
31
- /* req.body {
32
- action: "getUserBasic",
33
- route: "/something" (opt),
34
- service: "something" (opt),
35
- scope: "local" (opt),
36
- parent: "id" (opt),
37
- _lastUpdate: 0 (opt),
38
- data: {} (opt)
39
- } */
40
-
41
- try {
42
- if (this[req.body.action]) result = await this[req.body.action](req);
43
- else result = {
44
- status: "failed",
45
- message: `No function with the name ${req.body.action}`,
46
- isUpToDate: true,
47
- data: {}
48
- }
49
-
50
- res.send(result);
51
- } catch (error) {
52
- console.log(error);
53
- res.send(error);
54
- }
55
- }
56
-
57
- setupChat = (socket) => {
9
+ #setupChat = (socket) => {
58
10
  socket.join(socket.handshake.query.room);
59
11
 
60
12
  this.io.to(socket.handshake.query.room).emit("chat message", {
@@ -80,31 +32,62 @@ export default class SpiritWorld {
80
32
  });
81
33
  }
82
34
 
83
- recall = async (req) => {
84
- if (req.body.scope === "local") {
85
- loginCheck(req);
86
- let user = await findUser(req);
87
- req.body.parent = user.memory._id;
88
- }
35
+ constructor(io) {
36
+ this.io = io;
37
+ this.router = express.Router();
38
+ this.user = new User();
39
+ this.contact = new Contact();
40
+
41
+ this.router.post("/serve", this.serve);
42
+ this.router.get("/load", this.load);
43
+ this.router.use("/user", this.user.router);
44
+ this.router.use("/contact-nother", this.contact.router);
45
+
46
+ this.io.on('connection', this.#setupChat);
47
+ }
48
+
49
+ load = async (req, res) => {
50
+ let user = await req.db.User.recallOne(req.session.currentUser);
51
+
52
+ let parent = null;
53
+ if (req.query.scope === "local" && user) parent = user.id;
89
54
 
90
- let spirit = new req.db.Spirit(req.body);
91
- let spiritData = await spirit.recall();
55
+ let spirit = await req.db.Spirit.recallOne({
56
+ route: req.query.route,
57
+ service: req.query.service,
58
+ scope: req.query.scope,
59
+ parent: parent
60
+ });
61
+
62
+ if (!spirit) spirit = await req.db.Spirit.create({
63
+ route: req.query.route,
64
+ service: req.query.service,
65
+ scope: req.query.scope,
66
+ parent: parent
67
+ }, {});
92
68
 
93
- check(spiritData, "No spirit found.");
69
+ if (!spirit.memory.data) spirit.memory.data = {};
94
70
 
95
- return success("Spirit found.", spiritData);
71
+ res.send(spirit.memory.data);
96
72
  }
97
73
 
98
- commit = async (req) => {
99
- if (req.body.scope === "local") {
100
- loginCheck(req);
101
- let user = await findUser(req);
102
- req.body.parent = user.memory._id;
103
- }
74
+ serve = async (req, res) => {
75
+ try {
76
+ let scriptPath = `${req.contentPath}${req.body.route}/${req.body.data.script}.js`;
77
+
78
+ let script, result = null;
104
79
 
105
- let spirit = new req.db.Spirit(req.body);
106
- await spirit.commit(req.body.data);
80
+ if (fs.existsSync(scriptPath)) {
81
+ let user = await req.db.User.recallOne(req.session.currentUser);
107
82
 
108
- return success("Spirit updated.");
83
+ script = await import(scriptPath);
84
+ result = await script.default(req, user);
85
+ success(res, "Served.", result);
86
+ }
87
+ else fail(res, `Script not found: ${req.body.data.script} at ${scriptPath}`);
88
+ } catch (error) {
89
+ console.log(error);
90
+ fail(res, "Server error");
91
+ }
109
92
  }
110
93
  }
@@ -1,16 +1,23 @@
1
+ import express from "express";
1
2
  import { success } from "./util.js";
2
3
 
3
- export default {
4
- contactNother: async function(req) {
5
- req.body.service = "contact";
6
- let contact = new req.db.Spirit(req.body);
4
+ export default class Contact {
5
+ constructor() {
6
+ this.router = express.Router();
7
7
 
8
- await contact.commit({
9
- user: req.session.currentUser,
10
- location: req.body.data.route,
11
- content: req.body.data.content
12
- });
8
+ this.router.post(`/`, this.contactNother);
9
+ }
10
+
11
+ contactNother = async function(req, res) {
12
+ let user = await User.recallOne(req.session.currentUser);
13
+
14
+ let spirit = await req.db.Spirit.create({
15
+ route: "/",
16
+ service: "nother-contacts",
17
+ scope: "local",
18
+ parent: user.id
19
+ }, req.body);
13
20
 
14
- return success();
21
+ success(res, "Message sent.");
15
22
  }
16
23
  }
@@ -1,130 +1,162 @@
1
+ import express from "express";
1
2
  import bcrypt from "bcrypt";
2
- import {loginCheck, check, findUser, fail, success} from "./util.js";
3
-
4
- export default {
5
- logout: async (req) => {
6
- loginCheck(req);
3
+ import { check, success, fail, loginCheck } from "./util.js";
4
+
5
+ export default class User {
6
+ constructor() {
7
+ this.router = express.Router();
8
+
9
+ this.router.post("/logout", this.logout);
10
+ this.router.post("/sendPasswordReset", this.sendPasswordReset);
11
+ this.router.post("/changePassword", this.changePassword);
12
+ this.router.post("/register", this.register);
13
+ this.router.post("/login", this.login);
14
+ this.router.post("/changeEmail", this.changeEmail);
15
+ this.router.post("/changeUsername", this.changeUsername);
16
+ this.router.post("/deletePermanently", this.deletePermanently);
17
+ this.router.post("/getInventory", this.getInventory);
18
+ this.router.post("/getAttributes", this.getAttributes);
19
+ }
7
20
 
21
+ logout = async (req, res) => {
8
22
  await req.session.destroy();
9
23
 
10
- return success("Logged out.");
11
- },
12
- sendPasswordReset: async (req) => {
13
- let reset = new req.db.User("reset");
14
-
15
- let token = Math.floor(Math.random() * 9999);
16
-
17
- await reset.create({
18
- email: req.body.data.email,
19
- token: token,
20
- tokenExp: Date.now() + (1000 * 60 * 30)
21
- });
22
-
23
- req.db.SendMail.passwordReset(req.body.data.email, token);
24
-
25
- return success("Password reset.", {});
26
- },
27
- changePassword: async (req) => {
28
- let reset = new req.db.User("reset");
29
- let resetData = await reset.recallFromData("token", req.body.data.token);
30
-
31
- check(resetData, "Reset token not valid!");
32
- check(resetData.tokenExp < Date.now(), "Reset token expired!");
33
- check(req.body.data.password !== req.body.data.confirmation, "Passwords must match!");
34
-
35
- const salt = await bcrypt.genSalt(10);
36
- const hash = await bcrypt.hash(req.body.data.password, salt);
37
-
38
- let user = new req.db.User("user");
39
- let userData = (await user.recallFromData("email", resetData.email)).data;
40
-
41
- userData.password = hash;
42
- await user.commit(userData);
43
-
44
- await reset.delete();
45
-
46
- return success("Password changed successfully!");
47
- },
48
- register: async (req) => {
49
- check(req.body.data.password.length > 7, "Password too short.");
50
- check(req.body.data.email.length > 7, "Email too short.");
51
- check(req.body.data.username.length > 2, "Username too short.");
52
-
53
- let user = new req.db.User("user", req.body.data.email);
54
- let userData = await user.recall();
55
-
56
- check(!userData, "Email already in use!");
57
-
58
- const salt = await bcrypt.genSalt(10);
59
- const hash = await bcrypt.hash(req.body.data.password, salt);
60
-
61
- await user.create({
62
- username: req.body.data.username,
63
- password: hash,
64
- email: req.body.data.email,
65
- coin: 0,
66
- home: "/",
67
- authLevels: [ "Basic" ],
68
- location: "/the-front",
69
- attributes: {
70
- translation: 0,
71
- strength: 0,
72
- agility: 0,
73
- defense: 0
74
- },
75
- inventory: []
76
- });
77
-
78
- return success("Registration successful!");
79
- },
80
- login: async (req) => {
81
- let user = await findUser(req, req.body.data.email);
24
+ success(res, "Logged out.");
25
+ }
82
26
 
83
- let passResult = await bcrypt.compare(req.body.data.password, user.memory.data.password);
84
- check(passResult, "Password doesn't match.");
27
+ sendPasswordReset = async (req, res) => {
28
+ let spirit = await req.db.User.recallOne(req.body.data.email);
85
29
 
86
- req.session.currentUser = req.body.data.email;
30
+ if (spirit) {
31
+ let token = Math.floor(Math.random() * 9999);
87
32
 
88
- return success("Logged in.");
89
- },
90
- changeUserEmail: async (req) => {
91
- loginCheck(req);
33
+ if (req.body.data.test) console.log("token: " + token);
92
34
 
93
- let user = new req.db.User("user", req.body.data.email);
94
- let userData = await user.recall();
35
+ spirit.memory.data.resetToken = token;
36
+ spirit.memory.data.resetExp = Date.now() + (1000 * 60 * 10);
37
+ await spirit.commit();
38
+
39
+ req.db.SendMail.passwordReset(req.body.data.email, token);
40
+
41
+ success(res, "Password reset token sent.");
42
+ }
43
+ else fail(res, "User not found.");
44
+ }
95
45
 
96
- check(!userData, "Email already in use!");
46
+ changePassword = async (req, res) => {
47
+ if (check(res, req.body.data.token, "No token provided!")){
48
+ let spirit = await req.db.User.recallOne(req.body.data.email);
49
+
50
+ if (check(res, spirit, "User not found!") &&
51
+ check(res, spirit.memory.data.resetToken == req.body.data.token, "Reset token not valid!") &&
52
+ check(res, spirit.memory.data.resetExp > Date.now(), "Reset token expired!") &&
53
+ check(res, req.body.data.password === req.body.data.confirmation, "Passwords must match!"))
54
+ {
55
+ spirit.memory.data.resetExp = -1;
56
+
57
+ const salt = await bcrypt.genSalt(10);
58
+ const hash = await bcrypt.hash(req.body.data.password, salt);
59
+
60
+ spirit.memory.data.password = hash;
61
+ await spirit.commit();
62
+
63
+ success(res, "Password changed successfully!");
64
+ }
65
+ }
66
+ }
97
67
 
98
- user = await findUser(req);
68
+ register = async (req, res) => {
69
+ if (check(res, req.body.data.password.length > 7, "Password too short.") &&
70
+ check(res, req.body.data.email.length > 7, "Email too short.") &&
71
+ check(res, req.body.data.username.length > 2, "Username too short."))
72
+ {
73
+ let spirit = await req.db.User.recallOne(req.body.data.email);
74
+
75
+ if (check(res, !spirit, "Email already in use!")) {
76
+ spirit = await req.db.User.create(req.body.data.username, req.body.data.password, req.body.data.email);
77
+
78
+ success(res, "Registration successful!");
79
+ }
80
+ }
81
+ }
99
82
 
100
- user.memory.data.email = req.body.data.email;
101
- await user.commit();
83
+ login = async (req, res) => {
84
+ let spirit = await req.db.User.recallOne(req.body.data.email);
85
+ if (check(res, spirit, "User not found.")) {
86
+ let passResult = await bcrypt.compare(req.body.data.password, spirit.memory.data.password);
87
+
88
+ if (check(res, passResult, "Password doesn't match the email.")) {
89
+ req.session.currentUser = req.body.data.email;
90
+
91
+ success(res, "Logged in.", spirit.memory.data.username);
92
+ }
93
+ }
94
+ }
102
95
 
103
- req.session.currentUser = req.body.data.email;
96
+ changeEmail = async (req, res) => {
97
+ if (loginCheck(req, res)) {
98
+ let spirit = await req.db.User.recallOne(req.body.data.email);
99
+
100
+ if (check(res, !spirit, "Email already in use!")) {
101
+ spirit = await req.db.User.recallOne(req.session.currentUser);
102
+
103
+ spirit.memory.data.email = req.body.data.email;
104
+ await spirit.commit();
105
+
106
+ req.session.currentUser = req.body.data.email;
107
+
108
+ success(res, "Email changed.");
109
+ }
110
+ }
111
+ }
104
112
 
105
- return success();
106
- },
107
- changeUsername: async (req) => {
108
- loginCheck(req);
109
-
110
- let user = new req.db.User("user");
111
- let userData = await user.recallFromData("username", req.body.data.username);
112
- check(!userData, "Username already in use!");
113
+ changeUsername = async (req, res) => {
114
+ if (loginCheck(req, res)) {
115
+ let spirit = await req.db.User.recallOne(null, req.body.data.username);
116
+
117
+ if (check(res, !spirit, "Username already in use!")) {
118
+ spirit = await req.db.User.recallOne(req.session.currentUser);
119
+
120
+ spirit.memory.data.username = req.body.data.username;
121
+ await spirit.commit();
122
+
123
+ success(res, "Username changed");
124
+ }
125
+ }
126
+ }
113
127
 
114
- user = await findUser(req);
115
-
116
- user.memory.data.username = req.body.data.username;
117
- await user.commit();
118
-
119
- return success();
120
- },
121
- deleteUserPermanently: async (req) => {
122
- loginCheck(req);
128
+ deletePermanently = async (req, res) => {
129
+ if (loginCheck(req, res)) {
130
+ let deleted = await req.db.User.delete(req.session.currentUser);
131
+
132
+ if (check(res, deleted > 0, "No account deleted")) {
133
+ await req.session.destroy();
123
134
 
124
- await user.findOneAndDelete().where("data.email").equals(req.session.currentUser);
125
- await req.session.destroy();
135
+ success(res, "Account deleted.");
136
+ }
137
+ }
138
+ }
126
139
 
127
- return success("Account deleted.");
140
+ getInventory = async (req, res) => {
141
+ if (loginCheck(req, res)) {
142
+ let spirit = await req.db.User.recallOne(req.session.currentUser);
143
+ if (spirit.memory._lastUpdate > req.body._lastUpdate) {
144
+ let inv = spirit.memory.data.inventory;
145
+
146
+ success(res, "Inventory found", inv, spirit.memory._lastUpdate);
147
+ }
148
+ else fail(res, "Inventory up to date.");
149
+ }
128
150
  }
129
- }
130
151
 
152
+ getAttributes = async (req, res) => {
153
+ if (loginCheck(req, res)) {
154
+ let user = await req.db.User.recallOne(req.session.currentUser);
155
+
156
+ if (user.memory._lastUpdate > req.body._lastUpdate) {
157
+ success(res, "Attributes found", user.memory.data.attributes);
158
+ }
159
+ else fail(res, "Attributes up to date.");
160
+ }
161
+ }
162
+ }
@@ -1,39 +1,31 @@
1
- export let loginCheck = (req) => {
2
- check(req.session.currentUser, "Please login first.");
3
- }
4
-
5
- export let findUser = async (req, email = req.session.currentUser) => {
6
- let user = new req.db.User("user", email);
7
- let userData = await user.recall();
8
-
9
- check(userData, "User not found.");
10
-
11
- return user;
12
- }
13
-
14
- export let check = (checkee, failMsg) => {
15
- if (!checkee) throw {
16
- status: "failed",
17
- message: failMsg,
18
- isUpToDate: true,
19
- data: null
20
- };
21
- }
1
+ export const check = (res, checkee, failMsg = "Failed!") => {
2
+ if (!checkee) {
3
+ fail(res, failMsg);
4
+ return false;
5
+ }
6
+ else {
7
+ return true;
8
+ }
9
+ };
22
10
 
23
- export let success = (msg = "Update successful.", data = null, isUpToDate = false) => {
24
- return {
11
+ export const success = (res, msg = "Success!", data = null, lastUpdate = 0) => {
12
+ res.send({
25
13
  status: "success",
26
14
  message: msg,
27
- isUpToDate: isUpToDate,
15
+ lastUpdate: lastUpdate,
28
16
  data: data
29
- };
30
- }
17
+ });
18
+ };
31
19
 
32
- export let fail = (msg, data = null, isUpToDate = true) => {
33
- return {
20
+ export const fail = (res, msg = "Failed!") => {
21
+ res.send({
34
22
  status: "failed",
35
23
  message: msg,
36
- isUpToDate: isUpToDate,
37
- data: data
38
- }
24
+ lastUpdate: 0,
25
+ data: null
26
+ });
27
+ };
28
+
29
+ export const loginCheck = (req, res) => {
30
+ return check(res, req.session.currentUser, "Please login first.");
39
31
  }