notherbase-fs 4.4.7 → 4.5.1
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/notherbase-fs.js +40 -32
- package/package.json +1 -1
- package/public/js/base.js +1 -41
- package/server/creation.js +117 -0
- package/server/spirit-world.js +147 -0
- package/server/spirit.js +83 -0
- package/{controllers → server}/user.js +36 -37
- package/test/coast/tall-beach/nono-cove/index.ejs +3 -3
- package/test/the-front/add-gold.js +4 -12
- package/test/the-front/index.ejs +12 -6
- package/test2/the-front/index.ejs +0 -99
- package/views/explorer.ejs +1 -1
- package/views/footer.ejs +1 -1
- package/controllers/creation.js +0 -181
- package/controllers/spirit-world.js +0 -247
- package/models/index.js +0 -31
- package/models/spirit.js +0 -235
- package/test2/the-front/add-gold.js +0 -14
- package/test2/the-front/check/check.css +0 -3
- package/test2/the-front/check/emailTime.js +0 -10
- package/test2/the-front/check/flip.js +0 -10
- package/test2/the-front/check/index.ejs +0 -55
- package/test2/the-front/check/save-input.js +0 -8
- package/test2/the-front/keeper/clipboards.js +0 -134
- package/test2/the-front/keeper/index.ejs +0 -81
- package/test2/the-front/keeper/keeper.css +0 -158
- package/test2/the-front/keeper/keeper.js +0 -140
- package/test2/the-front/test-page/emailTime.js +0 -9
- package/test2/the-front/test-page/index.ejs +0 -74
- /package/{models → server}/send-mail.js +0 -0
- /package/{controllers → server}/util.js +0 -0
- /package/test/{the-front/void → void}/index.ejs +0 -0
- /package/test/{the-front/void → void}/void.css +0 -0
|
@@ -20,7 +20,6 @@ export default class User {
|
|
|
20
20
|
this.router.post("/downloadData", this.downloadData);
|
|
21
21
|
this.router.post("/deleteAlldata", this.deleteAlldata);
|
|
22
22
|
this.router.post("/importData", this.importData);
|
|
23
|
-
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
/**
|
|
@@ -30,7 +29,7 @@ export default class User {
|
|
|
30
29
|
*/
|
|
31
30
|
logout = async (req, res) => {
|
|
32
31
|
if (loginCheck(req, res)) {
|
|
33
|
-
delete req.user
|
|
32
|
+
delete req.user?.data?.sessions[req.session.id];
|
|
34
33
|
await req.user.commit();
|
|
35
34
|
await req.session?.destroy();
|
|
36
35
|
|
|
@@ -45,20 +44,20 @@ export default class User {
|
|
|
45
44
|
*/
|
|
46
45
|
changePassword = async (req, res) => {
|
|
47
46
|
if (loginCheck(req, res)) {
|
|
48
|
-
let spirit = await req.
|
|
47
|
+
let spirit = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
49
48
|
|
|
50
49
|
if (check(res, spirit, "User not found!") &&
|
|
51
50
|
check(res, req.body.newPassword === req.body.confirmation, "New password and confirmation must match!") &&
|
|
52
51
|
check(res, req.body.oldPassword != req.body.newPassword, "New password must be different from the old one."))
|
|
53
52
|
{
|
|
54
|
-
let passResult = await bcrypt.compare(req.body.oldPassword, spirit.
|
|
53
|
+
let passResult = await bcrypt.compare(req.body.oldPassword, spirit.data.password);
|
|
55
54
|
|
|
56
55
|
if (check(res, passResult, "Old password incorrect.")) {
|
|
57
56
|
const salt = await bcrypt.genSalt(10);
|
|
58
57
|
const hash = await bcrypt.hash(req.body.newPassword, salt);
|
|
59
58
|
|
|
60
59
|
spirit.addBackup({
|
|
61
|
-
...spirit.
|
|
60
|
+
...spirit.data,
|
|
62
61
|
password: hash
|
|
63
62
|
});
|
|
64
63
|
|
|
@@ -71,17 +70,17 @@ export default class User {
|
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
validatePassword = async (req, password, user) => {
|
|
74
|
-
if (password && user?.
|
|
75
|
-
if (password == user.
|
|
76
|
-
if (Date.now() < user.
|
|
77
|
-
user.
|
|
73
|
+
if (password && user?.data?.otp) {
|
|
74
|
+
if (password == user.data.otp.code) {
|
|
75
|
+
if (Date.now() < user.data.otp.expires) {
|
|
76
|
+
user.data.otp.expires = 0;
|
|
78
77
|
await user.commit();
|
|
79
78
|
return "Authenticated.";
|
|
80
79
|
}
|
|
81
80
|
else return "One-time password expired.";
|
|
82
81
|
}
|
|
83
82
|
else {
|
|
84
|
-
let passResult = await bcrypt.compare(req.body.password, user.
|
|
83
|
+
let passResult = await bcrypt.compare(req.body.password, user.data.password);
|
|
85
84
|
if (passResult) return "Authenticated.";
|
|
86
85
|
else return "Password doesn't match the username.";
|
|
87
86
|
}
|
|
@@ -96,18 +95,18 @@ export default class User {
|
|
|
96
95
|
*/
|
|
97
96
|
changeEmail = async (req, res) => {
|
|
98
97
|
if (loginCheck(req, res)) {
|
|
99
|
-
let spirit = await req.
|
|
98
|
+
let spirit = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
100
99
|
|
|
101
100
|
if (check(res, spirit, "User not found!") &&
|
|
102
101
|
check(res, req.body.email, "New email must be provided."))
|
|
103
102
|
{
|
|
104
103
|
let result = await this.validatePassword(req, req.body.password, spirit);
|
|
105
104
|
if (result == "Authenticated.") {
|
|
106
|
-
let other = await req.
|
|
105
|
+
let other = await req.Spirit.recallOne("user", null, { email: req.body.email });
|
|
107
106
|
|
|
108
107
|
if (check(res, !other, "Email already in use!")) {
|
|
109
108
|
spirit.addBackup({
|
|
110
|
-
...spirit.
|
|
109
|
+
...spirit.data,
|
|
111
110
|
email: req.body.email
|
|
112
111
|
});
|
|
113
112
|
|
|
@@ -128,18 +127,18 @@ export default class User {
|
|
|
128
127
|
*/
|
|
129
128
|
sendOneTimePassword = async (req, res) => {
|
|
130
129
|
if (loginCheck(req, res)) {
|
|
131
|
-
let spirit = await req.
|
|
130
|
+
let spirit = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
132
131
|
|
|
133
132
|
if (check(res, spirit, "User not found!")) {
|
|
134
133
|
let otp = Math.floor(100000 + Math.random() * 900000);
|
|
135
|
-
spirit.
|
|
134
|
+
spirit.data.otp = {
|
|
136
135
|
code: otp,
|
|
137
136
|
expires: Date.now() + 1000 * 60 * 15
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
await spirit.commit();
|
|
141
140
|
|
|
142
|
-
await req.
|
|
141
|
+
await req.SendMail.send(spirit.data.email, 'One Time Password for NotherBase',
|
|
143
142
|
`<h1>Your One-Time Password:<h1>
|
|
144
143
|
<h2>${otp}<h2>
|
|
145
144
|
<p>Visit <a href="https://www.notherbase.com/the-front/keeper">notherbase.com/the-front/keeper</a> to use your one-time password.</p>
|
|
@@ -159,13 +158,13 @@ export default class User {
|
|
|
159
158
|
if (check(res, req.body.password.length > 10, "Password must be >10 characters long.") &&
|
|
160
159
|
check(res, req.body.username.length > 2, "Username too short."))
|
|
161
160
|
{
|
|
162
|
-
let spirit = await req.
|
|
161
|
+
let spirit = await req.Spirit.findOne({ service: "user", username: req.body.username });
|
|
163
162
|
|
|
164
163
|
if (check(res, !spirit, "Username already in use!")) {
|
|
165
164
|
const salt = await bcrypt.genSalt(10);
|
|
166
165
|
const hash = await bcrypt.hash(req.body.password, salt);
|
|
167
166
|
|
|
168
|
-
spirit = await req.
|
|
167
|
+
spirit = await req.Spirit.create("user", {
|
|
169
168
|
username: req.body.username,
|
|
170
169
|
password: hash,
|
|
171
170
|
authLevels: [ "Basic" ],
|
|
@@ -189,9 +188,9 @@ export default class User {
|
|
|
189
188
|
* @param {Object} res An Express.js response.
|
|
190
189
|
*/
|
|
191
190
|
login = async (req, res) => {
|
|
192
|
-
let spirit = await req.
|
|
191
|
+
let spirit = await req.Spirit.findOne({ service: "user", username: req.body.username });
|
|
193
192
|
if (check(res, spirit, "User not found.")) {
|
|
194
|
-
spirit.
|
|
193
|
+
spirit.data = {
|
|
195
194
|
username: "",
|
|
196
195
|
password: "",
|
|
197
196
|
authLevels: [ "Basic" ],
|
|
@@ -202,15 +201,15 @@ export default class User {
|
|
|
202
201
|
expires: 0
|
|
203
202
|
},
|
|
204
203
|
sessions: {},
|
|
205
|
-
...spirit.
|
|
204
|
+
...spirit.data
|
|
206
205
|
}
|
|
207
206
|
await spirit.commit();
|
|
208
207
|
|
|
209
208
|
let result = await this.validatePassword(req, req.body.password, spirit);
|
|
210
209
|
if (result === "Authenticated.") {
|
|
211
210
|
req.session.currentUser = req.body.username;
|
|
212
|
-
if (typeof spirit.
|
|
213
|
-
spirit.
|
|
211
|
+
if (typeof spirit.data.sessions !== "object" || Array.isArray(spirit.data.sessions)) spirit.data.sessions = {};
|
|
212
|
+
spirit.data.sessions[req.session.id] = Date.now() + 1000 * 60 * 60 * 24 * 28; // 28 days
|
|
214
213
|
await spirit.commit();
|
|
215
214
|
success(res, "Login successful!", req.body.username);
|
|
216
215
|
}
|
|
@@ -225,13 +224,13 @@ export default class User {
|
|
|
225
224
|
*/
|
|
226
225
|
deletePermanently = async (req, res) => {
|
|
227
226
|
if (loginCheck(req, res)) {
|
|
228
|
-
let spirit = await req.
|
|
227
|
+
let spirit = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
229
228
|
|
|
230
229
|
if (check(res, spirit, "User not found.")) {
|
|
231
|
-
let passResult = await bcrypt.compare(req.body.password, spirit.
|
|
230
|
+
let passResult = await bcrypt.compare(req.body.password, spirit.data.password);
|
|
232
231
|
|
|
233
232
|
if (check(res, passResult, "Password doesn't match the username.")) {
|
|
234
|
-
let deleted = await req.
|
|
233
|
+
let deleted = await req.Spirit.deleteMany({ service: "user", username: req.session.username });
|
|
235
234
|
|
|
236
235
|
if (check(res, deleted > 0, "No account deleted")) {
|
|
237
236
|
await req.session.destroy();
|
|
@@ -250,11 +249,11 @@ export default class User {
|
|
|
250
249
|
*/
|
|
251
250
|
getInfo = async (req, res) => {
|
|
252
251
|
if (loginCheck(req, res)) {
|
|
253
|
-
let user = await req.
|
|
252
|
+
let user = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
254
253
|
|
|
255
254
|
if (check(res, user, "Account not found!")) {
|
|
256
255
|
success(res, "Info found", {
|
|
257
|
-
username: user.
|
|
256
|
+
username: user.data.username
|
|
258
257
|
});
|
|
259
258
|
}
|
|
260
259
|
}
|
|
@@ -263,11 +262,11 @@ export default class User {
|
|
|
263
262
|
//download all spirit data belonging to the user
|
|
264
263
|
downloadData = async (req, res) => {
|
|
265
264
|
if (loginCheck(req, res)) {
|
|
266
|
-
let user = await req.
|
|
265
|
+
let user = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
267
266
|
|
|
268
267
|
if (check(res, user, "Account not found!")) {
|
|
269
|
-
let data = await req.
|
|
270
|
-
let dataToDownload = data.map(d => d
|
|
268
|
+
let data = await req.Spirit.recallAll(null, user._id);
|
|
269
|
+
let dataToDownload = data.map(d => d);
|
|
271
270
|
|
|
272
271
|
successJSON(res, "Data Downloaded", dataToDownload);
|
|
273
272
|
}
|
|
@@ -277,14 +276,14 @@ export default class User {
|
|
|
277
276
|
//delete all spirit data belonging to the user
|
|
278
277
|
deleteAlldata = async (req, res) => {
|
|
279
278
|
if (loginCheck(req, res)) {
|
|
280
|
-
let user = await req.
|
|
279
|
+
let user = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
281
280
|
|
|
282
281
|
if (check(res, user, "Account not found!")) {
|
|
283
282
|
if (check(res, req.body.password, "Password error.")) {
|
|
284
|
-
let passResult = await bcrypt.compare(req.body.password, user.
|
|
283
|
+
let passResult = await bcrypt.compare(req.body.password, user.data.password);
|
|
285
284
|
|
|
286
285
|
if (check(res, passResult, "Password doesn't match the username.")) {
|
|
287
|
-
let deleted = await req.
|
|
286
|
+
let deleted = await req.Spirit.deleteMany({ parent: user._id });
|
|
288
287
|
if (check(res, deleted > 0, "No data deleted")) {
|
|
289
288
|
success(res, "Data Deleted", deleted);
|
|
290
289
|
}
|
|
@@ -297,18 +296,18 @@ export default class User {
|
|
|
297
296
|
// import spirit data from a JSON file
|
|
298
297
|
importData = async (req, res) => {
|
|
299
298
|
if (loginCheck(req, res)) {
|
|
300
|
-
let user = await req.
|
|
299
|
+
let user = await req.Spirit.findOne({ service: "user", username: req.session.username });
|
|
301
300
|
|
|
302
301
|
if (check(res, user, "Account not found!")) {
|
|
303
302
|
if (check(res, req.body.password, "Password error.")) {
|
|
304
|
-
let passResult = await bcrypt.compare(req.body.password, user.
|
|
303
|
+
let passResult = await bcrypt.compare(req.body.password, user.data.password);
|
|
305
304
|
|
|
306
305
|
if (check(res, passResult, "Password doesn't match the username.")) {
|
|
307
306
|
let data = JSON.parse(req.body.data);
|
|
308
307
|
let imported = 0;
|
|
309
308
|
for (let i = 0; i < data.length; i++) {
|
|
310
309
|
if (data[i].parent != null) {
|
|
311
|
-
let spirit = await req.
|
|
310
|
+
let spirit = await req.Spirit.create(data[i].service, data[i].data, user._id);
|
|
312
311
|
if (spirit) imported++;
|
|
313
312
|
}
|
|
314
313
|
}
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
|
|
23
23
|
<script src="/js/chat-box.js"></script>
|
|
24
24
|
<script>
|
|
25
|
-
let chatTest = new ChatBox("<%= user.
|
|
26
|
-
let chatTest2 = new ChatBox("<%= user.
|
|
27
|
-
let chatTest3 = new ChatBox("<%= user.
|
|
25
|
+
let chatTest = new ChatBox("<%= user.data.username %>", "test-chat");
|
|
26
|
+
let chatTest2 = new ChatBox("<%= user.data.username %>", "test-chat-2");
|
|
27
|
+
let chatTest3 = new ChatBox("<%= user.data.username %>", "test-chat-3");
|
|
28
28
|
|
|
29
29
|
chatTest.sendMessage("Hello, world!");
|
|
30
30
|
</script>
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
export default async (req, user, io) => {
|
|
2
|
-
|
|
3
|
-
let spirit = await req.
|
|
4
|
-
spirit.
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
await spirit.commit();
|
|
8
|
-
|
|
9
|
-
spirit = await req.db.Spirit.recallOrCreateOne("gold", user.memory._id);
|
|
10
|
-
spirit.addBackup({
|
|
11
|
-
amount: spirit.memory?.data?.amount != null ? spirit.memory.data.amount + 1 : 1
|
|
12
|
-
});
|
|
13
|
-
await spirit.commit();
|
|
2
|
+
if (!user) return "No user logged in";
|
|
3
|
+
let spirit = await req.Spirit.findOne({ service: "gold", parent: user._id });
|
|
4
|
+
await spirit.commit({ amount: spirit.data?.amount != null ? spirit.data.amount + 1 : 1 });
|
|
5
|
+
return spirit.data.amount;
|
|
14
6
|
}
|
package/test/the-front/index.ejs
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<input type="number" id="token">
|
|
17
17
|
<button onclick="test.continueTest()">Continue Test</button>
|
|
18
|
-
<button onclick="
|
|
18
|
+
<button onclick="addGold()">add gold</button>
|
|
19
19
|
<!-- download you data -->
|
|
20
20
|
<button onclick="downloadData()">Download Data</button>
|
|
21
21
|
<!-- delete all your data -->
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
<script>
|
|
43
43
|
let myGold = 0;
|
|
44
44
|
|
|
45
|
+
base.load("gold").then(loaded => {
|
|
46
|
+
myGold = loaded[0]?.data?.amount || 0;
|
|
47
|
+
$("#gold").text(`${myGold} Gold Added`);
|
|
48
|
+
});
|
|
49
|
+
|
|
45
50
|
class Test {
|
|
46
51
|
constructor() {
|
|
47
52
|
this.$info = $("main #info");
|
|
@@ -66,11 +71,6 @@
|
|
|
66
71
|
|
|
67
72
|
this.$info.append(this.newUsername + "<br>");
|
|
68
73
|
this.$info.append(this.newPassword + "<br>");
|
|
69
|
-
|
|
70
|
-
let loaded = await base.load("front-gold");
|
|
71
|
-
console.log("gold ", loaded);
|
|
72
|
-
myGold = loaded?.memory?.data?.amount || 0;
|
|
73
|
-
this.$gold.text(`${myGold} Gold Added`);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
runTest = async () => {
|
|
@@ -130,4 +130,10 @@
|
|
|
130
130
|
let res = await base.changeEmail(pass, email);
|
|
131
131
|
console.log(res.message);
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
let addGold = async () => {
|
|
135
|
+
myGold = myGold + 1;
|
|
136
|
+
let res = await base.do('add-gold', { amount: myGold, route: '/the-front' });
|
|
137
|
+
$("#gold").text(`${res.data} Gold Added`);
|
|
138
|
+
}
|
|
133
139
|
</script>
|
|
@@ -1,100 +1 @@
|
|
|
1
1
|
<h1>NotherBase 2</h1>
|
|
2
|
-
|
|
3
|
-
<p>
|
|
4
|
-
Welcome to The Front Test.
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<p id="gold">0 Gold Added</p>
|
|
8
|
-
|
|
9
|
-
<hr>
|
|
10
|
-
|
|
11
|
-
<h3>Test Accounts</h3>
|
|
12
|
-
<button onclick="test.runTest()">Run Test</button>
|
|
13
|
-
|
|
14
|
-
<p id="info"></p>
|
|
15
|
-
|
|
16
|
-
<input type="number" id="token">
|
|
17
|
-
<button onclick="test.continueTest()">Continue Test</button>
|
|
18
|
-
<button onclick="base.do('add-gold', { route: '/the-front' })">add gold</button>
|
|
19
|
-
<!-- download you data -->
|
|
20
|
-
<button onclick="base.downloadData()">Download Data</button>
|
|
21
|
-
<!-- delete all your data -->
|
|
22
|
-
<button onclick="base.deleteData($('#password').val())">Delete Data</button>
|
|
23
|
-
<!-- import your data -->
|
|
24
|
-
<button onclick="base.importData($('#password').val(), $('#fileInput')[0].files[0])">Import Data</button>
|
|
25
|
-
<input type="file" id="fileInput">
|
|
26
|
-
<!-- password input -->
|
|
27
|
-
<input type="test" id="password" placeholder="pass">
|
|
28
|
-
|
|
29
|
-
<hr>
|
|
30
|
-
|
|
31
|
-
<a href="/coast/tall-beach/nono-cove" class="to nother-base">
|
|
32
|
-
Go inside
|
|
33
|
-
</a>
|
|
34
|
-
|
|
35
|
-
<a href="/check">
|
|
36
|
-
Go to The Check
|
|
37
|
-
</a>
|
|
38
|
-
|
|
39
|
-
<script>
|
|
40
|
-
class Test {
|
|
41
|
-
constructor() {
|
|
42
|
-
this.$info = $("main #info");
|
|
43
|
-
this.$gold = $("#gold");
|
|
44
|
-
|
|
45
|
-
this.oldID = Math.floor(Math.random() * 1000);
|
|
46
|
-
this.oldUsername = `testuser00${this.oldID}`;
|
|
47
|
-
this.oldPassword = `password00${this.oldID}`;
|
|
48
|
-
|
|
49
|
-
this.newID = Math.floor(Math.random() * 1000);
|
|
50
|
-
this.newUsername = `testuser00${this.newID}`;
|
|
51
|
-
this.newPassword = `password00${this.newID}`;
|
|
52
|
-
|
|
53
|
-
this.prepTest();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
prepTest = async () => {
|
|
57
|
-
this.$info.empty();
|
|
58
|
-
|
|
59
|
-
this.$info.append(this.oldUsername + "<br>");
|
|
60
|
-
this.$info.append(this.oldPassword + "<br>");
|
|
61
|
-
|
|
62
|
-
this.$info.append(this.newUsername + "<br>");
|
|
63
|
-
this.$info.append(this.newPassword + "<br>");
|
|
64
|
-
|
|
65
|
-
let loaded = await base.load("gold", "global");
|
|
66
|
-
console.log("global gold ", loaded);
|
|
67
|
-
this.$gold.text(`?/${loaded?.memory?.data?.amount !== null ? loaded.memory.data.amount : 0} Gold Added`);
|
|
68
|
-
loaded = await base.loadAll("gold");
|
|
69
|
-
console.log("local gold ", loaded);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
runTest = async () => {
|
|
73
|
-
let response = await base.attemptRegister(this.oldUsername, this.oldPassword);
|
|
74
|
-
this.$info.append(response.message + "<br>");
|
|
75
|
-
|
|
76
|
-
response = await base.attemptLogin(this.oldUsername, this.oldPassword);
|
|
77
|
-
this.$info.append(response.message + "<br>");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
continueTest = async () => {
|
|
81
|
-
let response = await base.changePassword(
|
|
82
|
-
this.oldPassword,
|
|
83
|
-
this.newPassword,
|
|
84
|
-
this.newPassword
|
|
85
|
-
);
|
|
86
|
-
this.$info.append(response.message + "<br>");
|
|
87
|
-
|
|
88
|
-
response = await base.logout(true);
|
|
89
|
-
this.$info.append(response.message + "<br>");
|
|
90
|
-
|
|
91
|
-
response = await base.attemptLogin(this.oldUsername, this.newPassword);
|
|
92
|
-
this.$info.append(response.message + "<br>");
|
|
93
|
-
|
|
94
|
-
response = await base.logout(true);
|
|
95
|
-
this.$info.append(response.message + "<br>");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let test = new Test();
|
|
100
|
-
</script>
|
package/views/explorer.ejs
CHANGED
package/views/footer.ejs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
<footer>
|
|
3
3
|
<% if (user) { %>
|
|
4
|
-
<p class="login-status">Logged In: <%= user.
|
|
4
|
+
<p class="login-status">Logged In: <%= user.data.username %></p><button class="logout" onclick="base.logout()">Logout</button>
|
|
5
5
|
<% } else { %>
|
|
6
6
|
<p class="login-status">Not Logged In</p><button class="invisible logout" onclick="base.logout()">Logout</button>
|
|
7
7
|
<% } %>
|
package/controllers/creation.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creation is all the renedered pages in a base.
|
|
6
|
-
*/
|
|
7
|
-
export default class Creation {
|
|
8
|
-
constructor(bases = {}) {
|
|
9
|
-
this.bases = bases;
|
|
10
|
-
this.router = express.Router();
|
|
11
|
-
|
|
12
|
-
//home
|
|
13
|
-
this.router.get("/", this.front, this.explore);
|
|
14
|
-
|
|
15
|
-
//the-front
|
|
16
|
-
this.router.get(`/the-front`, this.front, this.explore);
|
|
17
|
-
this.router.get(`/the-front/:frontDetail`, this.frontDetail, this.explore);
|
|
18
|
-
|
|
19
|
-
//pages
|
|
20
|
-
// this.router.get(`/:page`, this.page, this.explore);
|
|
21
|
-
|
|
22
|
-
//the-front optional shortcuts
|
|
23
|
-
this.router.get(`/:frontDetail`, this.frontDetail, this.explore);
|
|
24
|
-
|
|
25
|
-
//explorer
|
|
26
|
-
this.router.get(`/:region/:area/:poi`, this.lock, this.poi, this.explore);
|
|
27
|
-
this.router.get(`/:region/:area/:poi/:detail`, this.lock, this.detail, this.explore);
|
|
28
|
-
|
|
29
|
-
//void
|
|
30
|
-
this.router.use(function(req, res) {
|
|
31
|
-
res.redirect("/void");
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* This middleware requires a user to login to access affected routes.
|
|
37
|
-
* @param {Object} req An Express.js request.
|
|
38
|
-
* @param {Object} res An Express.js response.
|
|
39
|
-
* @param {Function} next next()
|
|
40
|
-
*/
|
|
41
|
-
lock = (req, res, next) => {
|
|
42
|
-
req.lock = true;
|
|
43
|
-
next();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* This route renders a page and sends it to the client.
|
|
48
|
-
* @param {Object} req An Express.js request.
|
|
49
|
-
* @param {Object} res An Express.js response.
|
|
50
|
-
* @param {Function} next next()
|
|
51
|
-
*/
|
|
52
|
-
explore = async (req, res, next) => {
|
|
53
|
-
try {
|
|
54
|
-
if (fs.existsSync(req.main + ".ejs")) {
|
|
55
|
-
let stats = await req.db.Spirit.recallOrCreateOne("stats", null, { route: req.path });
|
|
56
|
-
if (stats.memory.data.visits) stats.memory.data.visits++;
|
|
57
|
-
else stats.memory.data.visits = 1;
|
|
58
|
-
await stats.commit();
|
|
59
|
-
|
|
60
|
-
let context = {
|
|
61
|
-
user: null,
|
|
62
|
-
siteTitle: req.siteTitle,
|
|
63
|
-
main: req.main,
|
|
64
|
-
query: req.query,
|
|
65
|
-
route: req.path,
|
|
66
|
-
requireUser: req.lock,
|
|
67
|
-
preprocessed: {}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (req.session.currentUser) {
|
|
71
|
-
let user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
|
|
72
|
-
context.user = {
|
|
73
|
-
memory: {
|
|
74
|
-
data: user.memory.data,
|
|
75
|
-
backups: user.memory.backups,
|
|
76
|
-
_id: user.memory._id,
|
|
77
|
-
parent: user.memory.parent,
|
|
78
|
-
service: user.memory.service,
|
|
79
|
-
_lastUpdate: user.memory._lastUpdate
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//preprocess
|
|
85
|
-
let preprocessScripts = fs.existsSync(req.preprocess) ? fs.readdirSync(req.preprocess) : [];
|
|
86
|
-
for (let preprocessScript of preprocessScripts) {
|
|
87
|
-
try {
|
|
88
|
-
let scriptPath = `${req.preprocess}/${preprocessScript}`;
|
|
89
|
-
|
|
90
|
-
if (fs.existsSync(scriptPath)) {
|
|
91
|
-
let script = await import(process.env.WINDOWS == "true" ? `file://${scriptPath}` : scriptPath);
|
|
92
|
-
let result = await script.default(req, context.user, this.io);
|
|
93
|
-
context.preprocessed[preprocessScript.split(".")[0]] = result;
|
|
94
|
-
}
|
|
95
|
-
else context.preprocessed[preprocessScript.split(".")[0]] = `Error: Script Not Found`;
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.log(error);
|
|
98
|
-
context.preprocessed[preprocessScript.split(".")[0]] = `Error: Server Error`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
res.render(req.toRender, context);
|
|
103
|
-
}
|
|
104
|
-
else next();
|
|
105
|
-
}
|
|
106
|
-
catch(err) {
|
|
107
|
-
console.log(err);
|
|
108
|
-
res.status(500).send("Server Error");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* This middleware directs exploration to the front.
|
|
114
|
-
* @param {Object} req An Express.js request.
|
|
115
|
-
* @param {Object} res An Express.js response.
|
|
116
|
-
* @param {Function} next next()
|
|
117
|
-
*/
|
|
118
|
-
front = async (req, res, next) => {
|
|
119
|
-
req.main = req.contentPath + "/the-front/index";
|
|
120
|
-
req.preprocess = req.contentPath + "/the-front/_preprocess";
|
|
121
|
-
req.siteTitle = this.bases[req.hosting].title;
|
|
122
|
-
req.toRender = "explorer";
|
|
123
|
-
next();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* This middleware directs exploration to a detail in the front.
|
|
128
|
-
* @param {Object} req An Express.js request.
|
|
129
|
-
* @param {Object} res An Express.js response.
|
|
130
|
-
* @param {Function} next next()
|
|
131
|
-
*/
|
|
132
|
-
frontDetail = async (req, res, next) => {
|
|
133
|
-
req.main = `${req.contentPath}/the-front/${req.params.frontDetail}/index`;
|
|
134
|
-
req.preprocess = `${req.contentPath}/the-front/${req.params.frontDetail}/_preprocess`;
|
|
135
|
-
req.siteTitle = `${this.bases[req.hosting].title} - ${req.params.frontDetail}`;
|
|
136
|
-
req.toRender = "explorer";
|
|
137
|
-
next();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* This middleware directs exploration to a point of interest.
|
|
142
|
-
* @param {Object} req An Express.js request.
|
|
143
|
-
* @param {Object} res An Express.js response.
|
|
144
|
-
* @param {Function} next next()
|
|
145
|
-
*/
|
|
146
|
-
poi = async (req, res, next) => {
|
|
147
|
-
req.main = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/index`;
|
|
148
|
-
req.preprocess = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/_preprocess`;
|
|
149
|
-
req.siteTitle = `${this.bases[req.hosting].title} - ${req.params.poi}`;
|
|
150
|
-
req.toRender = "explorer";
|
|
151
|
-
next();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* This middleware directs exploration to a detail.
|
|
156
|
-
* @param {Object} req An Express.js request.
|
|
157
|
-
* @param {Object} res An Express.js response.
|
|
158
|
-
* @param {Function} next next()
|
|
159
|
-
*/
|
|
160
|
-
detail = async (req, res, next) => {
|
|
161
|
-
req.main = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/index`;
|
|
162
|
-
req.preprocess = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/_preprocess`;
|
|
163
|
-
req.siteTitle = `${this.bases[req.hosting].title} - ${req.params.detail}`;
|
|
164
|
-
req.toRender = "explorer";
|
|
165
|
-
next();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* This middleware directs exploration to a one-off page.
|
|
170
|
-
* @param {Object} req An Express.js request.
|
|
171
|
-
* @param {Object} res An Express.js response.
|
|
172
|
-
* @param {Function} next next()
|
|
173
|
-
*/
|
|
174
|
-
// page = async (req, res, next) => {
|
|
175
|
-
// req.main = `${req.contentPath}/pages/${req.params.page}/index`;
|
|
176
|
-
// req.preprocess = `${req.contentPath}/pages/${req.params.page}/_preprocess`;
|
|
177
|
-
// req.siteTitle = `${req.params.page}`;
|
|
178
|
-
// req.toRender = req.main;
|
|
179
|
-
// next();
|
|
180
|
-
// }
|
|
181
|
-
}
|