diff --git a/src/api.js b/src/api.js index be37e65..7a0f3c3 100644 --- a/src/api.js +++ b/src/api.js @@ -277,7 +277,7 @@ Api.fn.user = { throw Api.err.INVALID_PARAMS; } - var users = this.xo.users; + var users = this.xo.users; return this.checkPermission(session, 'admin').then(function () { return users.remove(p_id); }).then(function (success) { diff --git a/src/collection/ldap.js b/src/collection/ldap.js new file mode 100644 index 0000000..6d79bba --- /dev/null +++ b/src/collection/ldap.js @@ -0,0 +1,72 @@ +/* + * LDAP collection + * Copyright (C) 2013 Martin Dobrev + * UNIXSOL LTD, registered company in UK and Wales + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * @autor: Martin Dobrev +**/ + +var _ = require('underscore'); +var Q = require('q'); + +function LDAP(options, models) +{ + if (!options) + { + options = {}; + } + + _.defaults(options, { + 'indexes': [], + }); + + LDAP.super_.call(this, models); + + this.indexes = options.indexes; + this.prefix = options.prefix; +} +require('util').inherits(LDAP, require('../collection')); + +// Private methods +LDAP.prototype._extract = function (ids) +{ + console.log('Not yet implemented'); +}; + +LDAP.prototype._get = function (properties) +{ + console.log('Not yet implemented'); +}; + +LDAP.prototype._add = function (models, options) +{ + throw "Adding information to LDAP is not supported. You can manage the entries by other means." +}; + +LDAP.prototype._remove = function (ids) +{ + throw "Removing information from LDAP is not supported. You can manage the entries by other means." +}; + +LDAP.prototype._update = function (models) +{ + throw "Updating information from LDAP is not supported. You can manage the entries by other means." +}; + +////////////////////////////////////////////////////////////////////// + +LDAP.extend = require('extendable'); +module.exports = LDAP; \ No newline at end of file diff --git a/src/collection/mysql.js b/src/collection/mysql.js index 9e22c67..a87a2e0 100644 --- a/src/collection/mysql.js +++ b/src/collection/mysql.js @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * @autor: Martin Dobrev + * @author: Martin Dobrev **/ var _ = require('underscore'); @@ -56,7 +56,7 @@ MySQL.prototype._extract = function (ids) var promises = []; _.each(ids, function (id) { - promises.push(knex('users').where('email', id).andWhere('active', 1).select('password', 'email', 'permissions').then(function (model) + promises.push(knex('users').where('email', id).andWhere('active', 1).select('id', 'password', 'email', 'permissions').then(function (model) { if (_.isEmpty(model)) { @@ -66,6 +66,7 @@ MySQL.prototype._extract = function (ids) var result = { id: id, + db_id: model[0].id, email: model[0].email, pw_hash: model[0].password, permission: perms[model[0].permissions], @@ -193,7 +194,10 @@ MySQL.prototype._remove = function (ids) } // @todo Handle indexes. - promises.push(knex('users').whereIn('email', keys).del()); + promises.push(knex('users').whereIn('email', keys).del().then(function (ids) + { + return true; + })); return Q.all(promises); }; diff --git a/src/main.js b/src/main.js index 87bf66c..ec2f3a1 100644 --- a/src/main.js +++ b/src/main.js @@ -356,7 +356,6 @@ cfg.merge({ // Modified by Martin Dobrev @ 2013-10-22 'mysql': { 'enabled' : false, - 'uri' : 'mysql://xoauser:xoapass@localhost:3306/xoa', 'username' : 'xoauser', 'password' : 'xoapass', 'database' : 'xoa', diff --git a/src/xo.js b/src/xo.js index 436a685..1fa5ade 100644 --- a/src/xo.js +++ b/src/xo.js @@ -170,12 +170,12 @@ function InitializeUsersBackend(backend) case 'mysql' : collection = require('./collection/mysql'); break; case 'postgre' : break; case 'sqlite' : break; - case 'ldap' : break; + case 'ldap' : collection = require('./collection/ldap'); break; default : throw "Userdb backend not supported: " + backend; break; } if (collection !== null) { - console.info('UserDB initialized with %s backend', backend); + console.info('UserDB initialized with "%s" backend', backend); return collection.extend({ 'model': User, @@ -196,7 +196,7 @@ function InitializeUsersBackend(backend) } }); } else { - throw "Unable to initialize UserDB Collection"; + throw "Unable to initialize UserDB Collection. Using not yet implemented backend: " + backend; } }