Update
This commit is contained in:
parent
4dfd8cd516
commit
5a64568824
22 changed files with 702 additions and 194 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -40,6 +40,7 @@ npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
testem.log
|
testem.log
|
||||||
/typings
|
/typings
|
||||||
|
*.env
|
||||||
|
|
||||||
# System Files
|
# System Files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@ WORKDIR /app-backend
|
||||||
COPY ["package.json", "package-lock.json*", "./"]
|
COPY ["package.json", "package-lock.json*", "./"]
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY . .
|
COPY . .
|
||||||
|
CMD ./app/jwtRS256.sh
|
||||||
CMD node server.js
|
CMD node server.js
|
||||||
|
|
|
||||||
3
backend/app/config/mongodb.config.js
Normal file
3
backend/app/config/mongodb.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
url: "mongodb://127.0.0.1:27017/polynotfound"
|
||||||
|
};
|
||||||
9
backend/app/config/response.config.js
Normal file
9
backend/app/config/response.config.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
function sendMessage (res, successCode, data) {
|
||||||
|
return res.status(200).json({ status: 'success', successCode: successCode, data: data });
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendError (res, statusCode, errorCode, reason) {
|
||||||
|
return res.status(statusCode).json({ status: 'error', errorCode: errorCode, reason: reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { sendMessage, sendError };
|
||||||
67
backend/app/config/sessionJWT.config.js
Normal file
67
backend/app/config/sessionJWT.config.js
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
const sessionJWTConfig = require ('jsonwebtoken');
|
||||||
|
require('dotenv').config({ path: './app/.env' });
|
||||||
|
const {sendError, sendMessage} = require ("./response.config");
|
||||||
|
|
||||||
|
if(process.env.JWTRS256_PRIVATE_KEY === undefined || process.env.JWTRS256_PUBLIC_KEY === undefined){
|
||||||
|
console.log('Error Env Variables');
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Env variables received');
|
||||||
|
const JWTRS256_PRIVATE_KEY = Buffer.from(process.env.JWTRS256_PRIVATE_KEY, 'base64');
|
||||||
|
const JWTRS256_PUBLIC_KEY = Buffer.from(process.env.JWTRS256_PUBLIC_KEY, 'base64');
|
||||||
|
|
||||||
|
function createSessionJWT (mail) {
|
||||||
|
return sessionJWTConfig.sign(
|
||||||
|
{
|
||||||
|
mail: mail,
|
||||||
|
midExp: Math.floor(Date.now() / 1000) + 1800
|
||||||
|
},
|
||||||
|
JWTRS256_PRIVATE_KEY,
|
||||||
|
{
|
||||||
|
algorithm: 'RS256',
|
||||||
|
expiresIn: '1h'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSessionCookie(req, res, payload) {
|
||||||
|
let jwtToken;
|
||||||
|
if ((typeof payload.mail !== 'undefined') &&
|
||||||
|
(typeof payload.midExp !== 'undefined') &&
|
||||||
|
(Math.floor(Date.now() / 1000) <= payload.midExp)) {
|
||||||
|
jwtToken = req.headers.cookie;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jwtToken = createSessionJWT(payload.mail);
|
||||||
|
}
|
||||||
|
res.cookie('SESSIONID', jwtToken, {httpOnly:true, secure:false});
|
||||||
|
}
|
||||||
|
module.exports.createSessionCookie = createSessionCookie;
|
||||||
|
|
||||||
|
function decodeSessionCookie(sessionid, res) {
|
||||||
|
if (typeof sessionid === 'undefined') {
|
||||||
|
return { mail: -1 };
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const token = sessionJWTConfig.verify(
|
||||||
|
sessionid,
|
||||||
|
JWTRS256_PUBLIC_KEY,
|
||||||
|
{algorithms: ['RS256']});
|
||||||
|
return sendMessage(res,1,{token: token});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return sendError(res,-1,{mail: -1});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports.decodeSessionCookie = decodeSessionCookie;
|
||||||
|
|
||||||
|
function getSession (sessionid, res) {
|
||||||
|
return decodeSessionCookie(sessionid, res);
|
||||||
|
}
|
||||||
|
module.exports.getSession = getSession;
|
||||||
|
|
||||||
|
function setSessionCookie (req, res, session) {
|
||||||
|
createSessionCookie(req, res, session);
|
||||||
|
}
|
||||||
|
module.exports.setSessionCookie = setSessionCookie;
|
||||||
117
backend/app/controllers/tutorial.controller.js
Normal file
117
backend/app/controllers/tutorial.controller.js
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
const db = require("../models/mongodb.model");
|
||||||
|
const {sendError, sendMessage} = require ("../config/response.config");
|
||||||
|
const Tutorial = db.tutorials;
|
||||||
|
|
||||||
|
// Create and Save a new Tutorial
|
||||||
|
exports.create = (req, res) => {
|
||||||
|
// Validate request
|
||||||
|
if (!req.body.title) {
|
||||||
|
sendError(res, 400,-1,"Content can not be empty!" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a Tutorial
|
||||||
|
const tutorial = new Tutorial({
|
||||||
|
title: req.body.title,
|
||||||
|
description: req.body.description,
|
||||||
|
published: req.body.published ? req.body.published : false
|
||||||
|
});
|
||||||
|
|
||||||
|
// Save Tutorial in the database
|
||||||
|
tutorial
|
||||||
|
.save(tutorial)
|
||||||
|
.then(data => {
|
||||||
|
sendMessage(res, 1, data)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res, 500,-1,err.message || "Some error occurred while creating the Tutorial.");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retrieve all Tutorials from the database.
|
||||||
|
exports.findAll = (req, res) => {
|
||||||
|
const title = req.query.title;
|
||||||
|
let condition = title ? { title: { $regex: new RegExp(title), $options: "i" } } : {};
|
||||||
|
|
||||||
|
Tutorial.find(condition)
|
||||||
|
.then(data => {
|
||||||
|
sendMessage(res, 1, data)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Some error occurred while retrieving tutorials.");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Find a single Tutorial with an id
|
||||||
|
exports.findOne = (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
Tutorial.findById(id)
|
||||||
|
.then(data => {
|
||||||
|
if (!data)
|
||||||
|
sendError(res,404,-1,"Not found Tutorial with id " + id );
|
||||||
|
else sendMessage(res, 1, data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Error retrieving Tutorial with id=" + id );
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update a Tutorial by the id in the request
|
||||||
|
exports.update = (req, res) => {
|
||||||
|
if (!req.body) {
|
||||||
|
sendError(res,400,-1,"Data to update can not be empty!");
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
Tutorial.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||||
|
.then(data => {
|
||||||
|
if (!data) {
|
||||||
|
sendError(res,404,-1,`Cannot update Tutorial with id=${id}. Maybe Tutorial was not found!`);
|
||||||
|
} else sendMessage(res, 1, { message: "Tutorial was updated successfully." });
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Error updating Tutorial with id=" + id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Delete a Tutorial with the specified id in the request
|
||||||
|
exports.delete = (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
Tutorial.findByIdAndRemove(id)
|
||||||
|
.then(data => {
|
||||||
|
if (!data) {
|
||||||
|
sendError(res,404,-1,`Cannot delete Tutorial with id=${id}. Maybe Tutorial was not found!`);
|
||||||
|
} else {
|
||||||
|
sendMessage(res, 1, { message: "Tutorial was deleted successfully!" });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Could not delete Tutorial with id=" + id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Delete all Tutorials from the database.
|
||||||
|
exports.deleteAll = (req, res) => {
|
||||||
|
Tutorial.deleteMany({})
|
||||||
|
.then(data => {
|
||||||
|
sendMessage(res, 1, {
|
||||||
|
message: `${data.deletedCount} Tutorials were deleted successfully!`
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Some error occurred while removing all tutorials.");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Find all published Tutorials
|
||||||
|
exports.findAllPublished = (req, res) => {
|
||||||
|
Tutorial.find({ published: true })
|
||||||
|
.then(data => {
|
||||||
|
sendMessage(res, 1, data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Some error occurred while retrieving tutorials.");
|
||||||
|
});
|
||||||
|
};
|
||||||
148
backend/app/controllers/user.controller.js
Normal file
148
backend/app/controllers/user.controller.js
Normal file
|
|
@ -0,0 +1,148 @@
|
||||||
|
const db = require("../models/mongodb.model");
|
||||||
|
const {sendError, sendMessage} = require ("../config/response.config");
|
||||||
|
const sessionJWT = require('../config/sessionJWT.config');
|
||||||
|
const User = db.users;
|
||||||
|
|
||||||
|
|
||||||
|
// Authenticate an User
|
||||||
|
exports.auth = (req, res) => {
|
||||||
|
// Validate request
|
||||||
|
if (!req.body.mail || !req.body.hashPass) {
|
||||||
|
sendError(res, 400,-1,"Content can not be empty ! (mail and hashPass needed)");
|
||||||
|
} else{
|
||||||
|
// Check User in the database
|
||||||
|
User
|
||||||
|
.findOne({mail: req.body.mail, hashPass: req.body.hashPass}, [{count: {$size: "$_id"}}])
|
||||||
|
.then(data => {
|
||||||
|
if (data !== null){
|
||||||
|
sessionJWT.setSessionCookie(req, res, { mail: req.body.mail });
|
||||||
|
return sendMessage(res, 1, true);
|
||||||
|
} else {
|
||||||
|
sessionJWT.setSessionCookie(req, res, { mail: -1 });
|
||||||
|
return sendError(res, -1, "Invalid mail or password.");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res, 500,-1,err.message || "Some error occurred while authenticating the User.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create and Save a new User
|
||||||
|
exports.create = (req, res) => {
|
||||||
|
// Validate request
|
||||||
|
if (!req.body.login || !req.body.hashPass || !req.body.mail || !req.body.role) {
|
||||||
|
sendError(res, 400,-1,"Content can not be empty ! (login, hashPass, mail and role needed");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
User.exists({login: req.body.login}, function (err, docs){
|
||||||
|
if(err){
|
||||||
|
sendError(res, 500,-1,err.message || "Some error occurred while checking if the User already exists.");
|
||||||
|
} else{
|
||||||
|
if(docs === null) {
|
||||||
|
const user = new User({
|
||||||
|
login: req.body.login,
|
||||||
|
hashPass: req.body.hashPass,
|
||||||
|
mail: req.body.mail,
|
||||||
|
role: req.body.role
|
||||||
|
});
|
||||||
|
|
||||||
|
// Save User in the database
|
||||||
|
user
|
||||||
|
.save(user)
|
||||||
|
.then(data => {
|
||||||
|
data.hashPass = undefined; // Hiding hashPass on return
|
||||||
|
sendMessage(res, 1, data)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res, 500,-1,err.message || "Some error occurred while creating the User.");
|
||||||
|
});
|
||||||
|
} else{
|
||||||
|
sendError(res, 500, -1, err || "User already exists.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retrieve all Users from the database.
|
||||||
|
exports.findAll = (req, res) => {
|
||||||
|
const login = req.query.login;
|
||||||
|
let condition = login ? { login: { $regex: new RegExp(login), $options: "i" } } : {};
|
||||||
|
|
||||||
|
User.find(condition, {hashPass: false})
|
||||||
|
.then(data => {
|
||||||
|
sendMessage(res, 1, data)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Some error occurred while retrieving users.");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Find a single User with an id
|
||||||
|
exports.findOne = (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
User.findById(id, {hashPass: false})
|
||||||
|
.then(data => {
|
||||||
|
if (data){
|
||||||
|
sendMessage(res, 1, data);
|
||||||
|
} else {
|
||||||
|
sendError(res,404,-1,"Not found User with id " + id );
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Error retrieving User with id=" + id );
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update a User by the id in the request
|
||||||
|
exports.update = (req, res) => {
|
||||||
|
if (!req.body) {
|
||||||
|
sendError(res,400,-1,"Data to update can not be empty!");
|
||||||
|
} else{
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
User.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||||
|
.then(data => {
|
||||||
|
if (data) {
|
||||||
|
sendMessage(res, 1, { message: "User was updated successfully." });
|
||||||
|
} else {
|
||||||
|
sendError(res,404,-1,`Cannot update User with id=${id}. Maybe User was not found!`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Error updating User with id=" + id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Delete a User with the specified id in the request
|
||||||
|
exports.delete = (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
User.findByIdAndRemove(id)
|
||||||
|
.then(data => {
|
||||||
|
if (data) {
|
||||||
|
sendMessage(res, 1, { message: "User was deleted successfully!" });
|
||||||
|
} else {
|
||||||
|
sendError(res,404,-1,`Cannot delete User with id=${id}. Maybe User was not found!`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Could not delete User with id=" + id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Delete all Users from the database.
|
||||||
|
exports.deleteAll = (req, res) => {
|
||||||
|
User.deleteMany({})
|
||||||
|
.then(data => {
|
||||||
|
sendMessage(res, 1,{
|
||||||
|
message: `${data.deletedCount} Users were deleted successfully!`
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
sendError(res,500,-1,err.message || "Some error occurred while removing all Users.");
|
||||||
|
});
|
||||||
|
};
|
||||||
14
backend/app/jwtRS256.key.pub
Normal file
14
backend/app/jwtRS256.key.pub
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
-----BEGIN PUBLIC KEY-----
|
||||||
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAyTaN1skc89wdcz8SLY9c
|
||||||
|
lkcARENbO40DncmcUZwQEq+EYR9BzUhjIzKJ6JetU+qGt4SJQkPAczQbw8+LaF6P
|
||||||
|
NT0QTF6E6BUgTZg1p98E/208AiFDnoqEjmlLdQN7ekttJXGDrVOTds9WMbn8lVpa
|
||||||
|
4EpVc+8CPDmrSTIC2YVSZmmektmFTSUA6411+5FGlq5oUdyKkToWYdn/ViJbYst8
|
||||||
|
N48E2Vuh1ghY5t7oPWGzPibMc/6A+uDAF7+VVD8x5UydMZ9id+RxC7lhtDDvZeRM
|
||||||
|
BllHcnWfw0UMhVk8PC6/BenJ4I8HiOgyl4cypTvlevfbZjSoNJ4g/u/lDKpdqbBg
|
||||||
|
T76OksaYqvwvTrcvPdgF1f8l/7M9ESYZTMpxvqK6YvYC/MG2355fmZ1SeuqKfDt8
|
||||||
|
rQXfXzesGSNmFNkm8mORHYiXBqyuNAwnSqRtP8qfoB4yXZ2W1HjUf24TvkvMrqwT
|
||||||
|
7PFg55c/f4LVdPjx52z30QzBJmcyVZgzXNOCG1KafwBibhriQmhdfiWogs824mwI
|
||||||
|
9w0vG2pPqSHRAa6N1y9JHSP1rIfu1jzRNFWTUuqyKgLYBE47HqxxJ21BwBryTVUz
|
||||||
|
8Ei+o05lJFkQX2/ISFYP2RunfUBccqmv0nEcGr+RSLTeqz5+WUTWs8tQxUItf2p6
|
||||||
|
9Y30htlmCJlSnHn2JlaJWQUCAwEAAQ==
|
||||||
|
-----END PUBLIC KEY-----
|
||||||
8
backend/app/jwtRS256.sh
Normal file
8
backend/app/jwtRS256.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key -q -N ""
|
||||||
|
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
|
||||||
|
rm .env
|
||||||
|
echo "JWTRS256_PRIVATE_KEY='`cat ./jwtRS256.key | base64 -w 0`'" >> .env
|
||||||
|
echo "JWTRS256_PUBLIC_KEY='`cat ./jwtRS256.key.pub | base64 -w 0`'" >> .env
|
||||||
|
source .env
|
||||||
|
rm jwtRS256.key
|
||||||
12
backend/app/models/mongodb.model.js
Normal file
12
backend/app/models/mongodb.model.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
const dbConfig = require("../config/mongodb.config");
|
||||||
|
|
||||||
|
const mongoose = require("mongoose");
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
|
||||||
|
const db = {};
|
||||||
|
db.mongoose = mongoose;
|
||||||
|
db.url = dbConfig.url;
|
||||||
|
db.tutorials = require("./tutorial.model")(mongoose);
|
||||||
|
db.users = require("./user.model")(mongoose);
|
||||||
|
|
||||||
|
module.exports = db;
|
||||||
17
backend/app/models/tutorial.model.js
Normal file
17
backend/app/models/tutorial.model.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
module.exports = mongoose => {
|
||||||
|
let schema = mongoose.Schema({
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
published: Boolean
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
schema.method("toJSON", function() {
|
||||||
|
const { __v, _id, ...object } = this.toObject();
|
||||||
|
object.id = _id;
|
||||||
|
return object;
|
||||||
|
});
|
||||||
|
|
||||||
|
return mongoose.model("tutorial", schema);
|
||||||
|
};
|
||||||
18
backend/app/models/user.model.js
Normal file
18
backend/app/models/user.model.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
module.exports = mongoose => {
|
||||||
|
let schema = mongoose.Schema({
|
||||||
|
login: String,
|
||||||
|
hashPass: String, // WARNING: We don't want to send back the hashPass
|
||||||
|
mail: String,
|
||||||
|
role: Object
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
schema.method("toJSON", function() {
|
||||||
|
const { __v, _id, ...object } = this.toObject();
|
||||||
|
object.id = _id;
|
||||||
|
return object;
|
||||||
|
});
|
||||||
|
|
||||||
|
return User = mongoose.model("user", schema);
|
||||||
|
};
|
||||||
28
backend/app/routes/tutorial.routes.js
Normal file
28
backend/app/routes/tutorial.routes.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
module.exports = app => {
|
||||||
|
const tutorials = require("../controllers/tutorial.controller.js");
|
||||||
|
|
||||||
|
let router = require("express").Router();
|
||||||
|
|
||||||
|
// Create a new Tutorial
|
||||||
|
router.post("/", tutorials.create);
|
||||||
|
|
||||||
|
// Retrieve all Tutorials
|
||||||
|
router.get("/", tutorials.findAll);
|
||||||
|
|
||||||
|
// Retrieve all published Tutorials
|
||||||
|
router.get("/published", tutorials.findAllPublished);
|
||||||
|
|
||||||
|
// Retrieve a single Tutorial with id
|
||||||
|
router.get("/:id", tutorials.findOne);
|
||||||
|
|
||||||
|
// Update a Tutorial with id
|
||||||
|
router.put("/:id", tutorials.update);
|
||||||
|
|
||||||
|
// Delete a Tutorial with id
|
||||||
|
router.delete("/:id", tutorials.delete);
|
||||||
|
|
||||||
|
// Create a new Tutorial
|
||||||
|
router.delete("/", tutorials.deleteAll);
|
||||||
|
|
||||||
|
app.use('/api/tutorials', router);
|
||||||
|
};
|
||||||
27
backend/app/routes/user.routes.js
Normal file
27
backend/app/routes/user.routes.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
const users = require("../controllers/user.controller");
|
||||||
|
module.exports = app => {
|
||||||
|
let router = require("express").Router();
|
||||||
|
|
||||||
|
// Create a new User
|
||||||
|
router.post("/", users.create);
|
||||||
|
|
||||||
|
// Retrieve all Users
|
||||||
|
router.get("/", users.findAll);
|
||||||
|
|
||||||
|
// Retrieve a single User with id
|
||||||
|
router.get("/:id", users.findOne);
|
||||||
|
|
||||||
|
// Update a User with id
|
||||||
|
router.put("/:id", users.update);
|
||||||
|
|
||||||
|
// Delete a User with id
|
||||||
|
router.delete("/:id", users.delete);
|
||||||
|
|
||||||
|
// Delete all Users
|
||||||
|
router.delete("/", users.deleteAll);
|
||||||
|
|
||||||
|
// Authenticate a User
|
||||||
|
router.post("/auth", users.auth);
|
||||||
|
|
||||||
|
app.use('/api/users', router);
|
||||||
|
};
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
const config = {
|
|
||||||
// paramètres de connexion à la base de données
|
|
||||||
mongodbDatabase: 'polynotfound',
|
|
||||||
mongodbHost: 'mongodb://mongodb:27017/',
|
|
||||||
// mongodbHost: 'mongodb://127.0.0.1:27017/',
|
|
||||||
charset: 'utf8',
|
|
||||||
mongodbLogin: '',
|
|
||||||
mongodbPassword: '',
|
|
||||||
|
|
||||||
// les noms des tables
|
|
||||||
mongodbUtilisateurs: 'users'
|
|
||||||
};
|
|
||||||
module.exports = config;
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
|
|
||||||
# Don't add passphrase
|
|
||||||
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
|
|
||||||
cat jwtRS256.key
|
|
||||||
cat jwtRS256.key.pub
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
const config = require('./config');
|
|
||||||
const MongoClient = require( 'mongodb' ).MongoClient;
|
|
||||||
const uri = config.mongodbHost;
|
|
||||||
let db;
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
connectToServer: function( callback ) {
|
|
||||||
MongoClient.connect( uri, { useNewUrlParser: true, useUnifiedTopology: true }, function( err, client ) {
|
|
||||||
if(err) throw err;
|
|
||||||
console.log('mongodb-checkConnection'+client===undefined);
|
|
||||||
if (client !== undefined) console.log(client.isConnected());
|
|
||||||
db = client.db(config.mongodbDatabase);
|
|
||||||
return callback( err );
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getDB: function() {
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
const config = require('./config');
|
|
||||||
const mongoDB = require ('./mongodbConnect').getDB();
|
|
||||||
|
|
||||||
function checkLoginQuery(login, password){
|
|
||||||
// SELECT idUtilisateurs
|
|
||||||
// FROM utilisateurs
|
|
||||||
// WHERE login = ? AND password = ?;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
resolve(mongoDB.collection(config.mongodbUtilisateurs).find(
|
|
||||||
{login: login, password: password},
|
|
||||||
{projection: {_id: 1}}).count());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
module.exports.checkLoginQuery = checkLoginQuery;
|
|
||||||
|
|
||||||
function register(login, password){
|
|
||||||
// INSERT INTO users(login, password)
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
mongoDB.collection(config.mongodbUtilisateurs).updateOne(
|
|
||||||
{'login': login},
|
|
||||||
{$setOnInsert: { 'login': login, 'password': password}},
|
|
||||||
{upsert:true},function(err,res){
|
|
||||||
//console.log(res);
|
|
||||||
if(res !== undefined){
|
|
||||||
if(typeof res.upsertedId !== 'undefined'){
|
|
||||||
resolve(res.upsertedId);
|
|
||||||
}else{
|
|
||||||
resolve(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
module.exports.register = register;
|
|
||||||
|
|
||||||
function getUsersQuery(username){
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
mongoDB.collection(config.mongodbUtilisateurs).find(
|
|
||||||
{ $and: [{'login': {$ne: 'Server'}}, {'login': {$ne: username}}]},
|
|
||||||
{projection: {_id: 0, password: 0}}
|
|
||||||
).toArray(function (err, result){
|
|
||||||
if(err) throw err;
|
|
||||||
resolve(result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
module.exports.getUsersQuery = getUsersQuery
|
|
||||||
|
|
||||||
function changePasswordQuery(login, password, newPassword){
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
mongoDB.collection(config.mongodbUtilisateurs).findOneAndUpdate(
|
|
||||||
{'login': login, 'password': password},
|
|
||||||
{$set: { 'login': login, 'password': newPassword}}
|
|
||||||
,function(err,res){
|
|
||||||
if(res !== undefined){
|
|
||||||
console.log(res);
|
|
||||||
resolve(res.lastErrorObject.n === 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
module.exports.changePasswordQuery = changePasswordQuery;
|
|
||||||
302
backend/package-lock.json
generated
302
backend/package-lock.json
generated
|
|
@ -4,6 +4,25 @@
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/node": {
|
||||||
|
"version": "16.11.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.6.tgz",
|
||||||
|
"integrity": "sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w=="
|
||||||
|
},
|
||||||
|
"@types/webidl-conversions": {
|
||||||
|
"version": "6.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-6.1.1.tgz",
|
||||||
|
"integrity": "sha512-XAahCdThVuCFDQLT7R7Pk/vqeObFNL3YqRyFZg+AqAP/W1/w3xHaIxuW7WszQqTbIBOPRcItYJIou3i/mppu3Q=="
|
||||||
|
},
|
||||||
|
"@types/whatwg-url": {
|
||||||
|
"version": "8.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.1.tgz",
|
||||||
|
"integrity": "sha512-2YubE1sjj5ifxievI5Ge1sckb9k/Er66HyR2c+3+I6VDUUg1TLPdYYTEbQ+DjRkS4nTxMJhgWfSfMRD2sl2EYQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*",
|
||||||
|
"@types/webidl-conversions": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"accepts": {
|
"accepts": {
|
||||||
"version": "1.3.7",
|
"version": "1.3.7",
|
||||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
|
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
|
||||||
|
|
@ -18,14 +37,10 @@
|
||||||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||||
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
|
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
|
||||||
},
|
},
|
||||||
"bl": {
|
"base64-js": {
|
||||||
"version": "2.2.1",
|
"version": "1.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||||
"integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
|
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
|
||||||
"requires": {
|
|
||||||
"readable-stream": "^2.3.5",
|
|
||||||
"safe-buffer": "^5.1.1"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"body-parser": {
|
"body-parser": {
|
||||||
"version": "1.19.0",
|
"version": "1.19.0",
|
||||||
|
|
@ -42,12 +57,39 @@
|
||||||
"qs": "6.7.0",
|
"qs": "6.7.0",
|
||||||
"raw-body": "2.4.0",
|
"raw-body": "2.4.0",
|
||||||
"type-is": "~1.6.17"
|
"type-is": "~1.6.17"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bson": {
|
"bson": {
|
||||||
"version": "1.1.6",
|
"version": "4.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/bson/-/bson-4.5.3.tgz",
|
||||||
"integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg=="
|
"integrity": "sha512-qVX7LX79Mtj7B3NPLzCfBiCP6RAsjiV8N63DjlaVVpZW+PFoDTxQ4SeDbSpcqgE6mXksM5CAwZnXxxxn/XwC0g==",
|
||||||
|
"requires": {
|
||||||
|
"buffer": "^5.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"requires": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"buffer-equal-constant-time": {
|
"buffer-equal-constant-time": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
|
|
@ -91,11 +133,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
|
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
|
||||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
|
||||||
},
|
|
||||||
"cors": {
|
"cors": {
|
||||||
"version": "2.8.5",
|
"version": "2.8.5",
|
||||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
|
@ -106,17 +143,17 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "2.6.9",
|
"version": "4.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ms": "2.0.0"
|
"ms": "2.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"denque": {
|
"denque": {
|
||||||
"version": "1.5.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz",
|
||||||
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw=="
|
"integrity": "sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ=="
|
||||||
},
|
},
|
||||||
"depd": {
|
"depd": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
|
|
@ -128,6 +165,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
||||||
},
|
},
|
||||||
|
"dotenv": {
|
||||||
|
"version": "10.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||||
|
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
|
||||||
|
},
|
||||||
"ecdsa-sig-formatter": {
|
"ecdsa-sig-formatter": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||||
|
|
@ -191,6 +233,21 @@
|
||||||
"type-is": "~1.6.18",
|
"type-is": "~1.6.18",
|
||||||
"utils-merge": "1.0.1",
|
"utils-merge": "1.0.1",
|
||||||
"vary": "~1.1.2"
|
"vary": "~1.1.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"finalhandler": {
|
"finalhandler": {
|
||||||
|
|
@ -205,6 +262,21 @@
|
||||||
"parseurl": "~1.3.3",
|
"parseurl": "~1.3.3",
|
||||||
"statuses": "~1.5.0",
|
"statuses": "~1.5.0",
|
||||||
"unpipe": "~1.0.0"
|
"unpipe": "~1.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forwarded": {
|
"forwarded": {
|
||||||
|
|
@ -237,6 +309,11 @@
|
||||||
"safer-buffer": ">= 2.1.2 < 3"
|
"safer-buffer": ">= 2.1.2 < 3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ieee754": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
|
||||||
|
},
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||||
|
|
@ -247,11 +324,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
|
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
|
||||||
},
|
},
|
||||||
"isarray": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
|
||||||
},
|
|
||||||
"jsonwebtoken": {
|
"jsonwebtoken": {
|
||||||
"version": "8.5.1",
|
"version": "8.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
|
||||||
|
|
@ -267,13 +339,6 @@
|
||||||
"lodash.once": "^4.0.0",
|
"lodash.once": "^4.0.0",
|
||||||
"ms": "^2.1.1",
|
"ms": "^2.1.1",
|
||||||
"semver": "^5.6.0"
|
"semver": "^5.6.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"ms": {
|
|
||||||
"version": "2.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
|
||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"jwa": {
|
"jwa": {
|
||||||
|
|
@ -295,6 +360,11 @@
|
||||||
"safe-buffer": "^5.0.1"
|
"safe-buffer": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"kareem": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
||||||
|
},
|
||||||
"lodash.includes": {
|
"lodash.includes": {
|
||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
||||||
|
|
@ -370,22 +440,60 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "3.7.2",
|
"version": "4.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.1.3.tgz",
|
||||||
"integrity": "sha512-/Qi0LmOjzIoV66Y2JQkqmIIfFOy7ZKsXnQNlUXPFXChOw3FCdNqVD5zvci9ybm6pkMe/Nw+Rz9I0Zsk2a+05iQ==",
|
"integrity": "sha512-lHvTqODBiSpuqjpCj48DOyYWS6Iq6ElJNUiH9HWdQtONyOfjgsKzJULipWduMGsSzaNO4nFi/kmlMFCLvjox/Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bl": "^2.2.1",
|
"bson": "^4.5.2",
|
||||||
"bson": "^1.1.4",
|
"denque": "^2.0.1",
|
||||||
"denque": "^1.4.1",
|
"mongodb-connection-string-url": "^2.0.0",
|
||||||
"optional-require": "^1.1.8",
|
"saslprep": "^1.0.3"
|
||||||
"safe-buffer": "^5.1.2",
|
}
|
||||||
"saslprep": "^1.0.0"
|
},
|
||||||
|
"mongodb-connection-string-url": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-Qf9Zw7KGiRljWvMrrUFDdVqo46KIEiDuCzvEN97rh/PcKzk2bd6n9KuzEwBwW9xo5glwx69y1mI6s+jFUD/aIQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/whatwg-url": "^8.2.1",
|
||||||
|
"whatwg-url": "^9.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mongoose": {
|
||||||
|
"version": "6.0.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.0.12.tgz",
|
||||||
|
"integrity": "sha512-BvsZk7zEEhb1AgQFLtxN9C+7qgy5edRuA3ZDDwHU+kHG/HM44vI6FdKV5m6HVdAUeCHHQTiVv+YQh8BRsToSHw==",
|
||||||
|
"requires": {
|
||||||
|
"bson": "^4.2.2",
|
||||||
|
"kareem": "2.3.2",
|
||||||
|
"mongodb": "4.1.3",
|
||||||
|
"mpath": "0.8.4",
|
||||||
|
"mquery": "4.0.0",
|
||||||
|
"ms": "2.1.2",
|
||||||
|
"regexp-clone": "1.0.0",
|
||||||
|
"sift": "13.5.2",
|
||||||
|
"sliced": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mpath": {
|
||||||
|
"version": "0.8.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz",
|
||||||
|
"integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g=="
|
||||||
|
},
|
||||||
|
"mquery": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mquery/-/mquery-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-nGjm89lHja+T/b8cybAby6H0YgA4qYC/lx6UlwvHGqvTq8bDaNeCwl1sY8uRELrNbVWJzIihxVd+vphGGn1vBw==",
|
||||||
|
"requires": {
|
||||||
|
"debug": "4.x",
|
||||||
|
"regexp-clone": "^1.0.0",
|
||||||
|
"sliced": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.0.0",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
},
|
},
|
||||||
"negotiator": {
|
"negotiator": {
|
||||||
"version": "0.6.2",
|
"version": "0.6.2",
|
||||||
|
|
@ -405,14 +513,6 @@
|
||||||
"ee-first": "1.1.1"
|
"ee-first": "1.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"optional-require": {
|
|
||||||
"version": "1.1.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz",
|
|
||||||
"integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==",
|
|
||||||
"requires": {
|
|
||||||
"require-at": "^1.0.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"parseurl": {
|
"parseurl": {
|
||||||
"version": "1.3.3",
|
"version": "1.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||||
|
|
@ -423,11 +523,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||||
},
|
},
|
||||||
"process-nextick-args": {
|
|
||||||
"version": "2.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
|
||||||
},
|
|
||||||
"proxy-addr": {
|
"proxy-addr": {
|
||||||
"version": "2.0.7",
|
"version": "2.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||||
|
|
@ -437,6 +532,11 @@
|
||||||
"ipaddr.js": "1.9.1"
|
"ipaddr.js": "1.9.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"punycode": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
|
||||||
|
},
|
||||||
"qs": {
|
"qs": {
|
||||||
"version": "6.7.0",
|
"version": "6.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
|
||||||
|
|
@ -458,24 +558,10 @@
|
||||||
"unpipe": "1.0.0"
|
"unpipe": "1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"readable-stream": {
|
"regexp-clone": {
|
||||||
"version": "2.3.7",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
|
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
|
||||||
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
|
"integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
|
||||||
"requires": {
|
|
||||||
"core-util-is": "~1.0.0",
|
|
||||||
"inherits": "~2.0.3",
|
|
||||||
"isarray": "~1.0.0",
|
|
||||||
"process-nextick-args": "~2.0.0",
|
|
||||||
"safe-buffer": "~5.1.1",
|
|
||||||
"string_decoder": "~1.1.1",
|
|
||||||
"util-deprecate": "~1.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"require-at": {
|
|
||||||
"version": "1.0.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz",
|
|
||||||
"integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g=="
|
|
||||||
},
|
},
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
|
|
@ -521,6 +607,21 @@
|
||||||
"statuses": "~1.5.0"
|
"statuses": "~1.5.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||||
|
|
@ -544,6 +645,16 @@
|
||||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||||
},
|
},
|
||||||
|
"sift": {
|
||||||
|
"version": "13.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/sift/-/sift-13.5.2.tgz",
|
||||||
|
"integrity": "sha512-+gxdEOMA2J+AI+fVsCqeNn7Tgx3M9ZN9jdi95939l1IJ8cZsqS8sqpJyOkic2SJk+1+98Uwryt/gL6XDaV+UZA=="
|
||||||
|
},
|
||||||
|
"sliced": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
|
||||||
|
},
|
||||||
"sparse-bitfield": {
|
"sparse-bitfield": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
|
||||||
|
|
@ -558,19 +669,19 @@
|
||||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
|
||||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "~5.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"toidentifier": {
|
"toidentifier": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||||
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
|
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
|
||||||
},
|
},
|
||||||
|
"tr46": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tr46/-/tr46-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==",
|
||||||
|
"requires": {
|
||||||
|
"punycode": "^2.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"type-is": {
|
"type-is": {
|
||||||
"version": "1.6.18",
|
"version": "1.6.18",
|
||||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||||
|
|
@ -585,11 +696,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
|
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
|
||||||
},
|
},
|
||||||
"util-deprecate": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
|
||||||
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
|
|
||||||
},
|
|
||||||
"utils-merge": {
|
"utils-merge": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||||
|
|
@ -599,6 +705,20 @@
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||||
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
|
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
|
||||||
|
},
|
||||||
|
"webidl-conversions": {
|
||||||
|
"version": "6.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz",
|
||||||
|
"integrity": "sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w=="
|
||||||
|
},
|
||||||
|
"whatwg-url": {
|
||||||
|
"version": "9.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-9.1.0.tgz",
|
||||||
|
"integrity": "sha512-CQ0UcrPHyomtlOCot1TL77WyMIm/bCwrJ2D6AOKGwEczU9EpyoqAokfqrf/MioU9kHcMsmJZcg1egXix2KYEsA==",
|
||||||
|
"requires": {
|
||||||
|
"tr46": "^2.1.0",
|
||||||
|
"webidl-conversions": "^6.1.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"cookie-parser": "^1.4.5",
|
"cookie-parser": "^1.4.5",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mongodb": "^3.6.9"
|
"mongoose": "^6.0.12"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,24 @@ app.use(bodyParser.json());
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
app.use(cors({origin: 'http://localhost:4200', credentials: true}));
|
app.use(cors({origin: 'http://localhost:4200', credentials: true}));
|
||||||
|
|
||||||
|
const db = require("./app/models/mongodb.model");
|
||||||
|
db.mongoose
|
||||||
|
.connect(db.url, {
|
||||||
|
useNewUrlParser: true,
|
||||||
|
useUnifiedTopology: true
|
||||||
|
}, function (err){
|
||||||
|
if(err){
|
||||||
|
console.log("Cannot connect to the database!", err);
|
||||||
|
process.exit();
|
||||||
|
} else{
|
||||||
|
console.log("Connected to the database!", db.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
require("./app/config/sessionJWT.config");
|
||||||
|
require("./app/routes/tutorial.routes")(app);
|
||||||
|
require("./app/routes/user.routes")(app);
|
||||||
|
|
||||||
app.listen(port, '0.0.0.0',() => {
|
app.listen(port, '0.0.0.0',() => {
|
||||||
console.log (`listening on port ${port}`);
|
console.log (`listening on port ${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ services:
|
||||||
build: .
|
build: .
|
||||||
command: ng serve --host 0.0.0.0
|
command: ng serve --host 0.0.0.0
|
||||||
volumes:
|
volumes:
|
||||||
- ./frontend:/data/frontend/
|
- ./src:/data/frontend/
|
||||||
- ./node_modules:/data/frontend/node_modules
|
- ./node_modules:/data/frontend/node_modules
|
||||||
ports:
|
ports:
|
||||||
- 4200:4200
|
- 4200:4200
|
||||||
|
|
|
||||||
Reference in a new issue