diff --git a/README.md b/README.md index c19bee7..a8e954b 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,22 @@ # XP-System -School Project -This school project is for my teacher to have students -log in and check out their XP and assignments. +This school project is for my teacher to have students log in and check out their XP and assignments. This website application is not available online, this is just a locally run website at our school. -To create a teacher, it must be done by a site admin. You'll need to create the site admin in the -database in a collection called `users` and set insert a document formatted as shown: -` -{ - "_id": your generated id, +To create a teacher, it must be done by a site admin. + +You'll need to create the site admin in the database in a collection called users, +and insert a document via MongoDB Compass. Format the document as shown: +`{ "role": "Admin", "name": your name, "email": your email, "password": your encrypted password -} -` + }` + +Replace `your name` with the name you specify, `your email` with the email you would like to use to login, +and replace `your encrypted password` with your [Encrypted Password](#Encrypting Your Password) + +The ID for your admin document should be auto generated by MongoDB Compass when you `insert` the document. ### Requirements : 1. [Node.js](https://nodejs.org/en/) @@ -28,7 +30,15 @@ database in a collection called `users` and set insert a document formatted as s 1. Run `npm start` to boot up server. 1. Go to http://localhost:8080. Or Whatever you set it to in the `.env` file. +### Setting up MongoDB +1. Install mongodb and follow the setup steps. +1. [Step by step instructions](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows) + ### Accessing the Database 1. Locally this will use any db you set the DB_URI to in the `.env` file. 1. You can use MongoDB compass app to view the db and edit any information stored. 2. Or connect it to an external db by changing the DB_URI in the `.env` to your db key. + +### Encrypting Your Password +1. To encrypt your password while creating the admin account. Go into the `config` folder, +1. follow the instructions in encrypt.js and run encrypt.js via node `node encrypt.js` diff --git a/config/encrypt.js b/config/encrypt.js new file mode 100644 index 0000000..27ef8b8 --- /dev/null +++ b/config/encrypt.js @@ -0,0 +1,13 @@ +const bcrypt = require('bcryptjs'); + +// Set `password` as the password you will use +// Then Run this script and copy the output as it is your encrypted password +let password = "APPLEZ57"; + +// Encrypts password and returns encrypted password +bcrypt.genSalt(10, (err, salt) => { + bcrypt.hash(password, salt, (err, hash) => { + if (err) throw err; + console.log(hash); + }); +}); diff --git a/routes/users.js b/routes/users.js index 3955cff..57bd25d 100644 --- a/routes/users.js +++ b/routes/users.js @@ -224,7 +224,7 @@ router.post('/addXP', (req, res, next) => { // Edit router.post('/edit', upload.single('image'), (req, res, next) => { // Passes image path to defaultImage Model - imagePath = __dirname + '/uploads/default-image'; + let imagePath = __dirname + '/uploads/default-image'; module.exports = { defaultPath: imagePath } @@ -426,7 +426,7 @@ router.post('/edit', upload.single('image'), (req, res, next) => { // Register Teacher router.post('/registerTeacher', upload.single('image'), (req, res, next) => { // Passes image path to defaultImage Model - imagePath = __dirname + '/uploads/default-image'; + let imagePath = __dirname + '/uploads/default-image'; module.exports = { defaultPath: imagePath } @@ -565,7 +565,7 @@ router.post('/registerTeacher', upload.single('image'), (req, res, next) => { // Register router.post('/register', upload.single('image'), (req, res, next) => { // Passes image path to defaultImage Model - imagePath = __dirname + '/uploads/default-image'; + let imagePath = __dirname + '/uploads/default-image'; module.exports = { defaultPath: imagePath } diff --git a/views/dashboard.ejs b/views/dashboard.ejs index 986d7ba..47ef569 100644 --- a/views/dashboard.ejs +++ b/views/dashboard.ejs @@ -1,3 +1,4 @@ + <% if (user.role == "Admin") { %> <% include admin %> diff --git a/views/quests.ejs b/views/quests.ejs index 183aa02..6b6ddcb 100644 --- a/views/quests.ejs +++ b/views/quests.ejs @@ -17,16 +17,20 @@ const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const id = urlParams.get('id'); - <% quests.forEach(function (quest) { %> - if('<%= quest._id %>' == id) { - document.getElementById('div-container').innerHTML += '
XP: <%= quest.xp %>
'; - document.getElementById('quest').innerHTML += 'Expires: <%= quest.expiry %>
'; - document.getElementById('quest').innerHTML += 'XP: <%= quest.xp %>
'; + document.getElementById('quest').innerHTML += 'Expires: <%= quest.expiry %>
'; + document.getElementById('quest').innerHTML += `