diff --git a/auth.js b/auth.js index ce77ee4..de66b03 100644 --- a/auth.js +++ b/auth.js @@ -91,6 +91,7 @@ var cuid = require('cuid'); var common = require('./model/common.js'); var user = require('./model/user.js'); var conf = require('./configuration.js'); +var utils = require('./utils.js'); var NOT_INTERNAL_AUTH_PWD = 'soooooo_useless'; @@ -212,6 +213,7 @@ module.exports = (function () { } return callback(new Error(emsg), false); } + console.log("before user.get"); user.get(login, function(err, u) { var props = ldapConf.properties; var mail; @@ -229,27 +231,30 @@ module.exports = (function () { return callback(new Error(emsg), false); } if (err) { + console.log("in user.get err"); // We have to create the user in mypads database ldapConf = conf.get('authLdapSettings'); user.set({ - login: ldapuser[props.login], + login: utils.getSingleton(ldapuser[props.login]), password: NOT_INTERNAL_AUTH_PWD, - firstname: ldapuser[props.firstname], - lastname: ldapuser[props.lastname], + firstname: utils.getSingleton(ldapuser[props.firstname]), + lastname: utils.getSingleton(ldapuser[props.lastname]), email: mail, lang: ldapConf.defaultLang || 'en' }, callback); } else if (u.email !== mail || - u.firstname !== ldapuser[props.firstname] || - u.lastname !== ldapuser[props.lastname]) { + u.firstname !== utils.getSingleton(ldapuser[props.firstname]) || + u.lastname !== utils.getSingleton(ldapuser[props.lastname])) { // Update database and cache informations if needed // (i.e. update from LDAP) + console.log("in user.get update"); u.email = mail; - u.firstname = ldapuser[props.firstname]; - u.lastname = ldapuser[props.lastname]; + u.firstname = utils.getSingleton(ldapuser[props.firstname]); + u.lastname = utils.getSingleton(ldapuser[props.lastname]); u.password = NOT_INTERNAL_AUTH_PWD; user.set(u, callback); } else { + console.log("in user.get callback"); return callback(null, u); } }); diff --git a/model/common.js b/model/common.js index b19829b..9421742 100644 --- a/model/common.js +++ b/model/common.js @@ -94,6 +94,7 @@ module.exports = (function() { var isFS = function (s) { return (ld.isString(s) && !ld.isEmpty(s)); }; ld.forEach(strFields, function (s) { if (!isFS(params[s])) { + console.log(params, s); throw new TypeError('BACKEND.ERROR.TYPE.PARAM_STR'); } if (s.length > 100) { diff --git a/utils.js b/utils.js index 32c2727..d381d06 100644 --- a/utils.js +++ b/utils.js @@ -14,3 +14,13 @@ exports.callbackify2 = function (fun) { return wrapPromise(fun(arg1, arg2), cb); }; }; + +exports.getSingleton = function (stringOrArray) { + if (Array.isArray(stringOrArray)) { + if (stringOrArray.length > 0) { + return stringOrArray[0]; + } + } else if (stringOrArray) { + return stringOrArray; + } +}