notherbase-fs 1.0.38 → 1.0.39

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.
@@ -0,0 +1,111 @@
1
+ const express = require("express");
2
+ const router = express.Router();
3
+ const bcrypt = require("bcrypt");
4
+
5
+ // Import my Data
6
+ const User = require("./models.js").user;
7
+ const inventory = require("../../models/inventory");
8
+
9
+ const authCheck = require("../authCheck");
10
+
11
+ router.post("/register", async function(req, res) {
12
+ try {
13
+ const foundAccount = await User.findOne({ username: req.body.username });
14
+
15
+ if (!foundAccount) {
16
+ const salt = await bcrypt.genSalt(10);
17
+ const hash = await bcrypt.hash(req.body.password, salt);
18
+
19
+ let qAuth = await User.create({
20
+ username: req.body.username,
21
+ password: hash,
22
+ email: "temp@example.com",
23
+ coin: 0,
24
+ home: "/",
25
+ authLevels: [ "Basic" ]
26
+ });
27
+
28
+ await inventory.create({
29
+ user: qAuth._id,
30
+ items: []
31
+ });
32
+
33
+ res.status(200).send("Registration Successful!");
34
+ }
35
+ else {
36
+ res.status(400).send("Registration Failed: Username taken!");
37
+ }
38
+ }
39
+ catch(err) {
40
+ console.log(err);
41
+
42
+ res.status(500).send("Registration Failed: Database error!");
43
+ }
44
+ });
45
+
46
+ router.post("/login", async function(req, res) {
47
+ try {
48
+ const foundAccount = await User.findOne({ username: req.body.username });
49
+
50
+ if (foundAccount) {
51
+ if (await bcrypt.compare(req.body.password, foundAccount.password)) {
52
+ req.session.currentUser = { _id: foundAccount._id };
53
+ req.session.currentUserFull = foundAccount;
54
+
55
+ res.status(200).send("Login successful!");
56
+ }
57
+ else {
58
+ res.status(401).send("Login Failed: Password incorrect!");
59
+ }
60
+ }
61
+ else {
62
+ res.status(401).send("Login Failed: Username not found!");
63
+ }
64
+ }
65
+ catch(err) {
66
+ console.log(err);
67
+
68
+ res.status(500).send("Login Failed: Database error!");
69
+ }
70
+ });
71
+
72
+ router.get("/logout", authCheck, async function(req, res) {
73
+ try {
74
+ await req.session.destroy();
75
+
76
+ res.redirect(`/`);
77
+ }
78
+ catch {
79
+ console.log(err);
80
+ }
81
+ });
82
+
83
+ router.get("/all", authCheck, async function(req, res) {
84
+ try {
85
+ let foundUsers = await User.find({}, 'username coin home authLevels location');
86
+
87
+ res.status(200).send({ foundUsers: foundUsers });
88
+ }
89
+ catch(err) {
90
+ res.status(500).end();
91
+ console.log(err);
92
+ }
93
+ });
94
+
95
+ router.delete("/", authCheck, async function(req, res) {
96
+ try {
97
+ const found = await User.findByIdAndDelete(req.session.currentUser);
98
+
99
+ if (!found) console.log("Could not find account. No deletion!");
100
+
101
+ await req.session.destroy();
102
+
103
+ res.redirect("/");
104
+ }
105
+ catch {
106
+ console.log(err);
107
+ }
108
+ });
109
+
110
+ module.exports = router;
111
+
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ explore: function explore(path) {
3
+ return require(`./${path}/${path}.js`)
4
+ },
5
+ data: require("./models"),
6
+ chat: null,
7
+ start: function (world) {
8
+ let theFront = require("the-front");
9
+ let explorer = require("explorer");
10
+
11
+ explorer.complete(world.explorer);
12
+ theFront.complete(world.theFront);
13
+
14
+ require("server")(theFront.router, explorer.router);
15
+ }
16
+ }
package/models/chat.js ADDED
@@ -0,0 +1,13 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ //get schema template
4
+ const Schema = mongoose.Schema;
5
+ const chatSchema = new Schema({
6
+ name: String,
7
+ text: String,
8
+ date: Number
9
+ });
10
+
11
+ module.exports = {
12
+ chat: mongoose.model('chat', chatSchema)
13
+ };
@@ -0,0 +1,17 @@
1
+ // This allows us to use Mongoose to connect to MongoDB
2
+ const mongoose = require("mongoose");
3
+
4
+ // This shows the kind of documents we're interacting with in the db
5
+ const contact = new mongoose.Schema({
6
+ user: {
7
+ type: mongoose.Schema.Types.ObjectId,
8
+ ref: "users",
9
+ required: true
10
+ },
11
+ location: String,
12
+ content: String
13
+ });
14
+
15
+ // This tells Mongoose to use the exampleSchema to access the examples collection
16
+ // in our db and then exports the model so we can use it.
17
+ module.exports = mongoose.model('contacts', contact);
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ chat: require("chat"),
3
+ item: require("item"),
4
+ user: require("user"),
5
+ contact: require("contact"),
6
+ explorer: require("explorer"),
7
+ front: require("the-front"),
8
+ inventory: require("inventory"),
9
+ }
10
+
11
+ require("start-mongoose");
@@ -0,0 +1,22 @@
1
+ // This allows us to use Mongoose to connect to MongoDB
2
+ const mongoose = require("mongoose");
3
+
4
+ // This shows the kind of documents we're interacting with in the db
5
+ const inventory = new mongoose.Schema({
6
+ user: {
7
+ type: mongoose.Schema.Types.ObjectId,
8
+ ref: "users",
9
+ required: true
10
+ },
11
+ items: [{
12
+ item: {
13
+ type: mongoose.Schema.Types.ObjectId,
14
+ ref: "items"
15
+ },
16
+ amount: Number
17
+ }]
18
+ });
19
+
20
+ // This tells Mongoose to use the exampleSchema to access the examples collection
21
+ // in our db and then exports the model so we can use it.
22
+ module.exports = mongoose.model('inventories', inventory);
package/models/item.js ADDED
@@ -0,0 +1,12 @@
1
+ // This allows us to use Mongoose to connect to MongoDB
2
+ const mongoose = require("mongoose");
3
+
4
+ const item = new mongoose.Schema({
5
+ name: String,
6
+ shortDescription: String,
7
+ fullDescription: String
8
+ });
9
+
10
+ // This tells Mongoose to use the exampleSchema to access the examples collection
11
+ // in our db and then exports the model so we can use it.
12
+ module.exports = mongoose.model('items', item);
@@ -0,0 +1,22 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ //connect mongoose and mongo
4
+ mongoose.connect(process.env.MONGODB_URI, {
5
+ useNewUrlParser: true,
6
+ useUnifiedTopology: true,
7
+ useCreateIndex: true,
8
+ useFindAndModify: false,
9
+ });
10
+
11
+ //handlers
12
+ mongoose.connection.on('connected', () => {
13
+ console.log(`Mongoose connected to db`);
14
+ });
15
+
16
+ mongoose.connection.on('error', (err) => {
17
+ console.log(`Mongoose connected error ${err}`);
18
+ });
19
+
20
+ mongoose.connection.on('disconnected', () => {
21
+ console.log('Mongoose disconnected');
22
+ });
package/models/user.js ADDED
@@ -0,0 +1,16 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ //convert schema to model
4
+ const user = mongoose.model('users',
5
+ new mongoose.Schema({
6
+ username: String,
7
+ password: String,
8
+ email: String,
9
+ coin: Number,
10
+ home: String,
11
+ authLevels: [ String ],
12
+ location: String
13
+ })
14
+ );
15
+
16
+ module.exports = { user: user };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
- "main": "main.js",
5
+ "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
@@ -17,6 +17,15 @@
17
17
  },
18
18
  "homepage": "https://github.com/Mosshide/notherbase-fs#readme",
19
19
  "dependencies": {
20
- "express": "^4.17.1"
20
+ "bcrypt": "^5.0.1",
21
+ "connect-mongo": "^4.6.0",
22
+ "dotenv": "^14.2.0",
23
+ "ejs": "^3.1.6",
24
+ "express": "^4.17.1",
25
+ "express-session": "^1.17.2",
26
+ "method-override": "^3.0.0",
27
+ "mongoose": "^6.1.7",
28
+ "serve-favicon": "^2.5.0",
29
+ "socket.io": "^4.4.1"
21
30
  }
22
31
  }
Binary file
@@ -0,0 +1,60 @@
1
+ .chat-box {
2
+ position: relative;
3
+ box-shadow: 5px 5px 10px 5px var(--shadowColor);
4
+ margin-top: 20px;
5
+ width: 100%;
6
+ min-height: 200px;
7
+ }
8
+
9
+ .chat-name {
10
+ color: var(--textColor);
11
+ padding: 10px;
12
+ }
13
+
14
+ .chat-log {
15
+ width: 100%;
16
+ height: calc(100% - 65px);
17
+ background-color: rgba(0, 0, 0, 0.534);
18
+ overflow: auto;
19
+ padding: 5px;
20
+ }
21
+
22
+ .chat-send {
23
+ position: absolute;
24
+ right: 0;
25
+ bottom: 0;
26
+ height: 25px;
27
+ width: 5em;
28
+ outline: none;
29
+ background-color: var(--bgColor);
30
+ border: 1px solid var(--textColor);
31
+ color: var(--textColor);
32
+ text-align: center;
33
+ padding: 2px;
34
+ }
35
+
36
+ .chat-send:hover {
37
+ border: 1px solid var(--textColorBright);
38
+ color: var(--textColorBright);
39
+ cursor: pointer;
40
+ }
41
+
42
+ .chat-entry {
43
+ position: absolute;
44
+ left: 0;
45
+ bottom: 0;
46
+ height: 25px;
47
+ width: calc(100% - 5em);
48
+ outline: none;
49
+ background-color: var(--bgColor);
50
+ border: 1px solid var(--textColor);
51
+ color: var(--textColor);
52
+ }
53
+
54
+ .chat-log > p {
55
+ color: var(--textColor);
56
+ margin: 0;
57
+ padding: 0;
58
+ line-height: 1em;
59
+ text-align: left;
60
+ }
@@ -0,0 +1,328 @@
1
+ :root {
2
+ --bgColor: rgb(37, 37, 37);
3
+ --darkBgColor: rgb(27, 27, 27);
4
+ --veryDarkBgColor: rgb(15, 15, 15);
5
+ --lightBgColor: rgb(57, 57, 57);
6
+ --shadowColor: rgb(26, 26, 26);
7
+ --textColor: rgb(185, 135, 69);
8
+ --textColorBright: rgb(221, 181, 130);
9
+ --woodColor: rgb(95, 68, 43);
10
+ --darkWoodColor: rgb(70, 50, 32);
11
+ }
12
+
13
+ * {
14
+ box-sizing: border-box;
15
+ margin: 0;
16
+ padding: 0;
17
+ color: var(--textColor);
18
+ }
19
+
20
+ .invisible {
21
+ display: none !important;
22
+ }
23
+
24
+ body {
25
+ background-color: var(--darkBgColor);
26
+ min-height: 100vh;
27
+ display: flex;
28
+ justify-content: center;
29
+ align-items: center;
30
+ align-content: center;
31
+ flex-direction: column;
32
+ position: relative;
33
+ }
34
+
35
+ main {
36
+ width: 500px;
37
+ min-height: 500px;
38
+ box-shadow: 5px 5px 5px 5px var(--shadowColor);
39
+ padding: 20px;
40
+ border-radius: 5px 5px 0px 0px;
41
+ margin-top: 15px;
42
+ margin-bottom: 0;
43
+ display: flex;
44
+ flex-wrap: wrap;
45
+ justify-content: center;
46
+ align-content: center;
47
+ align-items: flex-start;
48
+ background-color: var(--bgColor);
49
+ }
50
+
51
+ footer {
52
+ display: flex;
53
+ justify-content: center;
54
+ align-content: center;
55
+ align-items: flex-start;
56
+ min-height: 25px;
57
+ width: 500px;
58
+ background-color: var(--veryDarkBgColor);
59
+ border-radius: 0px 0px 5px 5px;
60
+ box-shadow: 5px 5px 5px 5px var(--shadowColor);
61
+ padding: 5px;
62
+ border: none;
63
+ margin-bottom: 100px;
64
+ }
65
+
66
+ footer a {
67
+ text-decoration: none;
68
+ height: 100%;
69
+ margin: 0;
70
+ padding: 5px;
71
+ width: 50%;
72
+ height: 100%;
73
+ }
74
+
75
+ hr {
76
+ border: none;
77
+ border-bottom: 1px solid var(--textColor);
78
+ margin: 20px;
79
+ width: 100%;
80
+ }
81
+
82
+ p {
83
+ color: var(--textColor);
84
+ margin-bottom: 10px;
85
+ width: 80%;
86
+ }
87
+
88
+ input, textarea {
89
+ padding: 10px;
90
+ width: calc(100% - 10px);
91
+ background-color: var(--bgColor);
92
+ border-radius: 5px;
93
+ border: 1px solid var(--textColor);
94
+ margin: 5px;
95
+ font-size: 15px;
96
+ }
97
+
98
+ input[type=submit], button, a {
99
+ background-color: var(--bgColor);
100
+ padding: 10px;
101
+ border-radius: 5px;
102
+ border: 1px solid var(--textColor);
103
+ color: var(--textColor);
104
+ margin: 5px;
105
+ margin-top: 20px;
106
+ text-decoration: none;
107
+ text-align: center;
108
+ }
109
+
110
+ input[type=submit]:hover, button:hover, a:hover {
111
+ border: 1px solid var(--textColorBright);
112
+ color: var(--textColorBright);
113
+ cursor: pointer;
114
+ }
115
+
116
+ .locked {
117
+ background-color: var(--bgColor);
118
+ padding: 10px;
119
+ border-radius: 5px;
120
+ border: 1px solid var(--textColor);
121
+ color: var(--textColor);
122
+ margin: 5px;
123
+ margin-top: 20px;
124
+ text-decoration: none;
125
+ text-align: center;
126
+ filter: brightness(.5);
127
+ user-select: none;
128
+ }
129
+
130
+ .to {
131
+ width: 100%;
132
+ height: 200px;
133
+ display: flex;
134
+ justify-content: flex-end;
135
+ align-items: flex-end;
136
+ padding: 20px;
137
+ }
138
+
139
+ .return {
140
+ width: 100%;
141
+ height: 75px;
142
+ display: flex;
143
+ justify-content: flex-end;
144
+ align-items: flex-end;
145
+ padding: 20px;
146
+ }
147
+
148
+ .do {
149
+ width: 100%;
150
+ height: 200px;
151
+ display: flex;
152
+ justify-content: flex-end;
153
+ align-items: flex-end;
154
+ padding: 20px;
155
+ }
156
+
157
+ h2, h3 {
158
+ color: var(--textColor);
159
+ width: 100%;
160
+ }
161
+
162
+ ul {
163
+ margin: 10px;
164
+ }
165
+
166
+
167
+ #contact {
168
+ position: fixed;
169
+ bottom: 30px;
170
+ left: 5px;
171
+ width: 64px;
172
+ height: 64px;
173
+ }
174
+
175
+ #contact-form {
176
+ width: 100%;
177
+ border: 1px solid var(--textColor);
178
+ color: var(--textColor);
179
+ position: fixed;
180
+ width: 90%;
181
+ height: 30%;
182
+ left: 5%;
183
+ bottom: 105px;
184
+ background-color: var(--bgColor);
185
+ padding: 5px;
186
+ border-radius: 5px;
187
+ z-index: 500;
188
+ display: flex;
189
+ flex-wrap: wrap;
190
+ overflow: auto;
191
+ }
192
+
193
+ .inventory {
194
+ width: 100%;
195
+ border: 1px solid var(--textColor);
196
+ color: var(--textColor);
197
+ position: fixed;
198
+ width: 90%;
199
+ height: 30%;
200
+ left: 5%;
201
+ bottom: 105px;
202
+ background-color: var(--bgColor);
203
+ padding: 5px;
204
+ border-radius: 5px;
205
+ z-index: 500;
206
+ display: flex;
207
+ flex-wrap: wrap;
208
+ overflow: auto;
209
+ }
210
+
211
+ .inventory .item-list {
212
+ width: 100%;
213
+ display: flex;
214
+ flex-wrap: wrap;
215
+ overflow: auto;
216
+ border: 1px solid var(--textColor);
217
+ }
218
+
219
+ .inventory .item-spawner {
220
+ width: 100%;
221
+ border: 1px solid var(--textColor);
222
+ }
223
+
224
+ .item-spawner .search-results {
225
+ width: 100%;
226
+ border: 1px solid var(--textColor);
227
+ overflow: auto;
228
+ }
229
+
230
+ .search-results p {
231
+ width: 100%;
232
+ cursor: pointer;
233
+ }
234
+
235
+ .search-results p:hover {
236
+ background-color: var(--woodColor);
237
+ }
238
+
239
+ #inventory-button {
240
+ position: fixed;
241
+ bottom: 30px;
242
+ right: 5px;
243
+ width: 64px;
244
+ height: 64px;
245
+ }
246
+
247
+ .item-card {
248
+ width: 100px;
249
+ height: 100px;
250
+ border-radius: 5px;
251
+ border: 1px solid var(--textColor);
252
+ padding: 10px;
253
+ margin: 5px;
254
+ position: relative;
255
+ }
256
+
257
+ .item-card button {
258
+ position: absolute;
259
+ right: 0;
260
+ top: 0;
261
+ margin: 0;
262
+ padding: 0;
263
+ }
264
+
265
+ .item-card hr {
266
+ margin: 5px -10px;
267
+ width: calc(100% + 20px);
268
+ }
269
+
270
+ .door {
271
+ border: 1px solid var(--darkWoodColor);
272
+ width: 100px;
273
+ height: 150px;
274
+ background-color: var(--woodColor);
275
+ position: relative;
276
+ }
277
+
278
+ .knob {
279
+ position: absolute;
280
+ width: 20px;
281
+ height: 20px;
282
+ border-radius: 50%;
283
+ right: 5px;
284
+ top: 50%;
285
+ background-color: var(--darkWoodColor);
286
+ }
287
+
288
+ iframe {
289
+ border: none;
290
+ }
291
+
292
+ .auth-form {
293
+ height: 100%;
294
+ width: 100%;
295
+ padding: 40px 5px;
296
+ overflow: hidden;
297
+ display: flex;
298
+ justify-content: center;
299
+ flex-wrap: wrap;
300
+ }
301
+
302
+
303
+ .auth-form h3 {
304
+ width: calc(100% - 20px);
305
+ text-align: center;
306
+ margin: 10px;
307
+ font-size: 15px;
308
+ }
309
+
310
+ .auth-form h1 {
311
+ width: calc(100% - 20px);
312
+ text-align: center;
313
+ margin: 10px;
314
+ font-size: 20px;
315
+ }
316
+
317
+ .auth-form p {
318
+ width: calc(100% - 20px);
319
+ text-align: center;
320
+ margin: 10px;
321
+ font-size: 12px;
322
+ }
323
+
324
+ @media only screen and (max-width: 500px) {
325
+ main {
326
+ width: 100%;
327
+ }
328
+ }