Merge remote-tracking branch 'origin/developer' into developer

# Conflicts:
#	public/index.html
#	public/routes/createMessage.js
This commit is contained in:
2019-07-21 14:22:16 +02:00
55 changed files with 2883 additions and 547 deletions
+10 -11
View File
@@ -3,13 +3,14 @@
/*
* Authorization
*/
var common, User;
var common, Users;
const ldap = require ('./ldap_ohm'),
crypto = require ("../server/crypto");
crypto = require ('./crypto'),
dbs = require ('./dbs');
// deactivated is not used yet
const serverVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, deactivated: true, host: true };
const clientVisibleSession = { user: true, name: true, type: true, mail: true, roles: true };
const serverVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, gender: true, deactivated: true, host: true };
const clientVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, gender: true };
// Fill in session object
@@ -59,7 +60,6 @@ const authorization = {
});
}
// TODO Auth: validate session ID
// Check whether to just validate current session ID
if (user === '' && pwd === '') {
console.log ("auth revalidate: " + req.session.user);
@@ -67,9 +67,9 @@ const authorization = {
return returnError();
return returnSession ();
}
/*
// check local database, then ldap
User.findById (req.body.user) .exec (function (err, entry) {
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) {
if (crypto.checkLocalAuth (entry, req.body.pwd)) {
@@ -80,7 +80,7 @@ const authorization = {
// check ldap
ldap.authorize (user.toLowerCase(), pwd, function (found) {
console.log ("ldap authorize " + user + " returns " + JSON.stringify (found));
//console.log ("ldap authorize " + user + " returns " + JSON.stringify (found));
// No ldap entry either -> unauthorized
if (found == null) {
return returnError ();
@@ -100,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) {
@@ -110,9 +110,8 @@ const authorization = {
init: function (_common) {
common = _common;
ldap.init (_common);
//User = require('../database/user.model.js');;
Users = dbs.models.Users;
},
};
module.exports = authorization;
+90 -9
View File
@@ -131,14 +131,15 @@ const dbs = {
});
},
},
"tag": {
"tag/id": {
params: ":id",
/* GET /api/tag/[tag-id]
/* GET /api/tag/id/[tag-id]
* -> Tag schema
* Get a particular tag
*/
get: function(req, res) {
model.Tags.findById(req.params.id) .exec(function(err, result) {
model.Tags.findById(req.params.id)
.exec(function(err, result) {
if (err) {
console.log (err);
res.status(404).json(err);
@@ -149,6 +150,85 @@ const dbs = {
});
},
},
"usr/id": {
params: ":id",
/* GET /api/usr/[usr-id]
* -> User Schema
* Get a particular user
*/
get: function(req, res) {
model.Users.findById(req.params.id)
.exec(function(err, result) {
if (err) {
console.log(err);
res.status(404).json(err);
} else {
//console.log(JSON.stringify(result));
res.json(result);
}
});
},
},
"usr": {
/* POST /api/usr
* <- User schema
* -> User schema
* Create a new user
*/
post: function(req, res) {
model.User.create({
_id: req.body.id,
name: req.body.name,
type: req.body.type,
roles: req.body.roles,
hash: req.body.hash,
salt: req.body.salt,
pwd: req.body.pwd,
abos: req.body.abos,
bookmarks: req.body.bookmarks,
}, function(err, result) {
if (err) {
console.log (err);
return res.status(401).json(err.message);
} else {
res.json({message: "User created!!"});
}
if (result == null) {
return res.status(500).json("Can not create user.")
}
});
},
/* PUT /api/usr
* <- User schema
* -> User schema
* Change a user
*/
put: function(req, res) {
model.Users.findById(reg.body._id)
.exec(function(err, entry) {
if (err)
console.log (err);
if (entry == null)
return res.status(404).json(err.message);
// TODO Catch edge cases
entry.save(function(err, data) {
// TODO Save/Update user
/*
_id: req.body.id,
name: req.body.name,
type: req.body.type,
roles: req.body.roles,
hash: req.body.hash,
salt: req.body.salt,
pwd: req.body.pwd,
abos: req.body.abos,
bookmarks: req.body.bookmarks,
*/
res.json(data);
});
});
},
},
},
/* Initialize requirements
* - DB connection
@@ -169,6 +249,8 @@ const dbs = {
console.log('Database connection error.');
process.exit();
});
// Default 'collection.ensureIndex' is deprecated; New is '.createIndexes'
common.mongoose.set('useCreateIndex', true);
/* DB Schemata
* Privat fields:
@@ -198,20 +280,19 @@ const dbs = {
model.Tags._list = [ "" ];
var userSchema = common.mongoose.Schema({
//_id: { type: String },
_id: { type: String },
name: { type: String, required: true,
_comment: "" },
pwd: { type: String,
_comment: "" },
//hash: { type: String },
//salt: { type: String },
//type: { type: String },
hash: { type: String },
salt: { type: String },
type: { type: String },
roles: { type: [String], required: true,
_comment: "" },
tags: { type: [String],
abos: { type: [String],
_comment: "" },
//deactivated: { type: Boolean },
//participating: { type: [String] },
//host: { type: Boolean },
bookmarks: { type: [String],
_comment: "" },
+6 -3
View File
@@ -7,7 +7,7 @@ const ldap = require('ldapjs');
const ldap_escape = require('ldap-escape');
// TODO: Where do I get the URL from?? A: Is given.
// NOTE: Where do I get the URL from?? A: Is given.
var ldap_client = ldap.createClient({
//url: 'ldap://gso2.ads1.fh-nuernberg.de/',
url: 'ldap://sso.cs.ohm-hochschule.de:389/',
@@ -16,7 +16,7 @@ var ldap_client = ldap.createClient({
// timeouts don't work reliably
});
// TODO: Where do I get the 'bindpath' parameters info from? A: Is given.
// NOTE: Where do I get the 'bindpath' parameters info from? A: Is given.
const ldap_config = {
bindpath: 'cn=Users,dc=ohm-hochschule,dc=de',
timeout: 2000
@@ -89,14 +89,17 @@ const ldap_ohm = {
console.log("ldap search error after bind for user " + user);
return cb (null);
}
// ldap_test output
// return_object = entry.object;
return cb (return_object);
});
res.on('error', function(err) {
console.log('ldap error: ' + err.message);
});
res.on('end', function(result) {
// TODO: Did we forget something?
// TODO: analyze result.status?
// console.info('ldap result: ');
// console.info(result);
});
});
});
-35
View File
@@ -1,35 +0,0 @@
// Terminal call: node server/ldap_test.js - needs VPN or eduroam
const inquirer = require('inquirer'),
ldap = require('./ldap_ohm.js');
inquirer.prompt([
{
name: 'username',
type: 'input',
message: 'Enter your VirtuOhm username:',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter your username.';
}
}
},
{
name: 'password',
type: 'password',
message: 'Enter your password:',
validate: function(value) {
if (value.length) {
return true;
} else {
return 'Please enter your password.';
}
}
}])
.then(answers => {
ldap.init(null);
ldap.authorize(answers.username,answers.password,function(user) {
console.log(JSON.stringify(user));
});
});