Compare commits

..
14 Commits
6 changed files with 18 additions and 32 deletions

No files matched your search

+6 -6
View File
@@ -1,13 +1,13 @@
var db = db.getSiblingDB('omdb');
var db = db.getSiblingDB('om');
// Delete all collections + all records
db.messages.deleteMany({});
db.tags.deleteMany({});
db.users.deleteMany({});
db.sessions.deleteMany({});
//db.messages.deleteMany({});
//db.tags.deleteMany({});
//db.users.deleteMany({});
//db.sessions.deleteMany({});
// Insert data in collections
load('mong_msg.js');
//load('mong_msg.js');
load('mong_tag.js');
load('mong_usr.js');
+2 -2
View File
@@ -1,8 +1,8 @@
db.users.insert([
// User: author, Pwd: author
{"_id":"author","name":"Author","type":"MA@EFI;","roles":'{"user":true,"author":true}',"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":["nulla","tempor","veniam","ipsum"],"bookmarks":[],},
{"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user":true,"author":true},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[]},
// User: admin, Pwd: SwenMho
{"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],},
// {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],},
])
//var c = require('./server/crypto.js'),
+2 -2
View File
@@ -64,7 +64,7 @@ app.use(session({
mongooseConnection: mong.connection,
ttl: 30 * 24 * 3600,
}), // mongoose + connect-mongo
//store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore
// store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore
}));
// Favicon for Desktop
@@ -112,7 +112,7 @@ app.use('/api', api_routes);
app.use(express.static(__dirname + '/public'));
// Other stuff is NOT authorized unless logged in
app.use (authorize.genCheckAuthorized ('user'));
//app.use (authorize.genCheckAuthorized ('user'));
// No error so far? Then it's a 404!
app.use(function (req, res, next) {
+6 -6
View File
@@ -14,13 +14,13 @@ const clientVisibleSession = { user: true, name: true, type: true, mail: true, r
// Return user role, query from found.mail
function getUserRole(found) {
var roles = "user";
var roles = "user:true";
var mail = found.mail;
if (!/\d/.test(mail)) {
// Mail contains no number
roles += ',"author"';
roles += ',"author:true"';
}
return JSON.stringify('{'+roles+'}');
return ('{'+roles+'}');
}
// Fill in session object
@@ -127,9 +127,9 @@ const authorization = {
Users.findById (req.body.user) .exec (function (err, entry) {
// If there is a local user AND it has a password associated, test against this, and only this
if (entry != null && entry.pwd) {
console.info(entry);
if (crypto.checkLocalAuth (entry, req.body.pwd)) {
console.info(entry.roles);
return fillSession (req, entry, JSON.parse(entry.roles), returnSession);
return fillSession (req, entry, entry.roles, returnSession);
}
return returnError ();
}
@@ -151,7 +151,7 @@ const authorization = {
entry.type = found.type;
if (! entry.orclgender || entry.orclgender === "")
entry.orclgender = found.orclgender;
return fillSession (req, entry, entry.roles.length > 0 ? common.arrayToHash(entry.roles) : {user:true}, returnSession);
return fillSession (req, entry, entry.roles.length > 0 ? entry.roles : {user:true}, returnSession);
}
// Otherwise create standard user entry
+1 -15
View File
@@ -305,7 +305,7 @@ const dbs = {
* Local db: common.config.dbLocalConn
* TH db: common.config.dbConn
*/
common.mongoose.connect(common.config.dbLocalConn, {
common.mongoose.connect(common.config.dbConn, {
useNewUrlParser: true
}).then(() => {
console.log("Database connected successfully.");
@@ -386,18 +386,4 @@ const dbs = {
models: model,
};
/*
app.get ("/api/msg/search/:phrase", function (req, res) {
Message.find ({$text: {$search: req.params.phrase}) .then (function (err, results){
if (err) {
console.log (err);
res .status(404) .json (err);
} else {
console.log(JSON.stringify(results));
res.json(results);
}
});
});
*/
module.exports = dbs;
+1 -1
View File
@@ -1,5 +1,5 @@
{
"dbConn": "mongodb://127.0.0.1:27017/om",
"dbConn": "mongodb://om:aeg1phuKeDaixese@127.0.0.1:27017/om",
"dbLocalConn": "mongodb://localhost:27017/omdb",
"dbUser": "om",
"dbPwd": "aeg1phuKeDaixese",