Compare commits
4 Commits
Manage-Por
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b25bfa8c92 | ||
| 555fc37047 | |||
| ec9092abf3 | |||
| eabb8199dc |
@@ -17,12 +17,16 @@ config.mail.pass = "password";
|
|||||||
config.mail.from = "name";
|
config.mail.from = "name";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Session purge settings
|
* Session settings
|
||||||
*/
|
*/
|
||||||
// Maximum session length in days
|
// Maximum session length in days
|
||||||
config.maxSessionLength = 1;
|
config.maxSessionLength = 1;
|
||||||
config.maxRefreshLength = 360;
|
config.maxRefreshLength = 360;
|
||||||
|
|
||||||
|
// Session string character length
|
||||||
|
config.sessionCharacterLength = 25;
|
||||||
|
config.refreshChracterLength = 60;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SSL settings
|
* SSL settings
|
||||||
*/
|
*/
|
||||||
@@ -49,5 +53,4 @@ config.http.port = 8080;
|
|||||||
config.db = {}
|
config.db = {}
|
||||||
config.db.connection = 'mongodb://localhost:27017/kno-logic';
|
config.db.connection = 'mongodb://localhost:27017/kno-logic';
|
||||||
|
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|||||||
11
index.js
11
index.js
@@ -13,7 +13,6 @@ const postRoutes = require('./routes/post.route');
|
|||||||
const categoryRoutes = require('./routes/category.route');
|
const categoryRoutes = require('./routes/category.route');
|
||||||
const mongoSanitize = require('express-mongo-sanitize');
|
const mongoSanitize = require('express-mongo-sanitize');
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { Http2ServerRequest } = require('http2');
|
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
|
||||||
console.log("Starting Kno-Logic Backend Server");
|
console.log("Starting Kno-Logic Backend Server");
|
||||||
@@ -46,10 +45,11 @@ app.use(function(req, res, next) {
|
|||||||
app.use(mongoSanitize());
|
app.use(mongoSanitize());
|
||||||
|
|
||||||
// Express routes
|
// Express routes
|
||||||
app.use('/admin', adminRoutes);
|
app.use('/v1/admin', adminRoutes);
|
||||||
app.use('/user', userRoutes);
|
app.use('/v1/user', userRoutes);
|
||||||
app.use('/post', postRoutes);
|
app.use('/v1/post', postRoutes);
|
||||||
app.use('/category', categoryRoutes);
|
app.use('/v1/category', categoryRoutes);
|
||||||
|
app.use('/manage', express.static('public'));
|
||||||
|
|
||||||
app.listen(config.http.port, () => {
|
app.listen(config.http.port, () => {
|
||||||
console.log('Express server running on port:', PORT);
|
console.log('Express server running on port:', PORT);
|
||||||
@@ -63,7 +63,6 @@ if (config.ssl.use) {
|
|||||||
https.createServer(options, app).listen(config.ssl.port);
|
https.createServer(options, app).listen(config.ssl.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Cron jobs
|
// Cron jobs
|
||||||
var purge = new CronJob('*/5 * * * *', utils.cron.purgeSessions);
|
var purge = new CronJob('*/5 * * * *', utils.cron.purgeSessions);
|
||||||
purge.start();
|
purge.start();
|
||||||
|
|||||||
97
package-lock.json
generated
97
package-lock.json
generated
@@ -16,7 +16,7 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-mongo-sanitize": "^2.1.0",
|
"express-mongo-sanitize": "^2.1.0",
|
||||||
"log-timestamp": "^0.3.0",
|
"log-timestamp": "^0.3.0",
|
||||||
"mongoose": "^5.12.7",
|
"mongoose": "^5.13.15",
|
||||||
"nodemailer": "^6.6.1"
|
"nodemailer": "^6.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -437,9 +437,9 @@
|
|||||||
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
|
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
|
||||||
},
|
},
|
||||||
"node_modules/denque": {
|
"node_modules/denque": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
||||||
"integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==",
|
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10"
|
"node": ">=0.10"
|
||||||
}
|
}
|
||||||
@@ -1110,14 +1110,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mongodb": {
|
"node_modules/mongodb": {
|
||||||
"version": "3.6.6",
|
"version": "3.7.3",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.6.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.3.tgz",
|
||||||
"integrity": "sha512-WlirMiuV1UPbej5JeCMqE93JRfZ/ZzqE7nJTwP85XzjAF4rRSeq2bGCb1cjfoHLOF06+HxADaPGqT0g3SbVT1w==",
|
"integrity": "sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bl": "^2.2.1",
|
"bl": "^2.2.1",
|
||||||
"bson": "^1.1.4",
|
"bson": "^1.1.4",
|
||||||
"denque": "^1.4.1",
|
"denque": "^1.4.1",
|
||||||
"optional-require": "^1.0.2",
|
"optional-require": "^1.1.8",
|
||||||
"safe-buffer": "^5.1.2"
|
"safe-buffer": "^5.1.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -1147,19 +1147,32 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mongoose": {
|
"node_modules/mongodb/node_modules/optional-require": {
|
||||||
"version": "5.12.7",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.12.7.tgz",
|
"resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz",
|
||||||
"integrity": "sha512-BniNwACn7uflK2h+M3juvyLH5nn9JDFgnB5KE2EwWFwSrRyhSpPnCtanRKJW3OtMCJyPccMIjtGZxHNW7JfnIw==",
|
"integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"require-at": "^1.0.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mongoose": {
|
||||||
|
"version": "5.13.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.15.tgz",
|
||||||
|
"integrity": "sha512-cxp1Gbb8yUWkaEbajdhspSaKzAvsIvOtRlYD87GN/P2QEUhpd6bIvebi36T6M0tIVAMauNaK9SPA055N3PwF8Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/bson": "1.x || 4.0.x",
|
||||||
"@types/mongodb": "^3.5.27",
|
"@types/mongodb": "^3.5.27",
|
||||||
"bson": "^1.1.4",
|
"bson": "^1.1.4",
|
||||||
"kareem": "2.3.2",
|
"kareem": "2.3.2",
|
||||||
"mongodb": "3.6.6",
|
"mongodb": "3.7.3",
|
||||||
"mongoose-legacy-pluralize": "1.0.2",
|
"mongoose-legacy-pluralize": "1.0.2",
|
||||||
"mpath": "0.8.3",
|
"mpath": "0.8.4",
|
||||||
"mquery": "3.2.5",
|
"mquery": "3.2.5",
|
||||||
"ms": "2.1.2",
|
"ms": "2.1.2",
|
||||||
|
"optional-require": "1.0.x",
|
||||||
"regexp-clone": "1.0.0",
|
"regexp-clone": "1.0.0",
|
||||||
"safe-buffer": "5.2.1",
|
"safe-buffer": "5.2.1",
|
||||||
"sift": "13.5.2",
|
"sift": "13.5.2",
|
||||||
@@ -1533,6 +1546,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
|
||||||
"integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
|
"integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
|
||||||
},
|
},
|
||||||
|
"node_modules/require-at": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz",
|
||||||
|
"integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/rimraf": {
|
"node_modules/rimraf": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||||
@@ -1682,7 +1703,7 @@
|
|||||||
"node_modules/sparse-bitfield": {
|
"node_modules/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",
|
||||||
"integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
|
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"memory-pager": "^1.0.2"
|
"memory-pager": "^1.0.2"
|
||||||
@@ -2192,9 +2213,9 @@
|
|||||||
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
|
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
|
||||||
},
|
},
|
||||||
"denque": {
|
"denque": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
||||||
"integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ=="
|
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw=="
|
||||||
},
|
},
|
||||||
"depd": {
|
"depd": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
@@ -2683,31 +2704,43 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "3.6.6",
|
"version": "3.7.3",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.6.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.3.tgz",
|
||||||
"integrity": "sha512-WlirMiuV1UPbej5JeCMqE93JRfZ/ZzqE7nJTwP85XzjAF4rRSeq2bGCb1cjfoHLOF06+HxADaPGqT0g3SbVT1w==",
|
"integrity": "sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bl": "^2.2.1",
|
"bl": "^2.2.1",
|
||||||
"bson": "^1.1.4",
|
"bson": "^1.1.4",
|
||||||
"denque": "^1.4.1",
|
"denque": "^1.4.1",
|
||||||
"optional-require": "^1.0.2",
|
"optional-require": "^1.1.8",
|
||||||
"safe-buffer": "^5.1.2",
|
"safe-buffer": "^5.1.2",
|
||||||
"saslprep": "^1.0.0"
|
"saslprep": "^1.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongoose": {
|
"mongoose": {
|
||||||
"version": "5.12.7",
|
"version": "5.13.15",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.12.7.tgz",
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.15.tgz",
|
||||||
"integrity": "sha512-BniNwACn7uflK2h+M3juvyLH5nn9JDFgnB5KE2EwWFwSrRyhSpPnCtanRKJW3OtMCJyPccMIjtGZxHNW7JfnIw==",
|
"integrity": "sha512-cxp1Gbb8yUWkaEbajdhspSaKzAvsIvOtRlYD87GN/P2QEUhpd6bIvebi36T6M0tIVAMauNaK9SPA055N3PwF8Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@types/bson": "1.x || 4.0.x",
|
||||||
"@types/mongodb": "^3.5.27",
|
"@types/mongodb": "^3.5.27",
|
||||||
"bson": "^1.1.4",
|
"bson": "^1.1.4",
|
||||||
"kareem": "2.3.2",
|
"kareem": "2.3.2",
|
||||||
"mongodb": "3.6.6",
|
"mongodb": "3.7.3",
|
||||||
"mongoose-legacy-pluralize": "1.0.2",
|
"mongoose-legacy-pluralize": "1.0.2",
|
||||||
"mpath": "0.8.3",
|
"mpath": "0.8.4",
|
||||||
"mquery": "3.2.5",
|
"mquery": "3.2.5",
|
||||||
"ms": "2.1.2",
|
"ms": "2.1.2",
|
||||||
|
"optional-require": "1.0.x",
|
||||||
"regexp-clone": "1.0.0",
|
"regexp-clone": "1.0.0",
|
||||||
"safe-buffer": "5.2.1",
|
"safe-buffer": "5.2.1",
|
||||||
"sift": "13.5.2",
|
"sift": "13.5.2",
|
||||||
@@ -2715,7 +2748,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mpath": {
|
"mpath": {
|
||||||
"version": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz",
|
"version": "0.8.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz",
|
||||||
"integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g=="
|
"integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g=="
|
||||||
},
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
@@ -2976,6 +3010,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
|
||||||
"integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
|
"integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
|
||||||
},
|
},
|
||||||
|
"require-at": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz",
|
||||||
|
"integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g=="
|
||||||
|
},
|
||||||
"rimraf": {
|
"rimraf": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||||
@@ -3102,7 +3141,7 @@
|
|||||||
"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",
|
||||||
"integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
|
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"memory-pager": "^1.0.2"
|
"memory-pager": "^1.0.2"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-mongo-sanitize": "^2.1.0",
|
"express-mongo-sanitize": "^2.1.0",
|
||||||
"log-timestamp": "^0.3.0",
|
"log-timestamp": "^0.3.0",
|
||||||
"mongoose": "^5.12.7",
|
"mongoose": "^5.13.15",
|
||||||
"nodemailer": "^6.6.1"
|
"nodemailer": "^6.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
1
public/consts.js
Normal file
1
public/consts.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
const backendURL = "http://127.0.0.1:8080";
|
||||||
73
public/index.html
Normal file
73
public/index.html
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<center>
|
||||||
|
<h1>Kno-Logic Management Portal</h1>
|
||||||
|
<form>
|
||||||
|
<table border="black">
|
||||||
|
<th colspan="2">
|
||||||
|
Login
|
||||||
|
</th>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="email">Email: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" id="email" name="email">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="password">Password: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="password" id="password" name="password">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<center><button type="button" onclick="login()">Login</button></center>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<a href="/manage/register.html">Register</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script src="./consts.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function login() {
|
||||||
|
let email = document.getElementById("email").value;
|
||||||
|
let password = document.getElementById("password").value;
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const rawResponse = await fetch(backendURL + '/v1/user/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ email: email, password: password })
|
||||||
|
});
|
||||||
|
const content = await rawResponse.text();
|
||||||
|
|
||||||
|
console.log(content);
|
||||||
|
})();
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
59
public/manageHome.html
Normal file
59
public/manageHome.html
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<center>
|
||||||
|
<h1>Kno-Logic Management Portal</h1>
|
||||||
|
<table border="black">
|
||||||
|
<th colspan="4">
|
||||||
|
Home
|
||||||
|
</th>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="/manage/manageHome.html">Home</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/manage/managePosts.html">Manage Posts</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/manage/manageCategories.html">Manage Categories</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/manage/manageHome.html">Analytics</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script src="./consts.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function login() {
|
||||||
|
let email = document.getElementById("email").value;
|
||||||
|
let password = document.getElementById("password").value;
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const rawResponse = await fetch(backendURL + '/v1/user/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ email: email, password: password })
|
||||||
|
});
|
||||||
|
const content = await rawResponse.text();
|
||||||
|
|
||||||
|
console.log(content);
|
||||||
|
})();
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
84
public/register.html
Normal file
84
public/register.html
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<center>
|
||||||
|
<h1>Kno-Logic Management Portal</h1>
|
||||||
|
<form>
|
||||||
|
<table border="black">
|
||||||
|
<th colspan="2">
|
||||||
|
Register
|
||||||
|
</th>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="email">Name: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" id="name" name="name">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="email">Email: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="email" id="email" name="email">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="password">Password: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="password" id="password" name="password">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<center><button type="button" onclick="login()">Login</button></center>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<a href="/manage/index.html">Log In</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script src="./consts.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function login() {
|
||||||
|
let name = document.getElementById("name").value;
|
||||||
|
let email = document.getElementById("email").value;
|
||||||
|
let password = document.getElementById("password").value;
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const rawResponse = await fetch(backendURL + '/v1/user/create', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ name: name, email: email, password: password })
|
||||||
|
});
|
||||||
|
const content = await rawResponse.text();
|
||||||
|
|
||||||
|
alert(content);
|
||||||
|
|
||||||
|
console.log(content);
|
||||||
|
})();
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -15,7 +15,7 @@ let User = require('../schema/user.model');
|
|||||||
*/
|
*/
|
||||||
adminRoutes.route('/stats').post((req, res) => {
|
adminRoutes.route('/stats').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
||||||
@@ -31,13 +31,13 @@ adminRoutes.route('/stats').post((req, res) => {
|
|||||||
User.count({}, (err, userCount) => {
|
User.count({}, (err, userCount) => {
|
||||||
stats.userCount = userCount;
|
stats.userCount = userCount;
|
||||||
stats.date = Date();
|
stats.date = Date();
|
||||||
res.json(stats);
|
res.status(200).json({ success: true, response: stats });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Invalid permissions to view stats.");
|
res.status(401).json({ success: false, response: "Invalid permissions to view stats" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ let User = require('../schema/user.model');
|
|||||||
*/
|
*/
|
||||||
categoryRoutes.route('/create').post((req, res) => {
|
categoryRoutes.route('/create').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
||||||
@@ -24,14 +24,14 @@ categoryRoutes.route('/create').post((req, res) => {
|
|||||||
let c = new Category(req.body);
|
let c = new Category(req.body);
|
||||||
c.save()
|
c.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json(c);
|
res.status(200).json({ success: true, response: c });
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).send("Error creating category");
|
res.status(500).json({ success: false, response: "Error creating category" });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Invalid permissions to create category.");
|
res.status(401).json({ success: false, response: "Invalid permissions to create category" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -47,10 +47,10 @@ categoryRoutes.route('/all').get((req, res) => {
|
|||||||
Category.find({}, (err, cArr) => {
|
Category.find({}, (err, cArr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error getting categories");
|
res.status(500).json({ success: false, response: "Error getting categories" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(cArr);
|
res.status(200).json({ success: true, response: cArr });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -63,11 +63,11 @@ categoryRoutes.route('/posts').get((req, res) => {
|
|||||||
Post.find({}, (err, postArr) => {
|
Post.find({}, (err, postArr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error getting posts");
|
res.status(500).json({ success: false, response: "Error getting posts" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
postArr = postArr.filter(post => post.category.includes(req.body._id));
|
postArr = postArr.filter(post => post.category.includes(req.body._id));
|
||||||
res.status(200).send(postArr);
|
res.status(200).json({ success: true, response: postArr });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ let User = require('../schema/user.model');
|
|||||||
*/
|
*/
|
||||||
postRoutes.route('/create').post((req, res) => {
|
postRoutes.route('/create').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
||||||
@@ -25,14 +25,14 @@ postRoutes.route('/create').post((req, res) => {
|
|||||||
p.date = utils.date.dateToEpoch(p.date);
|
p.date = utils.date.dateToEpoch(p.date);
|
||||||
p.save()
|
p.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json(p);
|
res.status(200).json({ success: true, response: p });
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).send("Error creating post");
|
res.status(500).json({ success: false, response: "Error creating post" });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Invalid permissions to create post.");
|
res.status(401).json({ success: false, response: "Invalid permissions to create post" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -47,7 +47,7 @@ postRoutes.route('/create').post((req, res) => {
|
|||||||
*/
|
*/
|
||||||
postRoutes.route('/delete').post((req, res) => {
|
postRoutes.route('/delete').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
||||||
@@ -55,13 +55,13 @@ postRoutes.route('/delete').post((req, res) => {
|
|||||||
if (isValidId && isAdmin) {
|
if (isValidId && isAdmin) {
|
||||||
Post.findByIdAndDelete(req.body._id, (err, r) => {
|
Post.findByIdAndDelete(req.body._id, (err, r) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(500).send("Error deleting post");
|
res.status(500).json({ success: false, response: "Error deleting post" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send("Deleted post");
|
res.status(200).json({ success: true, response: "Deleted post" });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Invalid permissions to delete post.");
|
res.status(401).json({ success: false, response: "Invalid permissions to delete post." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -76,7 +76,7 @@ postRoutes.route('/delete').post((req, res) => {
|
|||||||
*/
|
*/
|
||||||
postRoutes.route('/edit').post((req, res) => {
|
postRoutes.route('/edit').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
utils.account.checkSession(req.body.userId, req.body.sessionId, (isValidId) => {
|
||||||
@@ -84,7 +84,7 @@ postRoutes.route('/edit').post((req, res) => {
|
|||||||
if (isValidId && isAdmin) {
|
if (isValidId && isAdmin) {
|
||||||
Post.findById(req.body._id, (err, r) => {
|
Post.findById(req.body._id, (err, r) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(500).send("Error editing post");
|
res.status(500).json({ success: false, response: "Error editing post" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
r.save()
|
r.save()
|
||||||
@@ -93,12 +93,12 @@ postRoutes.route('/edit').post((req, res) => {
|
|||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).send("Error creating post");
|
res.status(500).json({ success: false, response: "Error creating post" });
|
||||||
});
|
});
|
||||||
res.status(200).send("Edited post");
|
res.status(200).json({ success: true, response: "Edited post" });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Invalid permissions to delete post.");
|
res.status(401).json({ success: false, response: "Invalid permissions to delete post." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -115,10 +115,10 @@ postRoutes.route('/id').post((req, res) => {
|
|||||||
Post.findById(req.body._id, (err, post) => {
|
Post.findById(req.body._id, (err, post) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error getting posts");
|
res.status(500).json({ success: false, response: "Error getting posts" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(post);
|
res.status(200).json({ success: true, response: post });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -133,10 +133,10 @@ postRoutes.route('/date').post((req, res) => {
|
|||||||
Post.find({ date: d}, (err, post) => {
|
Post.find({ date: d}, (err, post) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error getting posts");
|
res.status(500).json({ success: false, response: "Error getting posts" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(post);
|
res.status(200).json({ success: true, response: post });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -150,10 +150,10 @@ postRoutes.route('/all').get((req, res) => {
|
|||||||
Post.find({}, (err, postArr) => {
|
Post.find({}, (err, postArr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error getting posts");
|
res.status(500).json({ success: false, response: "Error getting posts" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(postArr);
|
res.status(200).json({ success: true, response: postArr });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -169,13 +169,11 @@ postRoutes.route('/today').get((req, res) => {
|
|||||||
Post.find({ date: date }, (err, postArr) => {
|
Post.find({ date: date }, (err, postArr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error getting posts");
|
res.status(500).json({ success: false, response: "Error getting posts" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(postArr);
|
res.status(200).json({ success: true, response: postArr });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = postRoutes;
|
module.exports = postRoutes;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ const utils = require('../utils/utils');
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
const userRoutes = express.Router();
|
const userRoutes = express.Router();
|
||||||
|
const config = require('../config.js');
|
||||||
|
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
const sessionLength = 25;
|
|
||||||
|
|
||||||
let Session = require('../schema/session.model');
|
let Session = require('../schema/session.model');
|
||||||
let User = require('../schema/user.model');
|
let User = require('../schema/user.model');
|
||||||
@@ -19,44 +19,44 @@ let Reset = require('../schema/reset.model');
|
|||||||
*/
|
*/
|
||||||
userRoutes.route('/create').post((req, res) => {
|
userRoutes.route('/create').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
} else if (!req.body.email || !req.body.password || !req.body.name) {
|
} else if (!req.body.email || !req.body.password || !req.body.name) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing fields" });
|
||||||
return;
|
return;
|
||||||
} else if (req.body.email == "" || req.body.password == "" || req.body.name == "") {
|
} else if (req.body.email == "" || req.body.password == "" || req.body.name == "") {
|
||||||
res.status(401).send("Empty fields");
|
res.status(401).json({ success: false, response: "Empty fields" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let u = new User(req.body);
|
let u = new User(req.body);
|
||||||
bcrypt.hash(u.password, saltRounds, (err, hash) => {
|
bcrypt.hash(u.password, saltRounds, (err, hash) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error creating user");;
|
res.status(500).json({ success: false, response: "Error creating user" });
|
||||||
} else {
|
} else {
|
||||||
u.password = hash;
|
u.password = hash;
|
||||||
User.find({ email: u.email }, (err, arr) => {
|
User.find({ email: u.email }, (err, arr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error creating user");
|
res.status(500).json({ success: false, response: "Error creating user" });
|
||||||
}
|
}
|
||||||
// Account already exists
|
// Account already exists
|
||||||
if (arr.length != 0) {
|
if (arr.length != 0) {
|
||||||
res.status(409).send("Account already exists");
|
res.status(409).json({ success: false, response: "Account already exists" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
u.permission = 0;
|
u.permission = 0;
|
||||||
u.save()
|
u.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.status(201).send("Success creating user");
|
res.status(201).json({ success: true, response: "Success creating user" });
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
res.status(500).send("Error creating user");;
|
res.status(500).json({ success: false, response: "Error creating user" });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -67,49 +67,57 @@ userRoutes.route('/create').post((req, res) => {
|
|||||||
*/
|
*/
|
||||||
userRoutes.route('/login').post((req, res) => {
|
userRoutes.route('/login').post((req, res) => {
|
||||||
if (!req.body) {
|
if (!req.body) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
} else if (!req.body.email || !req.body.password) {
|
} else if (!req.body.email || !req.body.password) {
|
||||||
res.status(401).send("Missing body");
|
res.status(401).json({ success: false, response: "Missing body" });
|
||||||
return;
|
return;
|
||||||
} else if (req.body.email == "" || req.body.password == "") {
|
} else if (req.body.email == "" || req.body.password == "") {
|
||||||
res.status(401).send("Empty fields");
|
res.status(401).json({ success: false, response: "Empty fields" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User.findOne({ email: req.body.email }, (err, u) => {
|
User.findOne({ email: req.body.email }, (err, u) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error logging in user");
|
res.status(500).json({ success: false, response: "Error logging in user" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!u) {
|
if (!u) {
|
||||||
res.status(401).send("No user exists with that email");
|
res.status(401).json({ success: false, response: "No user exists with that email" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bcrypt.compare(req.body.password, u.password, (err, result) => {
|
bcrypt.compare(req.body.password, u.password, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error logging in user");
|
res.status(500).json({ success: false, response: "Error logging in user" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
let refresh = new Session();
|
||||||
|
refresh.sessionId = generateSession(config.refreshChracterLength);
|
||||||
|
refresh.userId = u._id;
|
||||||
|
refresh.date = new Date();
|
||||||
|
refresh.type = 1;
|
||||||
|
|
||||||
let s = new Session();
|
let s = new Session();
|
||||||
s.sessionId = generateSession();
|
s.sessionId = generateSession(config.sessionCharacterLength);
|
||||||
s.userId = u._id;
|
s.userId = u._id;
|
||||||
s.date = new Date();
|
s.date = new Date();
|
||||||
|
s.type = 0;
|
||||||
|
|
||||||
s.save()
|
s.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json(s);
|
let send = { userId: u._id, sessionId: s.sessionId, refresh: refresh.sessionId}
|
||||||
|
res.status(200).json({ success: true, response: send});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
res.status(500).send("Error logging in user");
|
res.status(500).json({ success: false, response: "Error logging in user"});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Incorrect password");
|
res.status(401).json({ success: false, response: "Incorrect password"});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -126,24 +134,23 @@ userRoutes.route('/logout').post((req, res) => {
|
|||||||
Session.findOne({ sessionId: req.body.sessionId }, (err, sess) => {
|
Session.findOne({ sessionId: req.body.sessionId }, (err, sess) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error logging out");
|
res.status(500).json({ success: false, response: "Error logging out" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sess) {
|
if (!sess) {
|
||||||
res.status(400).send("No session found");
|
res.status(400).json({ success: false, response: "No session found" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.delete()
|
sess.delete()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.status(201).send("Success deleting session");
|
res.status(201).json({ success: true, response: "Success deleting session" });
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).send("Error logging out");
|
res.status(500).json({ success: false, response: "Error logging out" });
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,21 +168,21 @@ userRoutes.route('/favorite/add').post((req, res) => {
|
|||||||
User.findById(req.body.userId, (err, user) => {
|
User.findById(req.body.userId, (err, user) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error adding article");
|
res.status(500).json({ success: false, response: "Error adding article" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.favorites.push(req.body.postId);
|
user.favorites.push(req.body.postId);
|
||||||
user.save()
|
user.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.status(201).send("Success saving article");
|
res.status(201).json({ success: true, response: "Success saving article" });
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).send("Error saving article");
|
res.status(500).json({ success: false, response: "Error saving article" });
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).json({ success: false, response: "Unauthorized" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -192,21 +199,21 @@ userRoutes.route('/favorite/remove').post((req, res) => {
|
|||||||
User.findById(req.body.userId, (err, user) => {
|
User.findById(req.body.userId, (err, user) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error removing article");
|
res.status(500).json({ success: false, response: "Error removing article" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.favorites = utils.array.removeValue(user.favorites, req.body.articleId);
|
user.favorites = utils.array.removeValue(user.favorites, req.body.articleId);
|
||||||
user.save()
|
user.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.status(201).send("Success removing article");
|
res.status(201).json({ success: true, response: "Success removing article" });
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).send("Error removing article");
|
res.status(500).json({ success: false, response: "Error removing article" });
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).json({ success: false, response: "Unauthorized"});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -223,15 +230,15 @@ userRoutes.route('/favorite/get').post((req, res) => {
|
|||||||
User.findById(req.body.userId, (err, user) => {
|
User.findById(req.body.userId, (err, user) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).send("Error removing article");
|
res.status(500).json({ success: false, response: "Error removing article" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Post.find({ '_id': { $in: user.favorites } }, (err, postArray) => {
|
Post.find({ '_id': { $in: user.favorites } }, (err, postArray) => {
|
||||||
res.json(postArray);
|
res.status(200).json({ success: true, response: postArray });
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).json({ success: false, response: "Unauthorized" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -246,13 +253,13 @@ userRoutes.route('/refresh').post((req, res) => {
|
|||||||
|
|
||||||
s.save()
|
s.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json(s);
|
res.status(200).json({ success: true, response: s });
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
res.status(500).send("Error logging in user");
|
res.status(500).json({ success: false, response: "Error logging in user" });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Incorrect refresh token");
|
res.status(401).json({ success: false, response: "Incorrect refresh token" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -265,9 +272,9 @@ userRoutes.route('/check-email').post((req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arr.length > 0) {
|
if (arr.length > 0) {
|
||||||
res.status(400).send("Email already in use");
|
res.status(400).json({ success: false, response: "Email already in use" });
|
||||||
} else {
|
} else {
|
||||||
res.status(200).send("Email not in use");
|
res.status(200).json({ success: true, response: "Email not in use" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -282,13 +289,13 @@ userRoutes.route('/change-name').post((req, res) => {
|
|||||||
if (user) {
|
if (user) {
|
||||||
user.name = req.body.name;
|
user.name = req.body.name;
|
||||||
user.save();
|
user.save();
|
||||||
res.status(200).send("Success changing name");
|
res.status(200).json({ success: true, response: "Success changing name" });
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send("No user found with that ID");
|
res.status(400).json({ success: false, response: "No user found with that ID" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).json({ success: false, response: "Unauthorized" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -303,13 +310,13 @@ userRoutes.route('/change-email').post((req, res) => {
|
|||||||
if (user) {
|
if (user) {
|
||||||
user.email = req.body.email;
|
user.email = req.body.email;
|
||||||
user.save();
|
user.save();
|
||||||
res.status(200).send("Success changing email");
|
res.status(200).json({ success: true, response: "Success changing email" });
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send("No user found with that ID");
|
res.status(400).json({ success: false, response: "No user found with that ID" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).json({ success: false, response: "Unauthorized" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -324,13 +331,13 @@ userRoutes.route('/change-password').post((req, res) => {
|
|||||||
if (user) {
|
if (user) {
|
||||||
user.password = req.body.password;
|
user.password = req.body.password;
|
||||||
user.save();
|
user.save();
|
||||||
res.status(200).send("Success changing password");
|
res.status(200).json({ success: true, response: "Success changing password" });
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send("No user found with that ID");
|
res.status(400).json({ success: false, response: "No user found with that ID" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).json({ success: false, response: "Unauthorized" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -349,9 +356,9 @@ userRoutes.route('/forgot-password').post((req, res) => {
|
|||||||
r.date = new Date();
|
r.date = new Date();
|
||||||
r.save();
|
r.save();
|
||||||
utils.mail.sendMail(user, "forgotPassword", [{from: "%name%", to: user.name}, {from: "%pin%", to: pin}]);
|
utils.mail.sendMail(user, "forgotPassword", [{from: "%name%", to: user.name}, {from: "%pin%", to: pin}]);
|
||||||
res.status(200).send("Success sending reset email");
|
res.status(200).json({ success: true, response: "Success sending reset email" });
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send("No user found with that email");
|
res.status(400).json({ success: false, response: "No user found with that email" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -373,13 +380,13 @@ userRoutes.route('/reset-password').post((req, res) => {
|
|||||||
reset.remove();
|
reset.remove();
|
||||||
user.password = req.body.password;
|
user.password = req.body.password;
|
||||||
user.save();
|
user.save();
|
||||||
res.status(200).send("Success resetting password");
|
res.status(200).json({ success: true, response: "Success resetting password" });
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send("Invalid pin");
|
res.status(400).json({ success: false, response: "Invalid pin" });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send("No user found with that email");
|
res.status(400).json({ success: false, response: "No user found with that email" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -389,8 +396,7 @@ userRoutes.route('/reset-password').post((req, res) => {
|
|||||||
|
|
||||||
module.exports = userRoutes;
|
module.exports = userRoutes;
|
||||||
|
|
||||||
function generateSession() {
|
function generateSession(length) {
|
||||||
var length = sessionLength;
|
|
||||||
var result = [];
|
var result = [];
|
||||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+!@#$%^&*()';
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+!@#$%^&*()';
|
||||||
var charactersLength = characters.length;
|
var charactersLength = characters.length;
|
||||||
|
|||||||
70
schema/analytic.model.js
Normal file
70
schema/analytic.model.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
const mongoose = require('mongoose');
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
// Database schema for an email message
|
||||||
|
let AnalyticData = new Schema({
|
||||||
|
date: {
|
||||||
|
type: Date
|
||||||
|
},
|
||||||
|
viewCount: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
articleViewCounts: {
|
||||||
|
type: Array
|
||||||
|
},
|
||||||
|
systemTime: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemUptime: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCPUBrand: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCPUSpeed: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCPUSpeedMax: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCPUCores: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCPUAverage: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCPUTemperature: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemMemoryTotal: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemMemoryUsed: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemSwapTotal: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemSwapUsed: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemOSPlatform: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemOSDistro: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemOSRelease: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemOSKernel: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
systemCurrentLoad: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
collection: 'categories'
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = mongoose.model('AnalyticData', AnalyticData);
|
||||||
Reference in New Issue
Block a user