diff --git a/database/message.model.js b/database/message.model.js deleted file mode 100644 index f914fb7..0000000 --- a/database/message.model.js +++ /dev/null @@ -1,15 +0,0 @@ -const mongoose = require('mongoose'); - -//const Schema = mongoose.Schema, -//ObjectId = Schema.ObjectId; - -const MessageSchema = mongoose.Schema({ - subject: { type: String, required: true }, - message: { type: String, required: true }, - user: { type: String, required: true }, - tag: [{type: String }], - //createtime: { type: Date, default: Date.now }, -}); -MessageSchema.index({tag:'text'}); - -module.exports = mongoose.model('Message', MessageSchema); diff --git a/database/tag.model.js b/database/tag.model.js deleted file mode 100644 index b3e3ad7..0000000 --- a/database/tag.model.js +++ /dev/null @@ -1,8 +0,0 @@ -const mongoose = require('mongoose'); - - -const TagSchema = mongoose.Schema({ - name: { type: String, required: true }, //unique -}); - -module.exports = mongoose.model('Tag', TagSchema); diff --git a/database/user.model.js b/database/user.model.js deleted file mode 100644 index 632ccf0..0000000 --- a/database/user.model.js +++ /dev/null @@ -1,21 +0,0 @@ -const mongoose = require('mongoose'); - - -const UserSchema = mongoose.Schema({ -// _id: { type: String }, - name: { type: String, required: true }, - pwd: { type: String }, -// hash: { type: String }, -// salt: { type: String }, -// type: { type: String }, - roles: { type: [String], required: true }, - tags: { type: [String] }, -// deactivated: { type: Boolean }, -// participating: { type: [String] }, -// host: { type: Boolean }, - bookmarks: { type: [String] }, -}); -//tags as index: -//UserSchema.index({tags:'text'}); - -module.exports = mongoose.model('User', UserSchema); diff --git a/mongodb.config.js.example b/mongodb.config.js.example deleted file mode 100644 index 36a4a1a..0000000 --- a/mongodb.config.js.example +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - url: 'mongodb://localhost:27017/mydb' -} diff --git a/public/index.html b/public/index.html index 8861930..92b3ca8 100644 --- a/public/index.html +++ b/public/index.html @@ -98,10 +98,19 @@ @@ -178,6 +187,43 @@ methods: { } }); + const search_data = []; +/* + export.default { + data: function () { + return { + selected: [], + taglist: data, + }; + }, + computed: { + filteredTagArray() { + this.taglist = data.filter((option) => { + return option + .toString() + .toLowerCase() + .indexOf(this.name.toLowerCase()) >= 0 + }) + }, + + }, + methods: { + evaluate(text) { + this.taglist = data.filter((option) => { + return option + .toString() + .toLowerCase() + .indexOf(text.toLowerCase()) >= 0 + }) + }, + }, + mounted: function () { + if ($(this).bootstrapMaterialDesign) + $(this).bootstrapMaterialDesign(); + }, + }; +*/ + diff --git a/public/routes/createMessage.js b/public/routes/createMessage.js index b59b7f5..3746d3b 100644 --- a/public/routes/createMessage.js +++ b/public/routes/createMessage.js @@ -19,7 +19,7 @@ const CreateMsgRouter = { ABBRECHEN - SENDEN + SENDEN @@ -42,29 +42,30 @@ const CreateMsgRouter = { data: function () { return { selected: [], - items: data + taglist: data, }; }, methods: { createMsg: function () { - var subject = $("#subject").val(); - var message = $("#message").val(); - var tag = $("#tag").val(); - var user = $("#user").val(); - console.log("Message Created: " + tag + " " + message + " " + user); + var _subject = $("#subject").val(); + var _message = $("#message").val(); + var _tag = $("#tag").val(); + var _user = $("#user").val(); + //console.log("Message Created: " + _tag + " " + _message + " " + _user); $.ajax({ - url: "api/createMsg", + url: "api/msg", data: { - sub: subject, - mess: message, - use: user, - ta: tag + subject: _subject, + message: _message, + user: _user, + tag: _tag }, method: "POST" }).done(have_result).fail(have_error); function have_result(res) { - console.log(res); + //console.log(res); + router.push('/home') } function have_error(err) { @@ -73,13 +74,13 @@ const CreateMsgRouter = { } }, getFilteredTags(text) { - this.items = data.filter((option) => { + this.taglist = data.filter((option) => { return option .toString() .toLowerCase() .indexOf(text.toLowerCase()) >= 0 }) - }, + }, }, mounted: function () { if ($(this).bootstrapMaterialDesign) diff --git a/public/routes/home.js b/public/routes/home.js index 630eeb6..d120b9f 100644 --- a/public/routes/home.js +++ b/public/routes/home.js @@ -24,12 +24,12 @@ const HomeRouter = { }); },*/ list_messages: function () { - $.ajax({url: "api/ids", method: "GET"}) + $.ajax({url: "api/msg/ids", method: "GET"}) .done(jd => { // NICHT SO wg. Vue: _messagelist = jd; _messagelist.splice(0, _messagelist.length); _messagelist.push.apply(_messagelist, jd); - console.log("jd: "+jd); + //console.log("jd: "+jd); for (var e in jd) { if (!_messages[jd[e]]) { get_insert_message(jd[e]); @@ -49,7 +49,7 @@ const HomeRouter = { } }*/ }).fail(function (e, f, g) { - console.log("err: " + e + f + g); + console.log("list_msg: err: " + e + f + g); }); } }, @@ -61,7 +61,7 @@ const HomeRouter = { }; function get_insert_message(id) { - $.ajax({ url: "api/msg/"+id, method: "GET" }).done(function (msg) { + $.ajax({ url: "api/msg/id/"+id, method: "GET" }).done(function (msg) { Vue.set(_messages, id, msg); }).fail(function (e, f, g) { console.log("cannot load " + id + ".json: " + e + f + g); diff --git a/server.js b/server.js index c424653..d5ac4f7 100644 --- a/server.js +++ b/server.js @@ -1,35 +1,38 @@ +// Original file created by Prof.Dr. Matthias Hopf + /** * Express based http & https server * * Requires express >= 4 */ -var common = require ('./server/common'), - authorize = require ('./server/authorization'); +var common = require('./server/common'), + authorize = require('./server/authorization'), + dbs = require('./server/dbs'); /* dbs = require ('./server/dbs'), files = require ('./server/files'); */ -const fs = common.fs, // file sync, read certificates - http = common.http, // http handler - https = require ('https'), // https handler - express = require ('express'), // node server framework - session = require ('express-session'), // session management (security) - morgan = require ('morgan'), // logger - //serveFavicon = require ('serve-favicon'), - bodyParser = require ('body-parser'), // post request bodyparser - MongoStore = require ('connect-mongo')(session), // use mongodb as session storage - Message = require('./database/message.model.js'); +const fs = common.fs, // file sync, read certificates + http = common.http, // http handler + https = require('https'), // https handler + express = require('express'), // node server framework + session = require('express-session'), // session management (security) + morgan = require('morgan'), // logger + mong = common.mongoose, // mongoose +// serveFavicon = require('serve-favicon'), // provide favicon + bodyParser = require('body-parser'), // post request bodyparser + MongoStore = require('connect-mongo')(session); // use mongodb as session storage var app = express(); /* * Init */ -common .init (); -authorize.init (common); -//dbs .init (common); +common .init(); +authorize .init(common); +dbs .init (common); //files .init (common); - +mong.Promise = global.Promise; /* * Security @@ -40,203 +43,134 @@ authorize.init (common); * (Disable Header information: Powerd by Express) * -> Information disclosure */ -app.disable ('x-powered-by'); - -// Session Management -app.set('trust proxy', 1) // trust first proxy, neccessary for cookie secure: true flag -app.use (session({ - secret: 'ahhgylhuvh', // caesar(3) 2 letter surname - resave: false, - saveUninitialized: false, - cookie: { - maxAge: 30*24*3600*1000, // TODO: ttl for session as well (Store) - secure: true, // true for https only (since our app works only with https) - }, - name: 'om.sid', - store: new MongoStore ({mongooseConnection: common.mongoose.connection, ttl: 30*24*3600}), // mongoose + connect-mongo - //store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore -})); +app.disable('x-powered-by'); /* * Route Control */ +// Session Management +app.set('trust proxy', 1) // trust first proxy, neccessary for cookie secure: true flag +app.use(session({ + secret: 'ahhgylhuvh', // caesar(3) 2 letter surname + resave: false, + saveUninitialized: false, + cookie: { + maxAge: 30 * 24 * 3600 * 1000, // TODO: ttl for session as well (Store) + secure: true, // true for https only (since our app works only with https) + }, + name: 'om.sid', + store: new MongoStore({ + mongooseConnection: mong.connection, + ttl: 30 * 24 * 3600 + }), // mongoose + connect-mongo + //store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore +})); -// Fastpaths +// TODO Favicon for Desktop //app.use (serveFavicon (__dirname + '/public/favicon.ico')); - // Minimal Logging //app.use (morgan ('dev')); // Advanced Logging -morgan.token ('user', function (req, res) { return (req.session && req.session.user) || '-'; }); -morgan.token ('userColored', function (req, res) { - var color = 0; - if (req.session && req.session.roles) - color = req.session.roles.admin ? 31 // red - : req.session.roles.user ? 34 // blue - : 0; // no color - return '\x1b[' + color + 'm' + ((req.session && req.session.user) || '-') + '\x1b[0m'; +morgan.token('user', function (req, res) { + return (req.session && req.session.user) || '-'; }); -morgan.token ('statusColored', function (req, res) { - var color = res.statusCode >= 500 ? 31 // red - : res.statusCode >= 400 ? 33 // yellow - : res.statusCode >= 300 ? 36 // cyan - : res.statusCode >= 200 ? 32 // green - : 0; // no color - return '\x1b[' + color + 'm' + (res.headersSent ? res.statusCode : '-') + '\x1b[0m'; +morgan.token('userColored', function (req, res) { + var color = 0; + if (req.session && req.session.roles) + color = req.session.roles.admin ? 31 // red + : req.session.roles.user ? 34 // blue + : 0; // no color + return '\x1b[' + color + 'm' + ((req.session && req.session.user) || '-') + '\x1b[0m'; }); -app.use (morgan (':date[iso] :statusColored :method :url :userColored :response-time ms :res[content-length]')); +morgan.token('statusColored', function (req, res) { + var color = res.statusCode >= 500 ? 31 // red + : res.statusCode >= 400 ? 33 // yellow + : res.statusCode >= 300 ? 36 // cyan + : res.statusCode >= 200 ? 32 // green + : 0; // no color + return '\x1b[' + color + 'm' + (res.headersSent ? res.statusCode : '-') + '\x1b[0m'; +}); +app.use(morgan(':date[iso] :statusColored :method :url :userColored :response-time ms :res[content-length]')); // BodyParser // Returns middleware that only parses json bodies. // (https://www.npmjs.com/package/body-parser#bodyparserjsonoptions) -app.use (bodyParser.json()); +app.use(bodyParser.json()); // Returns middleware that only parses urlencoded bodies // with qs library (https://www.npmjs.com/package/qs#readme) -app.use (bodyParser.urlencoded({extended: true})); +app.use(bodyParser.urlencoded({ + extended: true +})); // API var api_routes = express.Router(); // express app-object routing +app.use('/api', api_routes); -app.use ('/api', api_routes); - -// Static Files -// Allow server access to 'public' folder +// Static Files - Allow access to 'public' folder app.use(express.static(__dirname + '/public')); // Other stuff is NOT authorized unless logged in //app.use (authorize.genCheckAuthorized ('user')); -// Uploaded files -//app.use ('/uploads', express.static(__dirname + '/uploads')); - -// Configuring the database -//var dbConfig = require('./mongodb.config.js'); - -common.mongoose.Promise = global.Promise; - -// Connecting to the database -// Local db: common.config.dbLocalConn -// Efi db: common.config.dbConn -common.mongoose.connect (common.config.dbLocalConn, {useNewUrlParser: true}) .then( () => { - console.log("Successfully connected to MongoDB."); -}).catch( err => { - console.log('Could not connect to MongoDB.'); - process.exit(); -}); - // No error so far? Then it's a 404! -//app.use (function (req, res, next) { next (common.genError (404, req.url)); }); +app.use(function (req, res, next) { + next(common.genError(404, req.url)); +}); //app.use (routes.errorHandler (true)); /* true: show stack traces */ - /* * API */ -/* // API allowed for all -api_routes.post ('/login', authorize.login); // /api/login +api_routes.post('/login', authorize.login); // Validate all other API calls -api_routes.use (authorize.genCheckAuthorized ('user')); -api_routes.post ('/logout', authorize.logout); +//api_routes.use(authorize.genCheckAuthorized('user')); +api_routes.post('/logout', authorize.logout); -function addRoutes (r) { - for (var e in r.routes) { - var params = r.routes[e].params ? "/" + r.routes[e].params : ""; - console.log ("Adding routes for /" + e + params + ":" + - (r.routes[e].get ? " get":" ") + (r.routes[e].post ? " post":" ") + - (r.routes[e].put ? " put":" ") + (r.routes[e].delete ? " delete":" ")); - if (r.routes[e].get) - api_routes.get ('/' + e + params, r.routes[e].get); - if (r.routes[e].post) - api_routes.post ('/' + e + params, r.routes[e].post); - if (r.routes[e].put) - api_routes.put ('/' + e + params, r.routes[e].put); - if (r.routes[e].delete) - api_routes.delete ('/' + e + params, r.routes[e].delete); - } +// Add API routes +function addRoutes(r) { + for (var e in r.routes) { + var route = '/' + e + (r.routes[e].params ? "/" + r.routes[e].params : ""); + var log = "Adding routes for " + route + ":"; + /* + var auth = r.routes[e].auth || r.auth; + if (auth) { + log += " [auth]"; + api_routes.use (route, function (req, res, next) { + if (! auth(req)) + return next (common.genError (403, "Unauthorized")); + next (); + }); + } + */ + /* + var role = r.routes[e].role || r.role; + if (role) { + log += " [role:"+role+"]"; + api_routes.use (route, authorize.genCheckAuthorized (role)); + } + */ + const methods = ["get", "post", "put", "delete"]; + for (var m in methods) { + if (r.routes[e][methods[m]]) { + log += " " + methods[m]; + api_routes[methods[m]](route, r.routes[e][methods[m]]); + } + } + console.log(log); + } } -*/ -app.get ('/api/ids', function (req, res) { - Message.find({},{id: true}) .exec () .then(results => { - //selects id from message: - var parsed = []; - for (var i in results) { - parsed.push (results[i].id); - } - //var parsed = results.map (x => x._id); - res.send(parsed); - } ) - .catch(err => { - console.log (err); - res .status(500) .json (err); - }); -}); - -app.get ("/api/msg/:id", function (req, res) { - Message.findOne ({_id: req.params.id}) .exec (function (err, results){ - if (err) { - console.log (err); - res .status(404) .json (err); - } else { - console.log(JSON.stringify(results)); - res.json(results); - } - }); -}); - -/*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); - } - }); -}); -*/ -/*function makeid() { - var text = ""; - var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - for (var i = 0; i < 5; i++) - text += possible.charAt(Math.floor(Math.random() * possible.length)); - - return text; -}*/ - -app.post("/api/createMsg", function(req, res){ - //x = mongoose.Types.ObjectId(); - //y = x.toString(); - //var z = makeid(); - console.log("SUbject: "+JSON.stringify(req.body)); - var message = new Message( {subject: req.body.sub, message: req.body.mess, user: req.body.use, tag: req.body.ta } ); - - message.save(function(err,result){ - if(err){ - return res .status(401) .send(err.message); - }else{ - res.json({message: "Message created!!"}); - } - }); -}); - -/* -addRoutes (dbs); -addRoutes (admin); -addRoutes (files); -*/ +addRoutes(dbs); /* * Servers */ -http.createServer (app) .listen (common.config.httpPort, function () { - console.log ("Express http server listening on port " + common.config.httpPort); +http.createServer(app).listen(common.config.httpPort, function () { + console.log("Express http server listening on port " + common.config.httpPort); }); /* @@ -255,23 +189,23 @@ if (common.config.httpsPort) { try { try { // In case it's a real certificate: add CA chain cersts (TODO: use array if required) - var ca = fs.readFileSync ('keys/ca_cert.pem'); + var ca = fs.readFileSync('keys/ca_cert.pem'); } catch (e) { ca = undefined; - console.log ("Note: Can't read CA bundle: "+e); + console.log("Note: Can't read CA bundle: " + e); } if (ca != undefined) { options = { - key: fs.readFileSync ('keys/omkey.pem'), - cert: fs.readFileSync ('keys/certificate.pem'), + key: fs.readFileSync('keys/omkey.pem'), + cert: fs.readFileSync('keys/certificate.pem'), ca: ca - }; - https.createServer (options, app) .listen (common.config.httpsPort, function () { - console.log ("Express https server listening on port " + common.config.httpsPort); + }; + https.createServer(options, app).listen(common.config.httpsPort, function () { + console.log("Express https server listening on port " + common.config.httpsPort); }); } } catch (e) { - console.log ("Note: Can't read SSL keys/certs: "+e+"\nDisabling https server"); + console.log("Note: Can't read SSL keys/certs: " + e + "\nDisabling https server"); } } else { console.log("Note: https server disabled by config"); @@ -280,9 +214,7 @@ if (common.config.httpsPort) { /* * Uncaught Exceptions */ -process.on ("uncaughtException", function (err) { - console.error ("*** Uncaught Exception:"); - console.error (err.stack); +process.on("uncaughtException", function (err) { + console.error("*** Uncaught Exception:"); + console.error(err.stack); }); - - diff --git a/server/authorization.js b/server/authorization.js index ebd0e5f..7717ccb 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -1,10 +1,11 @@ +// Original file created by Prof.Dr. Matthias Hopf + /* * Authorization */ - var common, User; -const ldap = require ('./ldap_ohm'); -//const crypto = require ("./crypto"); +const ldap = require ('./ldap_ohm'), + crypto = require ("../server/crypto"); // deactivated is not used yet const serverVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, deactivated: true, host: true }; @@ -66,18 +67,16 @@ const authorization = { return returnError(); return returnSession (); } - - // check local database +/* + // check local database, then ldap User.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) { if (crypto.checkLocalAuth (entry, req.body.pwd)) { return fillSession (req, entry, common.arrayToHash(entry.roles), returnSession); } return returnError (); } - */ // check ldap ldap.authorize (user.toLowerCase(), pwd, function (found) { @@ -101,7 +100,7 @@ const authorization = { // Otherwise create standard user entry return fillSession (req, found, {user:true}, returnSession); }); - }); + });*/ }, logout: function (req, res, next) { fillSession (req, undefined, undefined, function (err) { @@ -111,7 +110,7 @@ const authorization = { init: function (_common) { common = _common; ldap.init (_common); - User = require('../database/user.model.js');; + //User = require('../database/user.model.js');; }, }; diff --git a/server/common.js b/server/common.js index dd2e716..e71297d 100644 --- a/server/common.js +++ b/server/common.js @@ -1,3 +1,5 @@ +// Original file created by Prof.Dr. Matthias Hopf + /* * Common functions and imports */ diff --git a/server/crypto.js b/server/crypto.js new file mode 100644 index 0000000..0159428 --- /dev/null +++ b/server/crypto.js @@ -0,0 +1,31 @@ +// Original file created by Prof.Dr. Matthias Hopf + +/* + * Crypto routines for Authorization + */ + +const crypto = require ("crypto"); + +const defaultHash = "sha256"; +const defaultSaltLen = 16; // More (e.g. 256) for extra paranoia + +const mod = { + encodePwd: function (entry, pwd) { + return crypto.createHash (entry.hash) .update (entry.salt + ":" + pwd, 'utf8') .digest ('base64'); + }, + checkLocalAuth: function (entry, pwd) { + if (!entry || !entry._id || !entry.hash || !entry.salt || !entry.hash || !entry.pwd || + !pwd || pwd === '') + return false; + return mod.encodePwd (entry, pwd) === entry.pwd; + }, + fillLocalAuth: function (entry, pwd) { + if (!entry.hash) + entry.hash = defaultHash; + entry.salt = crypto.randomBytes (defaultSaltLen) .toString('base64'); + entry.pwd = mod.encodePwd (entry, pwd); + }, +} + + +module.exports = mod; diff --git a/server/dbs.js b/server/dbs.js new file mode 100644 index 0000000..004962f --- /dev/null +++ b/server/dbs.js @@ -0,0 +1,222 @@ +/* + * Main database access functions + */ +var common, + model = {}; + +const dbs = { + /* Method API route + * <- to server + * -> to client + * Description + */ + routes: { + "msg/ids": { + /* GET /api/msg/ids [no args] + * -> Array of message schema object ids + * Get ALL known message ids + */ + get: function(req, res) { + model.Messages.find({}, {_id: true}).exec() + .then(results => { + //selects id from message: + var parsed = []; + for (var i in results) { + parsed.push (results[i]._id); + } + //var parsed = results.map (x => x._id); + res.send(parsed); + } ) + .catch(err => { + console.log (err); + res.status(500).json(err); + }); + }, + }, + "msg/id": { + params: ":id", + /* GET /api/msg/id/[massage-id] + * -> Message schema + * Get a particular message + */ + get: function(req, res) { + model.Messages.findById(req.params.id) .exec(function(err, results) { + if (err) { + console.log (err); + res.status(404).json(err); + } else { + //console.log(JSON.stringify(results)); + res.json(results); + } + }); + }, + }, + "msg/search": {}, + "msg": { + /* POST /api/msg + * <- Message schema + * -> Message schema + * Create a new message + */ + post: function(req, res) { + /* + if ( !(req.body.tags instanceof Array) ) { + return res.status(400).json({ error: "bad request" }); + }*/ + console.log("Subject: "+JSON.stringify(req.body)); + model.Messages.create({ + subject: req.body.subject, + message: req.body.message, + user: req.body.user, + tags: req.body.tag + }, function(err, result) { + if (err) { + return res.status(401).json(err.message); + } else { + res.json({message: "Message created!!"}); + } + if (result == null) { + return res.status(500).json("Can not create message.") + } + }); + }, + /* PUT /api/msg + * <- + * -> + * Update a message + */ + //put: function(req, res) {}, + }, + "tag/ids": {}, + "tag": {}, + }, + /* Initialize requirements + * - DB connection + * - DB schemata + */ + init: function (_common) { + common = _common; + + /* DB Connection + * Local db: common.config.dbLocalConn + * TH db: common.config.dbConn + */ + common.mongoose.connect (common.config.dbLocalConn, { + useNewUrlParser: true + }).then(() => { + console.log("Database connected successfully."); + }).catch(err => { + console.log('Database connection error.'); + process.exit(); + }); + + /* DB Schemata + * Privat fields: + * - per model: _list: Elements that are included in list fetch + * - per entry: _comment: Comment for Admin UI - TODO: not working yet + */ + var messageSchema = common.mongoose.Schema({ + subject: { type: String, required: true, + _comment: "" }, + message: { type: String, required: true, + _comment: "" }, + user: { type: String, required: true, + _comment: "" }, + tags: { type: [String], + _comment: "" }, + //createtime: { type: Date, default: Date.now }, + }); + messageSchema.index({ tag:'text' }); + model.Messages = common.mongoose.model('messages', messageSchema); + model.Messages._list = [ "" ]; + + var tagSchema = common.mongoose.Schema({ + name: { type: String, required: true, + _comment: "" }, //unique + }); + model.Tags = common.mongoose.model('tags', messageSchema); + model.Tags._list = [ "" ]; + + var userSchema = common.mongoose.Schema({ + //_id: { type: String }, + name: { type: String, required: true, + _comment: "" }, + pwd: { type: String, + _comment: "" }, + //hash: { type: String }, + //salt: { type: String }, + //type: { type: String }, + roles: { type: [String], required: true, + _comment: "" }, + tags: { type: [String], + _comment: "" }, + //deactivated: { type: Boolean }, + //participating: { type: [String] }, + //host: { type: Boolean }, + bookmarks: { type: [String], + _comment: "" }, + }); + model.Users = common.mongoose.model('users', userSchema); + model.Users._list = [ "" ]; + }, + models: model, +}; + + + +/* +app.get ('/api/ids', function (req, res) { + Message.find({},{id: true}) .exec () .then(results => { + //selects id from message: + var parsed = []; + for (var i in results) { + parsed.push (results[i].id); + } + //var parsed = results.map (x => x._id); + res.send(parsed); + } ) + .catch(err => { + console.log (err); + res .status(500) .json (err); + }); +}); + +app.get ("/api/msg/:id", function (req, res) { + Message.findOne ({_id: req.params.id}) .exec (function (err, results){ + if (err) { + console.log (err); + res .status(404) .json (err); + } else { + console.log(JSON.stringify(results)); + res.json(results); + } + }); +}); + +/*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); + } + }); +}); +*/ +/* +app.post("/api/createMsg", function(req, res){ + console.log("Subject: "+JSON.stringify(req.body)); + var message = new Message( {subject: req.body.sub, message: req.body.mess, user: req.body.use, tag: req.body.ta } ); + + message.save(function(err,result){ + if(err){ + return res .status(401) .send(err.message); + }else{ + res.json({message: "Message created!!"}); + } + }); +}); +*/ +module.exports = dbs; diff --git a/server/ldap_ohm.js b/server/ldap_ohm.js index 99e0977..5ae2f06 100644 --- a/server/ldap_ohm.js +++ b/server/ldap_ohm.js @@ -1,3 +1,5 @@ +// Original file created by Prof.Dr. Matthias Hopf + /* * Valdiate ohm logins with ldap service */