aboutsummaryrefslogtreecommitdiff
path: root/pkgs/webapps/etherpad-lite/modules/ep_mypads/fix_ldap.patch
blob: 6ade6cb505beca3b2d1a86b7904eca5c688e2f7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/auth.js b/auth.js
index ce77ee4..235d8e6 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';
 
@@ -232,21 +233,21 @@ module.exports = (function () {
               // 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)
                 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 {
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;
+  }
+}