notherbase-fs 4.0.22 → 4.1.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 (55) hide show
  1. package/README.md +6 -6
  2. package/controllers/creation.js +171 -147
  3. package/controllers/spirit-world.js +174 -174
  4. package/controllers/user.js +240 -240
  5. package/controllers/util.js +64 -64
  6. package/models/index.js +33 -33
  7. package/models/send-mail.js +58 -58
  8. package/models/spirit.js +234 -234
  9. package/notherbase-fs.js +114 -112
  10. package/package.json +40 -40
  11. package/public/js/base.js +222 -227
  12. package/public/js/chat-box.js +120 -120
  13. package/test/coast/tall-beach/nono-cove/index.css +17 -17
  14. package/test/coast/tall-beach/nono-cove/index.ejs +29 -29
  15. package/test/coast/tall-beach/nono-cove/nono-og/add-gold.js +15 -15
  16. package/test/coast/tall-beach/nono-cove/nono-og/index.ejs +46 -46
  17. package/test/coast/tall-beach/nono-cove/nono-og/nono.css +88 -88
  18. package/test/coast/tall-beach/nono-cove/nono-og/nono.js +207 -207
  19. package/test/pages/test-page/emailTime.js +8 -8
  20. package/test/pages/test-page/index.ejs +104 -104
  21. package/test/pages/void/index.ejs +35 -35
  22. package/test/pages/void/void.css +2 -2
  23. package/test/public/styles/main.css +792 -792
  24. package/test/the-front/add-gold.js +13 -13
  25. package/test/the-front/check/_preprocess/saved.js +9 -0
  26. package/test/the-front/check/check.css +2 -2
  27. package/test/the-front/check/emailTime.js +9 -9
  28. package/test/the-front/check/flip.js +9 -9
  29. package/test/the-front/check/index.ejs +55 -54
  30. package/test/the-front/check/save-input.js +7 -7
  31. package/test/the-front/index.ejs +116 -99
  32. package/test/the-front/keeper/clipboards.js +133 -133
  33. package/test/the-front/keeper/index.ejs +80 -80
  34. package/test/the-front/keeper/keeper.css +157 -157
  35. package/test/the-front/keeper/keeper.js +140 -140
  36. package/test-index.js +19 -19
  37. package/test2/pages/test-page/emailTime.js +8 -8
  38. package/test2/pages/test-page/index.ejs +104 -104
  39. package/test2/pages/void/index.ejs +35 -35
  40. package/test2/pages/void/void.css +2 -2
  41. package/test2/public/styles/main.css +792 -792
  42. package/test2/the-front/add-gold.js +13 -13
  43. package/test2/the-front/check/check.css +2 -2
  44. package/test2/the-front/check/emailTime.js +9 -9
  45. package/test2/the-front/check/flip.js +9 -9
  46. package/test2/the-front/check/index.ejs +54 -54
  47. package/test2/the-front/check/save-input.js +7 -7
  48. package/test2/the-front/index.ejs +99 -99
  49. package/test2/the-front/keeper/clipboards.js +133 -133
  50. package/test2/the-front/keeper/index.ejs +80 -80
  51. package/test2/the-front/keeper/keeper.css +157 -157
  52. package/test2/the-front/keeper/keeper.js +140 -140
  53. package/views/explorer.ejs +82 -82
  54. package/views/footer.ejs +9 -9
  55. package/views/head.ejs +17 -17
@@ -1,241 +1,241 @@
1
- import express from "express";
2
- import bcrypt from "bcrypt";
3
- import { check, success, successJSON, fail, loginCheck } from "./util.js";
4
-
5
- /**
6
- * API routes for user functions.
7
- */
8
- export default class User {
9
- constructor() {
10
- this.router = express.Router();
11
-
12
- this.router.post("/logout", this.logout);
13
- this.router.post("/changePassword", this.changePassword);
14
- this.router.post("/register", this.register);
15
- this.router.post("/login", this.login);
16
- this.router.post("/deletePermanently", this.deletePermanently);
17
- this.router.post("/getInfo", this.getInfo);
18
- this.router.post("/getView", this.getView);
19
- this.router.post("/setView", this.setView);
20
- this.router.post("/downloadData", this.downloadData);
21
- this.router.post("/deleteAlldata", this.deleteAlldata);
22
- this.router.post("/importData", this.importData);
23
- }
24
-
25
- /**
26
- * Logs the user out.
27
- * @param {Object} req An Express.js request.
28
- * @param {Object} res An Express.js response.
29
- */
30
- logout = async (req, res) => {
31
- await req.session.destroy();
32
-
33
- success(res, "Logged out.");
34
- }
35
-
36
- /**
37
- * Change a user's password.
38
- * @param {Object} req An Express.js request.
39
- * @param {Object} res An Express.js response.
40
- */
41
- changePassword = async (req, res) => {
42
- if (loginCheck(req, res)) {
43
- let spirit = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
44
-
45
- if (check(res, spirit, "User not found!") &&
46
- check(res, req.body.newPassword === req.body.confirmation, "New password and confirmation must match!") &&
47
- check(res, req.body.oldPassword != req.body.newPassword, "New password must be different from the old one."))
48
- {
49
- let passResult = await bcrypt.compare(req.body.oldPassword, spirit.memory.data.password);
50
-
51
- if (check(res, passResult, "Old password incorrect.")) {
52
- const salt = await bcrypt.genSalt(10);
53
- const hash = await bcrypt.hash(req.body.newPassword, salt);
54
-
55
- spirit.addBackup({
56
- ...spirit.memory.data,
57
- password: hash
58
- });
59
-
60
- await spirit.commit();
61
-
62
- success(res, "Password changed successfully!");
63
- }
64
- }
65
- }
66
- }
67
-
68
- /**
69
- * Register a new user account.
70
- * @param {Object} req An Express.js request.
71
- * @param {Object} res An Express.js response.
72
- */
73
- register = async (req, res) => {
74
- if (check(res, req.body.password.length > 10, "Password must be >10 characters long.") &&
75
- check(res, req.body.username.length > 2, "Username too short."))
76
- {
77
- let spirit = await req.db.Spirit.recallOne("user", null, { username: req.body.username });
78
-
79
- if (check(res, !spirit, "Username already in use!")) {
80
- const salt = await bcrypt.genSalt(10);
81
- const hash = await bcrypt.hash(req.body.password, salt);
82
-
83
- spirit = await req.db.Spirit.create("user", {
84
- username: req.body.username,
85
- password: hash,
86
- authLevels: [ "Basic" ],
87
- view: "compact"
88
- });
89
-
90
- success(res, "Registration successful!");
91
- }
92
- }
93
- }
94
-
95
- /**
96
- * Logs a user in.
97
- * @param {Object} req An Express.js request.
98
- * @param {Object} res An Express.js response.
99
- */
100
- login = async (req, res) => {
101
- let spirit = await req.db.Spirit.recallOne("user", null, { username: req.body.username });
102
-
103
- if (check(res, spirit, "User not found.")) {
104
- let passResult = await bcrypt.compare(req.body.password, spirit.memory.data.password);
105
-
106
- if (check(res, passResult, "Password doesn't match the username.")) {
107
- req.session.currentUser = req.body.username;
108
-
109
- success(res, "Logged in.", req.body.username);
110
- }
111
- }
112
- }
113
-
114
- /**
115
- * Deletes a user account premanently.
116
- * @param {Object} req An Express.js request.
117
- * @param {Object} res An Express.js response.
118
- */
119
- deletePermanently = async (req, res) => {
120
- if (loginCheck(req, res)) {
121
- let spirit = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
122
-
123
- if (check(res, spirit, "User not found.")) {
124
- let passResult = await bcrypt.compare(req.body.password, spirit.memory.data.password);
125
-
126
- if (check(res, passResult, "Password doesn't match the username.")) {
127
- let deleted = await req.db.Spirit.delete("user", null, { username: req.session.currentUser });
128
-
129
- if (check(res, deleted > 0, "No account deleted")) {
130
- await req.session.destroy();
131
-
132
- success(res, "Account deleted.");
133
- }
134
- }
135
- }
136
- }
137
- }
138
-
139
- /**
140
- * Gets basic account information.
141
- * @param {Object} req An Express.js request.
142
- * @param {Object} res An Express.js response.
143
- */
144
- getInfo = async (req, res) => {
145
- if (loginCheck(req, res)) {
146
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
147
-
148
- if (check(res, user, "Account not found!")) {
149
- success(res, "Info found", {
150
- username: user.memory.data.username
151
- });
152
- }
153
- }
154
- }
155
-
156
- /**
157
- * Gets a user's saved view state.
158
- */
159
- getView = async (req, res) => {
160
- if (loginCheck(req, res)) {
161
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
162
-
163
- if (check(res, user, "Account not found!")) {
164
- success(res, "View found", user.memory.data.view);
165
- }
166
- }
167
- }
168
-
169
- /**
170
- * Sets a user's view state.
171
- */
172
- setView = async (req, res) => {
173
- if (loginCheck(req, res)) {
174
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
175
-
176
- if (check(res, user, "Account not found!")) {
177
- user.memory.data.view = req.body.view == "compact" ? "compact" : "full";
178
- await user.commit();
179
-
180
- success(res, "View set");
181
- }
182
- }
183
- }
184
-
185
- //download all spirit data belonging to the user
186
- downloadData = async (req, res) => {
187
- if (loginCheck(req, res)) {
188
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
189
-
190
- if (check(res, user, "Account not found!")) {
191
- let data = await req.db.Spirit.recallAll(null, user.memory._id);
192
- let dataToDownload = data.map(d => d.memory);
193
- dataToDownload.unshift(user.memory.data);
194
-
195
- successJSON(res, "Data Downloaded", dataToDownload);
196
- }
197
- }
198
- }
199
-
200
- //delete all spirit data belonging to the user
201
- deleteAlldata = async (req, res) => {
202
- if (loginCheck(req, res)) {
203
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
204
-
205
- if (check(res, user, "Account not found!")) {
206
- let passResult = await bcrypt.compare(req.body.password, user.memory.data.password);
207
-
208
- if (check(res, passResult, "Password doesn't match the username.")) {
209
- let deleted = await req.db.Spirit.delete(null, user.memory._id);
210
- if (check(res, deleted > 0, "No data deleted")) {
211
- success(res, "Data Deleted", deleted);
212
- }
213
- }
214
- }
215
- }
216
- }
217
-
218
- // import spirit data from a JSON file
219
- importData = async (req, res) => {
220
- if (loginCheck(req, res)) {
221
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
222
-
223
- if (check(res, user, "Account not found!")) {
224
- let passResult = await bcrypt.compare(req.body.password, user.memory.data.password);
225
-
226
- if (check(res, passResult, "Password doesn't match the username.")) {
227
- let data = req.body.data;
228
- let imported = 0;
229
- for (let i = 0; i < data.length; i++) {
230
- if (data[i].parent != null) {
231
- let spirit = await req.db.Spirit.create(data[i].service, data[i].data, user.memory._id);
232
- if (spirit) imported++;
233
- }
234
- }
235
-
236
- success(res, "Data Imported", imported);
237
- }
238
- }
239
- }
240
- }
1
+ import express from "express";
2
+ import bcrypt from "bcrypt";
3
+ import { check, success, successJSON, fail, loginCheck } from "./util.js";
4
+
5
+ /**
6
+ * API routes for user functions.
7
+ */
8
+ export default class User {
9
+ constructor() {
10
+ this.router = express.Router();
11
+
12
+ this.router.post("/logout", this.logout);
13
+ this.router.post("/changePassword", this.changePassword);
14
+ this.router.post("/register", this.register);
15
+ this.router.post("/login", this.login);
16
+ this.router.post("/deletePermanently", this.deletePermanently);
17
+ this.router.post("/getInfo", this.getInfo);
18
+ this.router.post("/getView", this.getView);
19
+ this.router.post("/setView", this.setView);
20
+ this.router.post("/downloadData", this.downloadData);
21
+ this.router.post("/deleteAlldata", this.deleteAlldata);
22
+ this.router.post("/importData", this.importData);
23
+ }
24
+
25
+ /**
26
+ * Logs the user out.
27
+ * @param {Object} req An Express.js request.
28
+ * @param {Object} res An Express.js response.
29
+ */
30
+ logout = async (req, res) => {
31
+ await req.session.destroy();
32
+
33
+ success(res, "Logged out.");
34
+ }
35
+
36
+ /**
37
+ * Change a user's password.
38
+ * @param {Object} req An Express.js request.
39
+ * @param {Object} res An Express.js response.
40
+ */
41
+ changePassword = async (req, res) => {
42
+ if (loginCheck(req, res)) {
43
+ let spirit = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
44
+
45
+ if (check(res, spirit, "User not found!") &&
46
+ check(res, req.body.newPassword === req.body.confirmation, "New password and confirmation must match!") &&
47
+ check(res, req.body.oldPassword != req.body.newPassword, "New password must be different from the old one."))
48
+ {
49
+ let passResult = await bcrypt.compare(req.body.oldPassword, spirit.memory.data.password);
50
+
51
+ if (check(res, passResult, "Old password incorrect.")) {
52
+ const salt = await bcrypt.genSalt(10);
53
+ const hash = await bcrypt.hash(req.body.newPassword, salt);
54
+
55
+ spirit.addBackup({
56
+ ...spirit.memory.data,
57
+ password: hash
58
+ });
59
+
60
+ await spirit.commit();
61
+
62
+ success(res, "Password changed successfully!");
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Register a new user account.
70
+ * @param {Object} req An Express.js request.
71
+ * @param {Object} res An Express.js response.
72
+ */
73
+ register = async (req, res) => {
74
+ if (check(res, req.body.password.length > 10, "Password must be >10 characters long.") &&
75
+ check(res, req.body.username.length > 2, "Username too short."))
76
+ {
77
+ let spirit = await req.db.Spirit.recallOne("user", null, { username: req.body.username });
78
+
79
+ if (check(res, !spirit, "Username already in use!")) {
80
+ const salt = await bcrypt.genSalt(10);
81
+ const hash = await bcrypt.hash(req.body.password, salt);
82
+
83
+ spirit = await req.db.Spirit.create("user", {
84
+ username: req.body.username,
85
+ password: hash,
86
+ authLevels: [ "Basic" ],
87
+ view: "compact"
88
+ });
89
+
90
+ success(res, "Registration successful!");
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Logs a user in.
97
+ * @param {Object} req An Express.js request.
98
+ * @param {Object} res An Express.js response.
99
+ */
100
+ login = async (req, res) => {
101
+ let spirit = await req.db.Spirit.recallOne("user", null, { username: req.body.username });
102
+
103
+ if (check(res, spirit, "User not found.")) {
104
+ let passResult = await bcrypt.compare(req.body.password, spirit.memory.data.password);
105
+
106
+ if (check(res, passResult, "Password doesn't match the username.")) {
107
+ req.session.currentUser = req.body.username;
108
+
109
+ success(res, "Logged in.", req.body.username);
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Deletes a user account premanently.
116
+ * @param {Object} req An Express.js request.
117
+ * @param {Object} res An Express.js response.
118
+ */
119
+ deletePermanently = async (req, res) => {
120
+ if (loginCheck(req, res)) {
121
+ let spirit = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
122
+
123
+ if (check(res, spirit, "User not found.")) {
124
+ let passResult = await bcrypt.compare(req.body.password, spirit.memory.data.password);
125
+
126
+ if (check(res, passResult, "Password doesn't match the username.")) {
127
+ let deleted = await req.db.Spirit.delete("user", null, { username: req.session.currentUser });
128
+
129
+ if (check(res, deleted > 0, "No account deleted")) {
130
+ await req.session.destroy();
131
+
132
+ success(res, "Account deleted.");
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Gets basic account information.
141
+ * @param {Object} req An Express.js request.
142
+ * @param {Object} res An Express.js response.
143
+ */
144
+ getInfo = async (req, res) => {
145
+ if (loginCheck(req, res)) {
146
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
147
+
148
+ if (check(res, user, "Account not found!")) {
149
+ success(res, "Info found", {
150
+ username: user.memory.data.username
151
+ });
152
+ }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Gets a user's saved view state.
158
+ */
159
+ getView = async (req, res) => {
160
+ if (loginCheck(req, res)) {
161
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
162
+
163
+ if (check(res, user, "Account not found!")) {
164
+ success(res, "View found", user.memory.data.view);
165
+ }
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Sets a user's view state.
171
+ */
172
+ setView = async (req, res) => {
173
+ if (loginCheck(req, res)) {
174
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
175
+
176
+ if (check(res, user, "Account not found!")) {
177
+ user.memory.data.view = req.body.view == "compact" ? "compact" : "full";
178
+ await user.commit();
179
+
180
+ success(res, "View set");
181
+ }
182
+ }
183
+ }
184
+
185
+ //download all spirit data belonging to the user
186
+ downloadData = async (req, res) => {
187
+ if (loginCheck(req, res)) {
188
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
189
+
190
+ if (check(res, user, "Account not found!")) {
191
+ let data = await req.db.Spirit.recallAll(null, user.memory._id);
192
+ let dataToDownload = data.map(d => d.memory);
193
+ dataToDownload.unshift(user.memory.data);
194
+
195
+ successJSON(res, "Data Downloaded", dataToDownload);
196
+ }
197
+ }
198
+ }
199
+
200
+ //delete all spirit data belonging to the user
201
+ deleteAlldata = async (req, res) => {
202
+ if (loginCheck(req, res)) {
203
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
204
+
205
+ if (check(res, user, "Account not found!")) {
206
+ let passResult = await bcrypt.compare(req.body.password, user.memory.data.password);
207
+
208
+ if (check(res, passResult, "Password doesn't match the username.")) {
209
+ let deleted = await req.db.Spirit.delete(null, user.memory._id);
210
+ if (check(res, deleted > 0, "No data deleted")) {
211
+ success(res, "Data Deleted", deleted);
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ // import spirit data from a JSON file
219
+ importData = async (req, res) => {
220
+ if (loginCheck(req, res)) {
221
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
222
+
223
+ if (check(res, user, "Account not found!")) {
224
+ let passResult = await bcrypt.compare(req.body.password, user.memory.data.password);
225
+
226
+ if (check(res, passResult, "Password doesn't match the username.")) {
227
+ let data = JSON.parse(req.body.data);
228
+ let imported = 0;
229
+ for (let i = 0; i < data.length; i++) {
230
+ if (data[i].parent != null) {
231
+ let spirit = await req.db.Spirit.create(data[i].service, data[i].data, user.memory._id);
232
+ if (spirit) imported++;
233
+ }
234
+ }
235
+
236
+ success(res, "Data Imported", imported);
237
+ }
238
+ }
239
+ }
240
+ }
241
241
  }
@@ -1,65 +1,65 @@
1
- /**
2
- * Check if something is true. Respond with a fail otherwise.
3
- * @param {Object} res An Express.js response.
4
- * @param {*} checkee What to check against.
5
- * @param {String} failMsg Message to send in a potential failure response.
6
- * @returns True or false.
7
- */
8
- export const check = (res, checkee, failMsg = "Failed!") => {
9
- if (!checkee) {
10
- fail(res, failMsg);
11
- return false;
12
- }
13
- else {
14
- return true;
15
- }
16
- };
17
-
18
- /**
19
- * Respond to the client with success.
20
- * @param {Object} res An Express.js response.
21
- * @param {String} msg A message describing the success.
22
- * @param {Object} data Data to send with the response.
23
- * @param {Number} lastUpdate A number date for synchronization.
24
- */
25
- export const success = (res, msg = "Success!", data = null, lastUpdate = 0) => {
26
- res.send({
27
- status: "success",
28
- message: msg,
29
- lastUpdate: lastUpdate,
30
- data: data
31
- });
32
- };
33
-
34
- export const successJSON = (res, msg = "Success!", data = null, lastUpdate = 0) => {
35
- res.json({
36
- status: "success",
37
- message: msg,
38
- lastUpdate: lastUpdate,
39
- data: data
40
- });
41
- }
42
-
43
- /**
44
- * Respond to the client with failure.
45
- * @param {Object} res An Express.js response.
46
- * @param {String} msg A message describing the failure.
47
- */
48
- export const fail = (res, msg = "Failed!") => {
49
- res.send({
50
- status: "failed",
51
- message: msg,
52
- lastUpdate: 0,
53
- data: null
54
- });
55
- };
56
-
57
- /**
58
- * Check if a user is logged in.
59
- * @param {Object} req An Express.js request.
60
- * @param {Object} res An Express.js response.
61
- * @returns True if a user is logged in, else false.
62
- */
63
- export const loginCheck = (req, res) => {
64
- return check(res, req.session?.currentUser, "Please login first.");
1
+ /**
2
+ * Check if something is true. Respond with a fail otherwise.
3
+ * @param {Object} res An Express.js response.
4
+ * @param {*} checkee What to check against.
5
+ * @param {String} failMsg Message to send in a potential failure response.
6
+ * @returns True or false.
7
+ */
8
+ export const check = (res, checkee, failMsg = "Failed!") => {
9
+ if (!checkee) {
10
+ fail(res, failMsg);
11
+ return false;
12
+ }
13
+ else {
14
+ return true;
15
+ }
16
+ };
17
+
18
+ /**
19
+ * Respond to the client with success.
20
+ * @param {Object} res An Express.js response.
21
+ * @param {String} msg A message describing the success.
22
+ * @param {Object} data Data to send with the response.
23
+ * @param {Number} lastUpdate A number date for synchronization.
24
+ */
25
+ export const success = (res, msg = "Success!", data = null, lastUpdate = 0) => {
26
+ res.send({
27
+ status: "success",
28
+ message: msg,
29
+ lastUpdate: lastUpdate,
30
+ data: data
31
+ });
32
+ };
33
+
34
+ export const successJSON = (res, msg = "Success!", data = null, lastUpdate = 0) => {
35
+ res.json({
36
+ status: "success",
37
+ message: msg,
38
+ lastUpdate: lastUpdate,
39
+ data: data
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Respond to the client with failure.
45
+ * @param {Object} res An Express.js response.
46
+ * @param {String} msg A message describing the failure.
47
+ */
48
+ export const fail = (res, msg = "Failed!") => {
49
+ res.send({
50
+ status: "failed",
51
+ message: msg,
52
+ lastUpdate: 0,
53
+ data: null
54
+ });
55
+ };
56
+
57
+ /**
58
+ * Check if a user is logged in.
59
+ * @param {Object} req An Express.js request.
60
+ * @param {Object} res An Express.js response.
61
+ * @returns True if a user is logged in, else false.
62
+ */
63
+ export const loginCheck = (req, res) => {
64
+ return check(res, req.session?.currentUser, "Please login first.");
65
65
  }